Class: SugarCRM::Base

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = nil, attributes = {}) ⇒ Base

Creates an instance of a Module Class, i.e. Account, User, Contact, etc. This call depends upon SugarCRM.modules having actual data in it. If you are using Base.establish_connection, you should be fine. But if you are using the Connection class by itself, you may need to prime the pump with a call to Module.register_all



279
280
281
282
283
284
285
# File 'lib/sugarcrm/base.rb', line 279

def initialize(id=nil, attributes={})
  @id = id
  @attributes = self.class.attributes_from_module_fields.merge(attributes)
  @associations = associations_from_module_link_fields
  define_attribute_methods
  define_association_methods
end

Instance Attribute Details

#attributesObject

Contains a list of attributes



23
24
25
# File 'lib/sugarcrm/base.rb', line 23

def attributes
  @attributes
end

#debugObject

Returns the value of attribute debug.



25
26
27
# File 'lib/sugarcrm/base.rb', line 25

def debug
  @debug
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Class Method Details

.all(*args) ⇒ Object

This is an alias for find(:all). You can pass in all the same arguments to this method as you can to find(:all)



55
56
57
# File 'lib/sugarcrm/base.rb', line 55

def all(*args)
  find(:all, *args)
end

.establish_connection(url, user, pass, opts = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/sugarcrm/base.rb', line 28

def establish_connection(url, user, pass, opts={})
  options = { 
    :debug  => false,
  }.merge(opts)
  @debug  = options[:debug]
  @@connection = SugarCRM::Connection.new(url, user, pass, @debug)
end

.find(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/sugarcrm/base.rb', line 36

def find(*args)
  options = args.extract_options!
  validate_find_options(options)

  case args.first
    when :first then find_initial(options)
    when :all   then find_every(options)
    else             find_from_ids(args, options)
  end
end

.first(*args) ⇒ Object

A convenience wrapper for find(:first, *args). You can pass in all the same arguments to this method as you can to find(:first).



49
50
51
# File 'lib/sugarcrm/base.rb', line 49

def first(*args)
  find(:first, *args)
end

Instance Method Details

#association_methods_generated?Boolean

Returns:

  • (Boolean)


308
309
310
# File 'lib/sugarcrm/base.rb', line 308

def association_methods_generated?
  self.class.association_methods_generated
end

#attribute_methods_generated?Boolean

Wrapper around class attribute

Returns:

  • (Boolean)


304
305
306
# File 'lib/sugarcrm/base.rb', line 304

def attribute_methods_generated?
  self.class.attribute_methods_generated
end

#inspectObject



287
288
289
# File 'lib/sugarcrm/base.rb', line 287

def inspect
  self
end

#saveObject



299
300
301
# File 'lib/sugarcrm/base.rb', line 299

def save
  response = SugarCRM.connection.set_entry(self._module.name, @attributes)
end

#to_sObject



291
292
293
294
295
296
297
# File 'lib/sugarcrm/base.rb', line 291

def to_s
  attrs = []
  @attributes.each_key do |k|
     attrs << "#{k}: #{attribute_for_inspect(k)}"
  end
  "#<#{self.class} #{attrs.join(", ")}>"
end