class Safrano::Attribute

Represents a named and valued attribute of an Entity

Attributes

entity[R]
name[R]

Public Class Methods

new(entity, name) click to toggle source
# File lib/odata/attribute.rb, line 13
def initialize(entity, name)
  @entity = entity
  @name = name
end

Public Instance Methods

==(other) click to toggle source

for testing purpose (assert_equal …)

# File lib/odata/attribute.rb, line 49
def ==(other)
  (@entity == other.entity) && (@name == other.name)
end
odata_get(req) click to toggle source
# File lib/odata/attribute.rb, line 32
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(*) click to toggle source

output as OData json (v2)

# File lib/odata/attribute.rb, line 44
def to_odata_json(*)
  { 'd' => { @name => value } }.to_json
end
value() click to toggle source
# File lib/odata/attribute.rb, line 18
def value
  # WARNING ... this require more work to handle the timezones topci
  # currently it is just set to make some minimal testcase work
  case (v = @entity.values[@name.to_sym])
  when Time
    # try to get back the database time zone and value
    #        (v + v.gmt_offset).utc.to_datetime
    v.iso8601

  else
    v
  end
end