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 << <<~EOS def #{r[:name]} @#{r[:name]} end def #{r[:name]}=(records) @#{r[:name]} = records.map{|attributes| #{r[:class_name]}.new(attributes)} end EOS end end |
#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 <<~EOS class << self def field_names @field_names ||= #{ schema.field_names } end def parent_relations @parent_relations ||= #{ schema.parent_relations } end def children_relations @children_relations ||= #{ schema.children_relations } end end EOS end |
#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 << <<~EOS def #{name} @#{name} end def #{name}=(value) @#{name} = value return if %i[Id LastModifiedDate IsDeleted SystemModstamp CreatedById CreatedDate LastModifiedById].include?(:#{name}) current_attributes[:#{name}] = value if current_attributes[:#{name}] == original_attributes[:#{name}] updated_attributes[:#{name}] = nil else updated_attributes[:#{name}] = value end end EOS end end |
#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 << <<~EOS def #{r[:name]} @#{r[:name]} end def #{r[:name]}=(attributes) @#{r[:name]} = attributes.nil? ? nil : #{r[:class_name]}.new(attributes) end EOS end end |
#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 <<~Klass Class.new do include ::SfCli::Sf::Model::BaseMethods include ::SfCli::Sf::Model::DmlMethods include ::SfCli::Sf::Model::QueryMethods attr_reader :original_attributes, :current_attributes, :updated_attributes #{ class_methods } #{ field_attribute_methods } #{ parent_relation_methods } #{ children_relation_methods } end Klass end |