Class: SObjectModel::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/sobject_model/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Generator

Returns a new instance of Generator.



8
9
10
# File 'lib/sobject_model/generator.rb', line 8

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



6
7
8
# File 'lib/sobject_model/generator.rb', line 6

def connection
  @connection
end

Instance Method Details

#connected?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/sobject_model/generator.rb', line 12

def connected?
  connection.nil? == false
end

#generate(*object_types) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sobject_model/generator.rb', line 16

def generate(*object_types)
  generated_types = []
  object_types.each do |object_type|
    next if generated? object_type

    schema = describe(object_type)
    class_definition = ClassDefinition.new(schema)

    instance_eval "::#{object_type} = #{class_definition}"
    klass = Object.const_get object_type.to_sym
    klass.connection = connection
    SObjectModel.generated_classes << klass
    generated_types << object_type
  end

  generated_types
end