Module: MyERP::Model::ClassMethods

Defined in:
lib/myerp/model.rb

Instance Method Summary collapse

Instance Method Details

#api_path(path = nil) ⇒ void

This method returns an undefined value.

This sets the API path so the API collections can use them in an agnostic way



33
34
35
# File 'lib/myerp/model.rb', line 33

def api_path(path = nil)
  @_api_path ||= path
end

#delegate_methods(options) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/myerp/model.rb', line 53

def delegate_methods(options)
  raise "no methods given" if options.empty?
  options.each do |source, dest|
    class_eval "      def \#{source}\n        \#{dest}\n      end\n    EOV\n  end\nend\n"

#parse(json) ⇒ Object



37
38
39
40
# File 'lib/myerp/model.rb', line 37

def parse(json)
  parsed = String === json ? JSON.parse(json) : json
  Array.wrap(parsed).map {|attrs| new(attrs) }
end

#wrap(model_or_attrs) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/myerp/model.rb', line 42

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