Class: MoySklad::Client::Base

Inherits:
ActiveResource::Base show all
Defined in:
lib/moy_sklad/client/base.rb

Constant Summary collapse

@@template_path =
File.join(File.dirname(__FILE__), '..', 'model', 'templates')

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveResource::Base

#find_object

Class Method Details

.collection_nameObject



37
38
39
# File 'lib/moy_sklad/client/base.rb', line 37

def collection_name
  @collection_name ||= "#{element_name.classify}/list"
end

.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object

Custom path builder



25
26
27
28
29
30
31
# File 'lib/moy_sklad/client/base.rb', line 25

def element_path(id, prefix_options = {}, query_options = nil)
  check_prefix_options(prefix_options)

  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{element_name.classify}/" \
  "#{URI.parser.escape id.to_s}#{query_string(query_options)}"
end

.find(*args) ⇒ Object



18
19
20
21
22
# File 'lib/moy_sklad/client/base.rb', line 18

def find(*args)
  # Little trick for correct baseclass name
  self.format.element_name = element_name.classify
  super(*args)
end

.new_element_path(prefix_options = {}) ⇒ Object



33
34
35
# File 'lib/moy_sklad/client/base.rb', line 33

def new_element_path(prefix_options = {})
  "#{prefix(prefix_options)}#{element_name.classify}"
end

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/moy_sklad/client/base.rb', line 56

def applicable?
  applicable.to_s == 'true'
end

#createObject

Override create method, this required because moysklad uses PUT instead of POST



43
44
45
# File 'lib/moy_sklad/client/base.rb', line 43

def create
  run_callbacks :create do _create end
end

#destroyObject



47
48
49
# File 'lib/moy_sklad/client/base.rb', line 47

def destroy
  run_callbacks :destroy do _destroy end
end

#saveObject



51
52
53
54
# File 'lib/moy_sklad/client/base.rb', line 51

def save
  super
  self.error.is_a?(MoySklad::Client::Attribute::MissingAttr)
end