Class: Troupe::Contract::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/troupe/contract/property.rb

Constant Summary collapse

DEFAULTS =
{ presence: :provided }
VALID_OPTIONS =
{
  presence: [:expected, :permitted, :provided]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Property

Returns a new instance of Property.



12
13
14
15
16
17
18
# File 'lib/troupe/contract/property.rb', line 12

def initialize(opts={})
  validate_options(opts)
  opts = DEFAULTS.merge(opts)
  @default      = opts[:default]
  @on_violation = opts[:on_violation]
  @presence     = opts[:presence]
end

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



10
11
12
# File 'lib/troupe/contract/property.rb', line 10

def default
  @default
end

#on_violationObject

Returns the value of attribute on_violation.



10
11
12
# File 'lib/troupe/contract/property.rb', line 10

def on_violation
  @on_violation
end

#presenceObject

Returns the value of attribute presence.



10
11
12
# File 'lib/troupe/contract/property.rb', line 10

def presence
  @presence
end

Instance Method Details

#merge!(hash) ⇒ Object



20
21
22
23
24
# File 'lib/troupe/contract/property.rb', line 20

def merge!(hash)
  hash.each do |k, v|
    send("#{k}=", v)
  end
end