Method: Ardm::ActiveRecord::Property::ClassMethods#property

Defined in:
lib/ardm/active_record/property.rb

#property(name, type, options = {}) ⇒ Property

Defines a Property on the Resource

Parameters:

  • name (Symbol)

    the name for which to call this property

  • type (Class)

    the ruby type to define this property as

  • options (Hash(Symbol => String)) (defaults to: {})

    a hash of available options

Returns:

See Also:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ardm/active_record/property.rb', line 49

def property(name, type, options = {})
  # if the type can be found within Property then
  # use that class rather than the primitive
  klass = Ardm::Property.determine_class(type)

  if !klass || klass == NilClass
    raise ArgumentError, "+type+ was #{type.inspect}, which is not a supported type"
  end

  property = klass.new(self, name, options)

  self.properties << property

  # add the property to the child classes only if the property was
  # added after the child classes' properties have been copied from
  # the parent
  descendants.each do |descendant|
    descendant.properties << property
  end

  serialize(property.field, property)

  set_primary_key_for(property)
  create_reader_for(property)
  create_writer_for(property)
  add_validations_for(property)

  # FIXME: explicit return needed for YARD to parse this properly
  return property
end