Module: Ripple::Properties

Defined in:
lib/ripple/properties.rb

Overview

Adds the ability to declare properties on your Ripple::Document class. Properties will automatically generate accessor (get/set/query) methods and handle type-casting between your Ruby type and JSON-compatible types.

Instance Method Summary collapse

Instance Method Details

#inherited(subclass) ⇒ Object



11
12
13
14
# File 'lib/ripple/properties.rb', line 11

def inherited(subclass)
  super
  subclass.properties.merge!(properties)
end

#propertiesHash

Returns the properties defined on the document.

Returns:

  • (Hash)

    the properties defined on the document



17
18
19
# File 'lib/ripple/properties.rb', line 17

def properties
  @properties ||= {}.with_indifferent_access
end

#property(key, type, options = {}) ⇒ Object



21
22
23
24
# File 'lib/ripple/properties.rb', line 21

def property(key, type, options={})
  prop = Property.new(key, type, options)
  properties[prop.key] = prop
end