Class: Yamori::Generator
- Inherits:
-
Object
- Object
- Yamori::Generator
- Defined in:
- lib/yamori/generator.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #connected? ⇒ Boolean
- #generate(*object_types) ⇒ Object
-
#initialize(connection) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(connection) ⇒ Generator
Returns a new instance of Generator.
7 8 9 |
# File 'lib/yamori/generator.rb', line 7 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/yamori/generator.rb', line 5 def connection @connection end |
Instance Method Details
#connected? ⇒ Boolean
11 12 13 |
# File 'lib/yamori/generator.rb', line 11 def connected? connection.nil? == false end |
#generate(*object_types) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/yamori/generator.rb', line 15 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 generated_types << object_type end generated_types end |