Last active
August 29, 2015 14:25
-
-
Save kannan4k/4ccb4dd1a30496fd56b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TSheets::Model | |
def self.from_raw(hash, cache, supplemental = {}) | |
instance = hash.inject self.new(cache) do |o, p| | |
k, v = p | |
casted = cast_raw(v, k, cache) | |
has_key = o.attributes.keys.include? k | |
if !has_key | |
o.instance_variable_set "@#{k}".to_sym, casted | |
o.define_singleton_method k do | |
o.instance_variable_get "@#{k}".to_sym | |
end | |
else | |
o.send "#{k}=", casted | |
end | |
o | |
end | |
models.each do |model_def| | |
instance.send "#{model_def[:name]}=", resolve_supplemental(instance, model_def, cache, supplemental) | |
end | |
instance | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment