class Fixtory::DSL::Table

Attributes

_block[RW]
_builder[RW]
_model_class[RW]
_name[RW]
_rows[RW]
_table_name[RW]

Public Class Methods

new(name, builder, &block) click to toggle source
# 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

Public Instance Methods

_row(name, &block) click to toggle source
# 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
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# 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

Private Instance Methods

_sti_table?() click to toggle source
# File lib/fixtory/dsl/table.rb, line 60
def _sti_table?
  _name != _table_name
end