Class: YamlFixture

Inherits:
Fixture show all
Defined in:
lib/active_record/fixtures.rb

Overview

A YamlFixture is like a fixture, but instead of a name to use as a key, it uses a yaml_name.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Fixture

#[], #key_list, #to_hash, #value_list

Constructor Details

#initialize(yaml_name, fixture) ⇒ YamlFixture

constructor is passed the name & the actual instantiate fixture



157
158
159
# File 'lib/active_record/fixtures.rb', line 157

def initialize(yaml_name, fixture)
  @yaml_name, @fixture = yaml_name, fixture
end

Instance Attribute Details

#yaml_nameObject

yaml_name is equivalent to a normal fixture’s filename



154
155
156
# File 'lib/active_record/fixtures.rb', line 154

def yaml_name
  @yaml_name
end

Class Method Details

.produce(yaml_file_name) ⇒ Object

given a valid yaml file name, create an array of YamlFixture objects



162
163
164
165
166
167
168
169
170
171
# File 'lib/active_record/fixtures.rb', line 162

def self.produce( yaml_file_name )
  results = []
  yaml_file = File.open( yaml_file_name )
  YAML::load_documents( yaml_file ) do |doc|
    f = YamlFixture.new( doc['name'], doc['data'] )
    results << f
  end
  yaml_file.close
  results
end