module Harvest::Model::ClassMethods
Public Instance Methods
api_path(path = nil)
click to toggle source
delegate_methods(options)
click to toggle source
# File lib/harvest/model.rb, line 83 def delegate_methods(options) raise "no methods given" if options.empty? options.each do |source, dest| class_eval <<-EOV def #{source} #{dest} end EOV end end
json_root()
click to toggle source
# File lib/harvest/model.rb, line 63 def json_root Harvest::Model::Utility.underscore( Harvest::Model::Utility.demodulize(to_s)) end
parse(json)
click to toggle source
# File lib/harvest/model.rb, line 57 def parse(json) parsed = String === json ? JSON.parse(json) : json objects = skip_json_root? && parsed[json_root.pluralize] || parsed Array.wrap(objects).map { |attrs| new(attrs) } end
skip_json_root(skip = nil)
click to toggle source
# File lib/harvest/model.rb, line 49 def skip_json_root(skip = nil) @_skip_json_root ||= skip end
skip_json_root?()
click to toggle source
# File lib/harvest/model.rb, line 53 def skip_json_root? @_skip_json_root == true end
to_json(json)
click to toggle source
# File lib/harvest/model.rb, line 68 def to_json(json) parsed = String === json ? JSON.parse(json) : json end
wrap(model_or_attrs)
click to toggle source
# File lib/harvest/model.rb, line 72 def wrap(model_or_attrs) case model_or_attrs when Hashie::Mash model_or_attrs when Hash new(model_or_attrs) else model_or_attrs end end