Class: Safrano::Attribute
- Inherits:
-
Object
- Object
- Safrano::Attribute
- Includes:
- Transitions
- Defined in:
- lib/odata/attribute.rb
Overview
Represents a named and valued attribute of an Entity
Defined Under Namespace
Modules: Transitions
Constant Summary
Constants included from Transitions
Transitions::ALLOWED_TRANSITIONS
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#==(other) ⇒ Object
for testing purpose (assert_equal …).
-
#initialize(entity, name) ⇒ Attribute
constructor
A new instance of Attribute.
- #odata_get(req) ⇒ Object
-
#to_odata_json ⇒ Object
output as OData json (v2).
- #value ⇒ Object
Methods included from Transitions
#allowed_transitions, #transition_end, #transition_value
Methods included from Transitions::GetNextTrans::BySimpleDetect
Constructor Details
#initialize(entity, name) ⇒ Attribute
Returns a new instance of Attribute.
13 14 15 16 17 |
# File 'lib/odata/attribute.rb', line 13 def initialize(entity, name) @entity = entity @name = name @allowed_transitions = ALLOWED_TRANSITIONS end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
11 12 13 |
# File 'lib/odata/attribute.rb', line 11 def entity @entity end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/odata/attribute.rb', line 10 def name @name end |
Instance Method Details
#==(other) ⇒ Object
for testing purpose (assert_equal …)
48 49 50 |
# File 'lib/odata/attribute.rb', line 48 def ==(other) (@entity == other.entity) && (@name == other.name) end |
#odata_get(req) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/odata/attribute.rb', line 31 def odata_get(req) if req.walker.raw_value [200, CT_TEXT, value.to_s] elsif req.accept?(APPJSON) # json is default content type so we dont need to specify it here again [200, EMPTY_HASH, to_odata_json(service: req.service)] else # TODO: other formats 406 end end |
#to_odata_json ⇒ Object
output as OData json (v2)
43 44 45 |
# File 'lib/odata/attribute.rb', line 43 def to_odata_json(*) { 'd' => { @name => value } }.to_json end |
#value ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/odata/attribute.rb', line 19 def value # WARNING ... this require more work to handle the timezones topci # currently it is just set to make some minimal testcase work # See also model_ext.rb case (v = @entity.values[@name.to_sym]) when Date, Time, DateTime v.to_edm_json else v end end |