Class: Parametric::Policies::Value

Inherits:
Object
  • Object
show all
Defined in:
lib/parametric/policies.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val, msg = 'invalid value') ⇒ Value

Returns a new instance of Value.



35
36
37
38
# File 'lib/parametric/policies.rb', line 35

def initialize(val, msg = 'invalid value')
  @message = msg
  @val = val
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



33
34
35
# File 'lib/parametric/policies.rb', line 33

def message
  @message
end

Instance Method Details

#coerce(_value, _key, _context) ⇒ Object



44
45
46
# File 'lib/parametric/policies.rb', line 44

def coerce(_value, _key, _context)
  @val
end

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/parametric/policies.rb', line 40

def eligible?(value, key, payload)
  payload.key?(key)
end

#meta_dataObject



52
53
54
# File 'lib/parametric/policies.rb', line 52

def 
  { value: @val }
end

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/parametric/policies.rb', line 48

def valid?(value, key, payload)
  !payload.key?(key) || !!(value == @val)
end