Class: SfCli::Sf::Model::ClassDefinition
- Inherits:
-
Object
- Object
- SfCli::Sf::Model::ClassDefinition
- Defined in:
- lib/sf_cli/sf/model/class_definition.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #children_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.
12 13 14 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 12 def initialize(schema) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
10 11 12 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 10 def schema @schema end |
Instance Method Details
#children_relation_methods ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 88 def children_relation_methods schema.children_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
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 34 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 children_relations\n @children_relations ||= \#{ schema.children_relations }\n end\n end\n EOS\nend\n" |
#field_attribute_methods ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 52 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\n end\n end\n EOS\n end\nend\n" |
#parent_relation_methods ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 74 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sf_cli/sf/model/class_definition.rb', line 16 def to_s " Class.new do\n include ::SfCli::Sf::Model::BaseMethods\n include ::SfCli::Sf::Model::DmlMethods\n include ::SfCli::Sf::Model::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 \#{ children_relation_methods }\n end\n Klass\nend\n" |