Class: RestModel::Property

Inherits:
Key
  • Object
show all
Includes:
Retriever, Sender, Response
Defined in:
lib/rest_model/key/property.rb,
lib/rest_model/key/property/sender.rb,
lib/rest_model/key/property/builder.rb,
lib/rest_model/key/property/response.rb,
lib/rest_model/key/property/retriever.rb

Defined Under Namespace

Modules: Builder, Response, Retriever, Sender

Instance Attribute Summary collapse

Attributes inherited from Key

#model, #name, #options, #summarize

Instance Method Summary collapse

Methods included from Response

#build_links, #resource, #resource_keys, #summarize?

Methods included from Retriever

#digg, #from_source

Methods included from Sender

#to_source!

Methods inherited from Key

#convert_input_keys, #present?, #root_path?, #source_path, #visible?

Constructor Details

#initialize(name, options = {}) ⇒ Property

Returns a new instance of Property.



12
13
14
15
16
# File 'lib/rest_model/key/property.rb', line 12

def initialize(name, options = {})
  super
  @serializer  = options.fetch(:type, Serialization::String)
  @translation = Source::Translation.new(options)
end

Instance Attribute Details

#serializerObject

Returns the value of attribute serializer.



10
11
12
# File 'lib/rest_model/key/property.rb', line 10

def serializer
  @serializer
end

#translationObject

Returns the value of attribute translation.



10
11
12
# File 'lib/rest_model/key/property.rb', line 10

def translation
  @translation
end

Instance Method Details

#from_hash(value, resource = nil) ⇒ Object



18
19
20
21
22
# File 'lib/rest_model/key/property.rb', line 18

def from_hash(value, resource = nil)
  serializer == Serialization::String ? value : serializer.serialize(value)
rescue
  value
end