Method: ActiveGit::ModelParser.from_json
- Defined in:
- lib/active_git/model_parser.rb
.from_json(model, json) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_git/model_parser.rb', line 20 def self.from_json(model, json) record = model.new attributes = json.is_a?(Hash) ? json : JSON.parse(json) attributes.each do |attr, value| if model.column_names.include?(attr.to_s) if model.columns_hash[attr.to_s].type == :datetime && value.is_a?(String) record.send("#{attr}=", Time.parse(value).utc) else record.send("#{attr}=", value) end end end record end |