Skip to content

Commit

Permalink
Merge pull request #5 from PizzaPowered/error-gracefully
Browse files Browse the repository at this point in the history
Handle extra API attributes with a warning.
  • Loading branch information
EmmanuelOga committed May 4, 2011
2 parents b2d033b + 9e17a9c commit 0bd3b3f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/firering/instantiator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ def instantiate(conn, data, base_key = nil, &callback)
attributes ||= Hash.new

attributes.each do |key, val|
setter = "#{key}="
value = ( key.to_s =~ /(_at|_on)$/ ) ? (Time.parse(val) rescue val) : val
instance.send("#{key}=", value)
if instance.respond_to?(setter)
instance.send(setter, value)
else
Kernel.warn "WARNING: Tried to set #{setter} #{value.inspect} on a #{instance.class} instance but it didn't respond"
end
end

callback.call(instance) if callback
Expand Down

0 comments on commit 0bd3b3f

Please sign in to comment.