Module: CORS::Policy
- Defined in:
- lib/cors/policy.rb,
lib/cors/policy/s3.rb,
lib/cors/policy/s3_post.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, S3Post
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.
-
#rules ⇒ CORS::Rules
Rules assigned to this policy.
-
#sign(*args, &block) ⇒ String
Signs the manifest, but only if it is #valid?.
-
#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[normalize_attributes(attributes)] self.errors = rules.validate(self.attributes) 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(*args, &block) ⇒ String
should not be overridden by the includers!
Signs the manifest, but only if it is #valid?.
101 102 103 |
# File 'lib/cors/policy.rb', line 101 def sign(*args, &block) sign!(*args, &block) if valid? end |
#sign! ⇒ String
should be overridden by includers!
Returns signature derived from the manifest.
107 108 109 |
# File 'lib/cors/policy.rb', line 107 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 |