Class: SObjectModel::ClassDefinition
- Inherits:
-
Object
- Object
- SObjectModel::ClassDefinition
- Defined in:
- lib/sobject_model/class_definition.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #child_relation_methods ⇒ Object
- #class_methods ⇒ Object
- #field_attribute_methods ⇒ Object
-
#initialize(schema) ⇒ ClassDefinition
constructor
A new instance of ClassDefinition.
- #parent_relation_methods ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(schema) ⇒ ClassDefinition
Returns a new instance of ClassDefinition.
10 11 12 |
# File 'lib/sobject_model/class_definition.rb', line 10 def initialize(schema) @schema = Schema.new(schema) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
8 9 10 |
# File 'lib/sobject_model/class_definition.rb', line 8 def schema @schema end |
Instance Method Details
#child_relation_methods ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sobject_model/class_definition.rb', line 86 def child_relation_methods schema.child_relations.each_with_object('') do |r, s| s << " def \#{r[:name]}\n @\#{r[:name]}\n end\n\n def \#{r[:name]}=(records)\n @\#{r[:name]} = records.map{|attributes| \#{r[:class_name]}.new(attributes)}\n end\n EOS\n end\nend\n" |
#class_methods ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sobject_model/class_definition.rb', line 32 def class_methods " class << self\n def field_names\n @field_names ||= \#{ schema.field_names }\n end\n\n def parent_relations\n @parent_relations ||= \#{ schema.parent_relations }\n end\n\n def child_relations\n @child_relations ||= \#{ schema.child_relations }\n end\n end\n EOS\nend\n" |
#field_attribute_methods ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sobject_model/class_definition.rb', line 50 def field_attribute_methods schema.field_names.each_with_object('') do |name, s| s << " def \#{name}\n @\#{name}\n end\n\n def \#{name}=(value)\n @\#{name} = value\n return if %i[Id LastModifiedDate IsDeleted SystemModstamp CreatedById CreatedDate LastModifiedById].include?(:\#{name})\n\n current_attributes[:\#{name}] = value\n if current_attributes[:\#{name}] == original_attributes[:\#{name}]\n updated_attributes[:\#{name}] = nil\n else\n updated_attributes[:\#{name}] = (value.nil? ? :null : value)\n end\n end\n EOS\n end\nend\n" |
#parent_relation_methods ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sobject_model/class_definition.rb', line 72 def parent_relation_methods schema.parent_relations.each_with_object('') do |r, s| s << " def \#{r[:name]}\n @\#{r[:name]}\n end\n\n def \#{r[:name]}=(attributes)\n @\#{r[:name]} = attributes.nil? ? nil : \#{r[:class_name]}.new(attributes)\n end\n EOS\n end\nend\n" |
#to_s ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sobject_model/class_definition.rb', line 14 def to_s " Class.new do\n include ::SObjectModel::BaseMethods\n include ::SObjectModel::DmlMethods\n include ::SObjectModel::QueryMethods\n\n attr_reader :original_attributes, :current_attributes, :updated_attributes\n\n \#{ class_methods }\n\n \#{ field_attribute_methods }\n \#{ parent_relation_methods }\n \#{ child_relation_methods }\n end\n Klass\nend\n" |