Class: SugarCRM::Module
- Inherits:
-
Object
- Object
- SugarCRM::Module
- Defined in:
- lib/sugarcrm/module.rb
Overview
A class for handling SugarCRM Modules
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#link_fields ⇒ Object
readonly
Returns the value of attribute link_fields.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
-
.find(name) ⇒ Object
Finds a module by name, or klass name.
-
.initialized? ⇒ Boolean
Class variable to track if we’ve initialized or not.
-
.register_all ⇒ Object
Registers all of the SugarCRM Modules.
Instance Method Summary collapse
- #fields? ⇒ Boolean
- #handle_empty_array ⇒ Object
-
#initialize(name) ⇒ Module
constructor
Dynamically register objects based on Module name I.e.
- #link_fields? ⇒ Boolean
-
#register ⇒ Object
Registers a single module by name Adds module to SugarCRM.modules (SugarCRM.modules << Module.new(“Users”)) Adds module class to SugarCRM parent module (SugarCRM.constants << User) Note, SugarCRM::User.module == Module.find(“Users”).
- #registered? ⇒ Boolean
- #to_class ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Module
Dynamically register objects based on Module name I.e. a SugarCRM Module named Users will generate a SugarCRM::User class.
13 14 15 16 17 18 19 20 21 |
# File 'lib/sugarcrm/module.rb', line 13 def initialize(name) @name = name @klass = name.classify @table_name = name.tableize @fields = {} @link_fields = {} @fields_registered = false self end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
7 8 9 |
# File 'lib/sugarcrm/module.rb', line 7 def fields @fields end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
6 7 8 |
# File 'lib/sugarcrm/module.rb', line 6 def klass @klass end |
#link_fields ⇒ Object (readonly)
Returns the value of attribute link_fields.
8 9 10 |
# File 'lib/sugarcrm/module.rb', line 8 def link_fields @link_fields end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/sugarcrm/module.rb', line 4 def name @name end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
5 6 7 |
# File 'lib/sugarcrm/module.rb', line 5 def table_name @table_name end |
Class Method Details
.find(name) ⇒ Object
Finds a module by name, or klass name
96 97 98 99 100 101 102 103 |
# File 'lib/sugarcrm/module.rb', line 96 def find(name) register_all unless initialized? SugarCRM.modules.each do |m| return m if m.name == name return m if m.klass == name end false end |
.initialized? ⇒ Boolean
Class variable to track if we’ve initialized or not
106 107 108 |
# File 'lib/sugarcrm/module.rb', line 106 def initialized? @initialized ||= false end |
.register_all ⇒ Object
Registers all of the SugarCRM Modules
87 88 89 90 91 92 93 |
# File 'lib/sugarcrm/module.rb', line 87 def register_all SugarCRM.connection.get_modules.each do |m| SugarCRM.modules << m.register end @initialized = true true end |
Instance Method Details
#fields? ⇒ Boolean
32 33 34 |
# File 'lib/sugarcrm/module.rb', line 32 def fields? @fields_registered end |
#handle_empty_array ⇒ Object
46 47 48 49 50 |
# File 'lib/sugarcrm/module.rb', line 46 def handle_empty_array if @link_fields.class == Array && @link_fields.length == 0 @link_fields = {} end end |
#link_fields? ⇒ Boolean
42 43 44 |
# File 'lib/sugarcrm/module.rb', line 42 def link_fields? @fields_registered end |
#register ⇒ Object
Registers a single module by name Adds module to SugarCRM.modules (SugarCRM.modules << Module.new(“Users”)) Adds module class to SugarCRM parent module (SugarCRM.constants << User) Note, SugarCRM::User.module == Module.find(“Users”)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sugarcrm/module.rb', line 56 def register return self if registered? mod_instance = self # class Class < SugarCRM::Base # module_name = "Accounts" # end klass = Class.new(SugarCRM::Base) do self._module = mod_instance end # class Account < SugarCRM::Base SugarCRM.const_set self.klass, klass self end |
#registered? ⇒ Boolean
71 72 73 |
# File 'lib/sugarcrm/module.rb', line 71 def registered? SugarCRM.const_defined? @klass end |
#to_class ⇒ Object
79 80 81 |
# File 'lib/sugarcrm/module.rb', line 79 def to_class SugarCRM.const_get(@klass).new end |
#to_s ⇒ Object
75 76 77 |
# File 'lib/sugarcrm/module.rb', line 75 def to_s @name end |