Class: Paradocs::Policies::Format

Inherits:
BasePolicy show all
Defined in:
lib/paradocs/policies.rb

Instance Attribute Summary collapse

Attributes inherited from BasePolicy

#environment

Instance Method Summary collapse

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

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/paradocs/policies.rb', line 6

def message
  @message
end

Instance Method Details

#eligible?(value, key, payload) ⇒ Boolean

Returns:

  • (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