Class: Fixtory::DSL::Table
- Inherits:
-
Object
- Object
- Fixtory::DSL::Table
- Defined in:
- lib/fixtory/dsl/table.rb
Instance Attribute Summary collapse
-
#_block ⇒ Object
Returns the value of attribute _block.
-
#_builder ⇒ Object
Returns the value of attribute _builder.
-
#_model_class ⇒ Object
Returns the value of attribute _model_class.
-
#_name ⇒ Object
Returns the value of attribute _name.
-
#_rows ⇒ Object
Returns the value of attribute _rows.
-
#_table_name ⇒ Object
Returns the value of attribute _table_name.
Instance Method Summary collapse
- #_row(name, &block) ⇒ Object
-
#initialize(name, builder, &block) ⇒ Table
constructor
A new instance of Table.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(name, builder, &block) ⇒ Table
Returns a new instance of Table.
11 12 13 14 15 16 17 |
# File 'lib/fixtory/dsl/table.rb', line 11 def initialize(name, builder, &block) @_name = name.to_s @_table_name = _model_class.table_name @_builder = builder @_rows = [] @_block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/fixtory/dsl/table.rb', line 31 def method_missing(method, *args, &block) if block && block.respond_to?(:call) _row(method, &block) else method = method.to_s if @_block instance_eval(&_block) @_block = nil end row = _rows.find do |row| row.instance_eval('@name') == method end if row != nil if row.instance_eval("@inserted") _model_class.find(row._primary_key_value) else row end else super end end end |
Instance Attribute Details
#_block ⇒ Object
Returns the value of attribute _block.
9 10 11 |
# File 'lib/fixtory/dsl/table.rb', line 9 def _block @_block end |
#_builder ⇒ Object
Returns the value of attribute _builder.
6 7 8 |
# File 'lib/fixtory/dsl/table.rb', line 6 def _builder @_builder end |
#_model_class ⇒ Object
Returns the value of attribute _model_class.
8 9 10 |
# File 'lib/fixtory/dsl/table.rb', line 8 def _model_class @_model_class end |
#_name ⇒ Object
Returns the value of attribute _name.
4 5 6 |
# File 'lib/fixtory/dsl/table.rb', line 4 def _name @_name end |
#_rows ⇒ Object
Returns the value of attribute _rows.
7 8 9 |
# File 'lib/fixtory/dsl/table.rb', line 7 def _rows @_rows end |
#_table_name ⇒ Object
Returns the value of attribute _table_name.
5 6 7 |
# File 'lib/fixtory/dsl/table.rb', line 5 def _table_name @_table_name end |
Instance Method Details
#_row(name, &block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/fixtory/dsl/table.rb', line 23 def _row(name, &block) row = ::Fixtory::DSL::Row.new(name, self, &block) if _sti_table? row.instance_eval('@attributes')['type'] = _name.singularize.camelize end _rows << row end |