Class: Abacos::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/abacos/base.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Base

Returns a new instance of Base.



41
42
43
44
45
46
# File 'lib/abacos/base.rb', line 41

def initialize(params)
  params.each do |key, value|
    instance_variable_set "@#{key}", value
    define_singleton_method(key) { instance_variable_get "@#{key}" }
  end
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/abacos/base.rb', line 3

def response
  @response
end

Class Method Details

.available(params) ⇒ Object



5
6
7
# File 'lib/abacos/base.rb', line 5

def self.available(params)
  call(:"#{collection_name}_disponiveis", params).map { |params| new params }
end

.call(method, params) ⇒ Object



29
30
31
# File 'lib/abacos/base.rb', line 29

def self.call(method, params)
  Response.new method, api.call(method, message: params)
end

.collection_nameObject



24
25
26
# File 'lib/abacos/base.rb', line 24

def collection_name
  @collection_name ||= "#{resource_name}s"
end

.create(method, params) ⇒ Object



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

def self.create(method, params)
  new response: call(method, params)
end

.execute(query) ⇒ Object



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

def self.execute(query)
  db.execute(query).map { |params| new params }
end

Instance Method Details

#confirm!Object



9
10
11
# File 'lib/abacos/base.rb', line 9

def confirm!
  self.class.call(:"confirmar_recebimento_#{self.class.resource_name}", :"protocolo_#{self.class.resource_name}" => send("protocolo_#{self.class.resource_name}"))
end

#persisted?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/abacos/base.rb', line 48

def persisted?
  response.success?
end