Module: Turbine::Properties

Included in:
Edge, Node
Defined in:
lib/turbine/properties.rb

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object

Public: Returns a single property on the model.

key - The property to be retrieved.

Returns the value or nil if the property does not exist.



43
44
45
# File 'lib/turbine/properties.rb', line 43

def get(key)
  properties[key]
end

#propertiesObject

Public: Returns the properties associated with the model.

Returns a hash containing the properties. This is the original properties hash, not a duplicate.



8
9
10
# File 'lib/turbine/properties.rb', line 8

def properties
  @properties ||= Hash.new
end

#properties=(new_props) ⇒ Object

Public: Mass-assigns properties to the model.

new_props - A hash containing zero or more properties. The internal

properties hash is set to whatever parameters you provide; a
duplicate is not made before assignment. You may provide
+nil+ to remove all properties.

Returns the properties.



20
21
22
23
24
25
26
# File 'lib/turbine/properties.rb', line 20

def properties=(new_props)
  unless new_props.is_a?(Hash) || new_props.nil?
    raise InvalidPropertiesError.new(self, new_props)
  end

  @properties = new_props
end

#set(key, value) ⇒ Object

Public: Sets a single property on the model.

key - The property name. value - The value to be set.

Returns the value.



34
35
36
# File 'lib/turbine/properties.rb', line 34

def set(key, value)
  properties[key] = value
end