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 81 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 64 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 59 def parse(json) parsed = String === json ? JSON.parse(json) : json Array.wrap(parsed).map {|attrs| skip_json_root? ? new(attrs) : new(attrs[json_root])} end
skip_json_root(skip = nil)
click to toggle source
# File lib/harvest/model.rb, line 51 def skip_json_root(skip = nil) @_skip_json_root ||= skip end
skip_json_root?()
click to toggle source
# File lib/harvest/model.rb, line 55 def skip_json_root? @_skip_json_root == true end
wrap(model_or_attrs)
click to toggle source
# File lib/harvest/model.rb, line 70 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