Sha256: 50199250371498b0566cbfa3291cef43795a14a9343e242f1bda928ba587b2cf
Contents?: true
Size: 866 Bytes
Versions: 1
Compression:
Stored size: 866 Bytes
Contents
class RestModel module Source class Translation attr_accessor :values, :from_source, :to_source def initialize(attrs = {}) @values = attrs[:values] @from_source = attrs[:from_source] @to_source = attrs[:to_source] end def translate_from_source(value, resource) if from_source resource.instance_exec(value, &from_source) elsif values fail "from source error" unless values.has_value?(value) values.key(value) else value end end def translate_to_source(value, resource) if to_source resource.instance_exec(value, &to_source) elsif values fail "to source error" unless values.has_key?(value) values[value] else value end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rest_model-0.1.5 | lib/rest_model/source/translation.rb |