Skip to content

Instantly share code, notes, and snippets.

@kannan4k
Last active August 29, 2015 14:25
Show Gist options
  • Save kannan4k/4ccb4dd1a30496fd56b6 to your computer and use it in GitHub Desktop.
Save kannan4k/4ccb4dd1a30496fd56b6 to your computer and use it in GitHub Desktop.
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