Class: Stronger::PropertySet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/stronger/property_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(given_values, config_props) ⇒ PropertySet

TODO: given_props should be called values



13
14
15
16
17
18
19
# File 'lib/stronger/property_set.rb', line 13

def initialize(given_values, config_props)
  @config_props = config_props
  @values = Hash.new

  given_values.each {|k,v| set(k, v) }
  validate_required_present!
end

Instance Method Details

#[](key) ⇒ Object



29
30
31
32
33
# File 'lib/stronger/property_set.rb', line 29

def [](key)
  get_property(key)
  values[key] || (raise MissingProperty,
    "#{key} is not required and has not been set!")
end

#[]=(key, value) ⇒ Object Also known as: set



22
23
24
25
26
# File 'lib/stronger/property_set.rb', line 22

def []=(key, value)
  property = get_property(key)
  validate_type!(value, property)
  values[key] = value
end

#delete(name) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/stronger/property_set.rb', line 35

def delete(name)
  unless get_property(name).required?
    values.delete(name)
  else
    raise MissingProperty, "You can't delete required property #{name}!"
  end
end