Class: VtigerRuby::VtigerModel

Inherits:
Object
  • Object
show all
Defined in:
lib/vtiger-ruby/models/vtiger_model.rb

Direct Known Subclasses

Account

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, attribs = {}) ⇒ VtigerModel

Returns a new instance of VtigerModel.



25
26
27
28
# File 'lib/vtiger-ruby/models/vtiger_model.rb', line 25

def initialize(client, attribs = {})
  @client = client
  self.attributes = attribs unless attribs.empty?
end

Instance Attribute Details

#fetch_responseObject

Returns the value of attribute fetch_response.



30
31
32
# File 'lib/vtiger-ruby/models/vtiger_model.rb', line 30

def fetch_response
  @fetch_response
end

Class Method Details

.all_from_vtiger(klass, sql_query) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/vtiger-ruby/models/vtiger_model.rb', line 7

def self.all_from_vtiger(klass, sql_query)
  VtigerRuby::Api::Query
    .new(@@client, sql_query: sql_query)
      .fetch_all
        .reduce([]) do |memo, data|
          memo << klass.new(@@client, data)
        end
end

.class_config(client) ⇒ Object



3
4
5
# File 'lib/vtiger-ruby/models/vtiger_model.rb', line 3

def self.class_config(client)
  @@client = client
end

.fetch_from_vtiger(klass, sql_query) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/vtiger-ruby/models/vtiger_model.rb', line 16

def self.fetch_from_vtiger(klass, sql_query)
  VtigerRuby::Api::Query
    .new(@@client)
      .fetch(sql_query)
        .reduce([]) do |memo, data|
          memo << klass.new(@@client, data)
        end
end

Instance Method Details

#attributes=(hash) ⇒ Object



32
33
34
# File 'lib/vtiger-ruby/models/vtiger_model.rb', line 32

def attributes=(hash)
  @fetch_response = hash
end