Module: CORS::Policy
- Included in:
- S3
- Defined in:
- lib/cors/policy.rb,
lib/cors/policy/s3.rb
Overview
Mixin for declaring CORS Policies.
Classes who include this mixin should define both #manifest and #sign.
Defined Under Namespace
Modules: ClassMethods Classes: S3
Instance Attribute Summary collapse
- #attributes ⇒ Hash<String, Object> readonly
- #errors ⇒ Hash readonly
Class Method Summary collapse
-
.included(other) ⇒ Object
Extends the target with ClassMethods.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Object
Initialize the policy with the given attributes and validate the attributes.
-
#manifest ⇒ String
The compiled manifest.
-
#rules ⇒ CORS::Rules
Rules assigned to this policy.
-
#sign ⇒ String
Signature derived from the manifest.
-
#valid? ⇒ Boolean
True if no errors was encountered during validation in #initialize.
Instance Attribute Details
#attributes ⇒ Hash<String, Object>
79 80 81 |
# File 'lib/cors/policy.rb', line 79 def attributes @attributes end |
#errors ⇒ Hash
83 84 85 |
# File 'lib/cors/policy.rb', line 83 def errors @errors end |
Class Method Details
.included(other) ⇒ Object
Extends the target with ClassMethods
60 61 62 |
# File 'lib/cors/policy.rb', line 60 def included(other) other.extend(ClassMethods) end |
Instance Method Details
#initialize(attributes) ⇒ Object
attribute keys are converted to strings and downcased for validation
validations are run instantly
Initialize the policy with the given attributes and validate the attributes.
73 74 75 76 |
# File 'lib/cors/policy.rb', line 73 def initialize(attributes) self.attributes = Hash[attributes.map { |k, v| [k.to_s.downcase, v] }] self.errors = rules.validate(self.attributes) end |
#manifest ⇒ String
must be overridden by includers!
Returns the compiled manifest.
99 100 101 |
# File 'lib/cors/policy.rb', line 99 def manifest raise NotImplementedError, "#manifest has not been defined on #{inspect}" end |
#rules ⇒ CORS::Rules
Returns rules assigned to this policy.
88 89 90 |
# File 'lib/cors/policy.rb', line 88 def rules self.class.rules or raise "no rules defined for policy #{inspect}" end |
#sign ⇒ String
must be overridden by includers!
Returns signature derived from the manifest.
105 106 107 |
# File 'lib/cors/policy.rb', line 105 def sign(*) raise NotImplementedError, "#sign has not been defined on #{inspect}" end |
#valid? ⇒ Boolean
Returns true if no errors was encountered during validation in #initialize.
93 94 95 |
# File 'lib/cors/policy.rb', line 93 def valid? errors.empty? end |