Class: Fixture
- Inherits:
-
Object
- Object
- Fixture
- Includes:
- Enumerable
- Defined in:
- activerecord/lib/active_record/fixtures.rb
Overview
:nodoc:
Defined Under Namespace
Classes: FixtureError, FormatError
Instance Attribute Summary (collapse)
-
- (Object) model_class
readonly
Returns the value of attribute model_class.
Instance Method Summary (collapse)
- - (Object) [](key)
- - (Object) class_name
- - (Object) each
- - (Object) find
-
- (Fixture) initialize(fixture, model_class, connection = ActiveRecord::Base.connection)
constructor
A new instance of Fixture.
- - (Object) key_list
- - (Object) to_hash
- - (Object) value_list
Methods included from Enumerable
#as_json, #each_with_object, #exclude?, #group_by, #index_by, #many?, #sum
Constructor Details
- (Fixture) initialize(fixture, model_class, connection = ActiveRecord::Base.connection)
A new instance of Fixture
780 781 782 783 784 |
# File 'activerecord/lib/active_record/fixtures.rb', line 780 def initialize(fixture, model_class, connection = ActiveRecord::Base.connection) @connection = connection @fixture = fixture @model_class = model_class.is_a?(Class) ? model_class : model_class.constantize rescue nil end |
Instance Attribute Details
- (Object) model_class (readonly)
Returns the value of attribute model_class
778 779 780 |
# File 'activerecord/lib/active_record/fixtures.rb', line 778 def model_class @model_class end |
Instance Method Details
- (Object) [](key)
794 795 796 |
# File 'activerecord/lib/active_record/fixtures.rb', line 794 def [](key) @fixture[key] end |
- (Object) class_name
786 787 788 |
# File 'activerecord/lib/active_record/fixtures.rb', line 786 def class_name @model_class.name if @model_class end |
- (Object) each
790 791 792 |
# File 'activerecord/lib/active_record/fixtures.rb', line 790 def each @fixture.each { |item| yield item } end |
- (Object) find
813 814 815 816 817 818 819 |
# File 'activerecord/lib/active_record/fixtures.rb', line 813 def find if model_class model_class.find(self[model_class.primary_key]) else raise FixtureClassNotFound, "No class attached to find." end end |
- (Object) key_list
802 803 804 |
# File 'activerecord/lib/active_record/fixtures.rb', line 802 def key_list @fixture.keys.map { |column_name| @connection.quote_column_name(column_name) }.join(', ') end |
- (Object) to_hash
798 799 800 |
# File 'activerecord/lib/active_record/fixtures.rb', line 798 def to_hash @fixture end |
- (Object) value_list
806 807 808 809 810 811 |
# File 'activerecord/lib/active_record/fixtures.rb', line 806 def value_list cols = (model_class && model_class < ActiveRecord::Base) ? model_class.columns_hash : {} @fixture.map do |key, value| @connection.quote(value, cols[key]).gsub('[^\]\\n', "\n").gsub('[^\]\\r', "\r") end.join(', ') end |