Class: Fixtory::DSL::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/fixtory/dsl/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#_blockObject

Returns the value of attribute _block.



9
10
11
# File 'lib/fixtory/dsl/table.rb', line 9

def _block
  @_block
end

#_builderObject

Returns the value of attribute _builder.



6
7
8
# File 'lib/fixtory/dsl/table.rb', line 6

def _builder
  @_builder
end

#_model_classObject

Returns the value of attribute _model_class.



8
9
10
# File 'lib/fixtory/dsl/table.rb', line 8

def _model_class
  @_model_class
end

#_nameObject

Returns the value of attribute _name.



4
5
6
# File 'lib/fixtory/dsl/table.rb', line 4

def _name
  @_name
end

#_rowsObject

Returns the value of attribute _rows.



7
8
9
# File 'lib/fixtory/dsl/table.rb', line 7

def _rows
  @_rows
end

#_table_nameObject

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