Class: Fixtory::DSL::Builder
- Inherits:
- BasicObject
- Defined in:
- lib/fixtory/dsl/builder.rb
Instance Attribute Summary collapse
-
#_inserted ⇒ Object
Returns the value of attribute _inserted.
-
#_tables ⇒ Object
Returns the value of attribute _tables.
Instance Method Summary collapse
- #_eval_from_fixtory_file(path) ⇒ Object
- #_insert ⇒ Object
- #_table(name, &block) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
7 8 9 |
# File 'lib/fixtory/dsl/builder.rb', line 7 def initialize @_tables = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fixtory/dsl/builder.rb', line 37 def method_missing(method, *args, &block) if block && block.respond_to?(:call) _table(method, &block) else table = _tables.find do |table| table._name == method.to_s end table || super end end |
Instance Attribute Details
#_inserted ⇒ Object
Returns the value of attribute _inserted.
5 6 7 |
# File 'lib/fixtory/dsl/builder.rb', line 5 def _inserted @_inserted end |
#_tables ⇒ Object
Returns the value of attribute _tables.
4 5 6 |
# File 'lib/fixtory/dsl/builder.rb', line 4 def _tables @_tables end |
Instance Method Details
#_eval_from_fixtory_file(path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/fixtory/dsl/builder.rb', line 15 def _eval_from_fixtory_file(path) contents = ::File.read(path) instance_eval(contents, path, 1) _tables.each do |table| if table._block table.instance_eval(&table._block) table._block = nil end end end |
#_insert ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fixtory/dsl/builder.rb', line 26 def _insert _tables.each do |table| table._rows.each do |row| _connection.insert_fixture(row.instance_eval('@attributes'), table._table_name) row.instance_eval("@inserted = true") end end self._inserted = true end |