Class: OData::ActiveRecordSchema::Property

Inherits:
OData::AbstractSchema::Property show all
Defined in:
lib/o_data/active_record_schema/property.rb

Constant Summary collapse

@@column_adapter_return_types =
{
  :binary    => 'Edm.Binary',
  :boolean   => 'Edm.Boolean',
  :byte      => 'Edm.Byte',
  :date      => 'Edm.Date',
  :datetime  => 'Edm.DateTime',
  :float     => 'Edm.Decimal',
  :integer   => 'Edm.Int32',
  :string    => 'Edm.String',
  :text      => 'Edm.String',
  :timestamp => 'Edm.DateTime',
  :time      => 'Edm.Time'
}.freeze

Instance Attribute Summary collapse

Attributes inherited from OData::AbstractSchema::Property

#entity_type, #nullable, #return_type

Attributes inherited from OData::AbstractSchema::SchemaObject

#name, #schema

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OData::AbstractSchema::Property

#inspect, #nullable?, #qualified_name

Methods inherited from OData::AbstractSchema::SchemaObject

#<=>, #inspect, #plural_name, #qualified_name, #singular_name

Methods included from OData::AbstractSchema::Comparable

#compare, #sort

Constructor Details

#initialize(schema, entity_type, column_adapter) ⇒ Property

Returns a new instance of Property.



33
34
35
36
37
# File 'lib/o_data/active_record_schema/property.rb', line 33

def initialize(schema, entity_type, column_adapter)
  super(schema, entity_type, self.class.name_for(column_adapter), self.class.return_type_for(column_adapter), self.class.nullable?(column_adapter))
  
  @column_adapter = column_adapter
end

Instance Attribute Details

#column_adapterObject (readonly)

Returns the value of attribute column_adapter.



31
32
33
# File 'lib/o_data/active_record_schema/property.rb', line 31

def column_adapter
  @column_adapter
end

Class Method Details

.name_for(column_adapter) ⇒ Object



23
24
25
# File 'lib/o_data/active_record_schema/property.rb', line 23

def self.name_for(column_adapter)
  column_adapter.name.to_s
end

.nullable?(column_adapter) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/o_data/active_record_schema/property.rb', line 27

def self.nullable?(column_adapter)
  column_adapter.null
end

.return_type_for(column_adapter) ⇒ Object



19
20
21
# File 'lib/o_data/active_record_schema/property.rb', line 19

def self.return_type_for(column_adapter)
  @@column_adapter_return_types[column_adapter.type]
end

Instance Method Details

#value_for(one) ⇒ Object



39
40
41
42
# File 'lib/o_data/active_record_schema/property.rb', line 39

def value_for(one)
  v = one.send(@column_adapter.name.to_sym)
  v.respond_to?(:iso8601) ? v.send(:iso8601) : v
end