Class: SfCli::Sf::Model::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/sf_cli/sf/model/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Generator

Returns a new instance of Generator.



10
11
12
# File 'lib/sf_cli/sf/model/generator.rb', line 10

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/sf_cli/sf/model/generator.rb', line 8

def connection
  @connection
end

Instance Method Details

#describe(object_name) ⇒ Object



27
28
29
# File 'lib/sf_cli/sf/model/generator.rb', line 27

def describe(object_name)
  connection.describe object_name
end

#generate(object_name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sf_cli/sf/model/generator.rb', line 14

def generate(object_name)
  return false if generated? object_name

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

  instance_eval "::#{object_name} = #{class_definition}"
  klass = Object.const_get object_name.to_sym
  klass.connection = connection

  true
end

#generated?(object_name) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/sf_cli/sf/model/generator.rb', line 31

def generated?(object_name)
  Object.const_get object_name.to_sym
  true
rescue NameError
  false
end