Class: Paradocs::Policies::Format
- Inherits:
-
BasePolicy
- Object
- BasePolicy
- Paradocs::Policies::Format
- Defined in:
- lib/paradocs/policies.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Attributes inherited from BasePolicy
Instance Method Summary collapse
- #eligible?(value, key, payload) ⇒ Boolean
-
#initialize(fmt, msg = "invalid format") ⇒ Format
constructor
A new instance of Format.
- #validate(value, key, payload) ⇒ Object
Methods inherited from BasePolicy
build, #coerce, coerce, eligible, message, meta_data, #meta_data, policy_name, #policy_name, policy_name=, #valid?, validate
Constructor Details
#initialize(fmt, msg = "invalid format") ⇒ Format
Returns a new instance of Format.
8 9 10 11 |
# File 'lib/paradocs/policies.rb', line 8 def initialize(fmt, msg="invalid format") @message = msg @fmt = fmt end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/paradocs/policies.rb', line 6 def @message end |
Instance Method Details
#eligible?(value, key, payload) ⇒ Boolean
13 14 15 |
# File 'lib/paradocs/policies.rb', line 13 def eligible?(value, key, payload) payload.key?(key) end |
#validate(value, key, payload) ⇒ Object
17 18 19 |
# File 'lib/paradocs/policies.rb', line 17 def validate(value, key, payload) !payload.key?(key) || !!(value.to_s =~ @fmt) end |