Class: SugarCRM::Base
- Inherits:
-
Object
- Object
- SugarCRM::Base
- Defined in:
- lib/sugarcrm/base.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Contains a list of attributes.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
-
.all(*args) ⇒ Object
This is an alias for find(:all).
- .establish_connection(url, user, pass, opts = {}) ⇒ Object
- .find(*args) ⇒ Object
-
.first(*args) ⇒ Object
A convenience wrapper for
find(:first, *args)
.
Instance Method Summary collapse
- #association_methods_generated? ⇒ Boolean
-
#attribute_methods_generated? ⇒ Boolean
Wrapper around class attribute.
-
#initialize(id = nil, attributes = {}) ⇒ Base
constructor
Creates an instance of a Module Class, i.e.
- #inspect ⇒ Object
- #save ⇒ Object
- #to_s ⇒ Object
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
#attributes ⇒ Object
Contains a list of attributes
23 24 25 |
# File 'lib/sugarcrm/base.rb', line 23 def attributes @attributes end |
#debug ⇒ Object
Returns the value of attribute debug.
25 26 27 |
# File 'lib/sugarcrm/base.rb', line 25 def debug @debug end |
#id ⇒ Object
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={}) = { :debug => false, }.merge(opts) @debug = [: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) = args. () case args.first when :first then find_initial() when :all then find_every() else find_from_ids(args, ) 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
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
304 305 306 |
# File 'lib/sugarcrm/base.rb', line 304 def attribute_methods_generated? self.class.attribute_methods_generated end |
#inspect ⇒ Object
287 288 289 |
# File 'lib/sugarcrm/base.rb', line 287 def inspect self end |
#save ⇒ Object
299 300 301 |
# File 'lib/sugarcrm/base.rb', line 299 def save response = SugarCRM.connection.set_entry(self._module.name, @attributes) end |
#to_s ⇒ Object
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 |