Class: Dataset::Record::Fixture
- Inherits:
-
Object
- Object
- Dataset::Record::Fixture
- Defined in:
- lib/dataset/record/fixture.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#session_binding ⇒ Object
readonly
Returns the value of attribute session_binding.
-
#symbolic_name ⇒ Object
readonly
Returns the value of attribute symbolic_name.
Instance Method Summary collapse
- #create ⇒ Object
- #id ⇒ Object
-
#initialize(meta, attributes, symbolic_name, session_binding) ⇒ Fixture
constructor
A new instance of Fixture.
- #install_default_attributes! ⇒ Object
- #install_timestamps! ⇒ Object
- #now(column) ⇒ Object
- #record_class ⇒ Object
- #to_fixture ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(meta, attributes, symbolic_name, session_binding) ⇒ Fixture
Returns a new instance of Fixture.
9 10 11 12 13 14 15 16 |
# File 'lib/dataset/record/fixture.rb', line 9 def initialize(, attributes, symbolic_name, session_binding) @meta = @attributes = attributes.stringify_keys @symbolic_name = symbolic_name || object_id @session_binding = session_binding install_default_attributes! end |
Instance Attribute Details
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
7 8 9 |
# File 'lib/dataset/record/fixture.rb', line 7 def @meta end |
#session_binding ⇒ Object (readonly)
Returns the value of attribute session_binding.
7 8 9 |
# File 'lib/dataset/record/fixture.rb', line 7 def session_binding @session_binding end |
#symbolic_name ⇒ Object (readonly)
Returns the value of attribute symbolic_name.
7 8 9 |
# File 'lib/dataset/record/fixture.rb', line 7 def symbolic_name @symbolic_name end |
Instance Method Details
#create ⇒ Object
18 19 20 21 |
# File 'lib/dataset/record/fixture.rb', line 18 def create record_class.connection.insert_fixture to_fixture, .table_name id end |
#id ⇒ Object
23 24 25 |
# File 'lib/dataset/record/fixture.rb', line 23 def id @attributes['id'] end |
#install_default_attributes! ⇒ Object
45 46 47 48 |
# File 'lib/dataset/record/fixture.rb', line 45 def install_default_attributes! @attributes['id'] ||= symbolic_name.to_s.hash.abs end |
#install_timestamps! ⇒ Object
50 51 52 53 54 |
# File 'lib/dataset/record/fixture.rb', line 50 def ..each do |column| @attributes[column.name] = now(column) unless @attributes.key?(column.name) end end |
#now(column) ⇒ Object
56 57 58 |
# File 'lib/dataset/record/fixture.rb', line 56 def now(column) (ActiveRecord::Base.default_timezone == :utc ? Time.now.utc : Time.now).to_s(:db) end |
#record_class ⇒ Object
27 28 29 |
# File 'lib/dataset/record/fixture.rb', line 27 def record_class .record_class end |
#to_fixture ⇒ Object
31 32 33 |
# File 'lib/dataset/record/fixture.rb', line 31 def to_fixture ::Fixture.new(to_hash, .class_name) end |
#to_hash ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/dataset/record/fixture.rb', line 35 def to_hash hash = @attributes.dup hash[.inheritance_column] = .sti_name if .inheriting_record? record_class.reflections.each do |name, reflection| name = name.to_s add_reflection_attributes(hash, name, reflection) if hash[name] end hash end |