Module: ToFixture

Defined in:
lib/to_fixture.rb,
lib/to_fixture/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#columns_for_fixtureObject



20
21
22
# File 'lib/to_fixture.rb', line 20

def columns_for_fixture
  self.class.column_names - all_timestamp_attributes.map(&:to_s) - %w(id)
end

#to_fixture(label = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/to_fixture.rb', line 6

def to_fixture(label = nil)
  label = "#{self.class.table_name}_#{self.id}" unless label

  inspection = if defined?(@attributes) && @attributes
    columns_for_fixture.collect do |name|
      "  #{name}: #{read_attribute(name)}" if has_attribute?(name)
    end.compact.join("\n")
  else
    "not initialized"
  end

  "#{label}:\n#{inspection}"
end