Module: Harvest::Model::ClassMethods
- Defined in:
- lib/harvest/model.rb
Instance Method Summary (collapse)
-
- (void) api_path(path = nil)
This sets the API path so the API collections can use them in an agnostic way.
- - (Object) delegate_methods(options)
- - (Object) json_root
- - (Object) parse(json)
- - (Object) skip_json_root(skip = nil)
- - (Boolean) skip_json_root?
- - (Object) wrap(model_or_attrs)
Instance Method Details
- (void) api_path(path = nil)
This method returns an undefined value.
This sets the API path so the API collections can use them in an agnostic way
47 48 49 |
# File 'lib/harvest/model.rb', line 47 def api_path(path = nil) @_api_path ||= path end |
- (Object) delegate_methods(options)
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/harvest/model.rb', line 81 def delegate_methods() raise "no methods given" if .empty? .each do |source, dest| class_eval <<-EOV def #{source} #{dest} end EOV end end |
- (Object) json_root
64 65 66 67 68 |
# File 'lib/harvest/model.rb', line 64 def json_root Harvest::Model::Utility.underscore( Harvest::Model::Utility.demodulize(to_s) ) end |
- (Object) parse(json)
59 60 61 62 |
# 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 |
- (Object) skip_json_root(skip = nil)
51 52 53 |
# File 'lib/harvest/model.rb', line 51 def skip_json_root(skip = nil) @_skip_json_root ||= skip end |
- (Boolean) skip_json_root?
55 56 57 |
# File 'lib/harvest/model.rb', line 55 def skip_json_root? @_skip_json_root == true end |
- (Object) wrap(model_or_attrs)
70 71 72 73 74 75 76 77 78 79 |
# 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 |