Class: TestProf::AnyFixture::Dump
- Inherits:
-
Object
- Object
- TestProf::AnyFixture::Dump
- Defined in:
- lib/test_prof/any_fixture/dump.rb,
lib/test_prof/any_fixture/dump/digest.rb,
lib/test_prof/any_fixture/dump/sqlite.rb,
lib/test_prof/any_fixture/dump/postgresql.rb,
lib/test_prof/any_fixture/dump/base_adapter.rb
Defined Under Namespace
Modules: Digest Classes: BaseAdapter, PostgreSQL, SQLite, Subscriber
Instance Attribute Summary collapse
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
-
#success ⇒ Object
(also: #success?)
readonly
Returns the value of attribute success.
Instance Method Summary collapse
- #commit! ⇒ Object
- #exists? ⇒ Boolean
- #force? ⇒ Boolean
-
#initialize(name, watch: [], cache_key: nil) ⇒ Dump
constructor
A new instance of Dump.
- #load ⇒ Object
- #within_prepared_env(before: nil, after: nil, import: false) ⇒ Object
Constructor Details
#initialize(name, watch: [], cache_key: nil) ⇒ Dump
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/test_prof/any_fixture/dump.rb', line 116 def initialize(name, watch: [], cache_key: nil) @name = name @digest = [ Digest.call(*watch), cache_key.to_digest ].compact.join("-") @path = build_path(name, digest) @success = false @adapter = case ActiveRecord::Base.connection.adapter_name when /sqlite/i require "test_prof/any_fixture/dump/sqlite" SQLite.new when /postgresql/i require "test_prof/any_fixture/dump/postgresql" PostgreSQL.new else raise ArgumentError, "Your current database adapter (#{ActiveRecord::Base.connection.adapter_name}) " \ "is currently not supported. So far, we only support SQLite and PostgreSQL" end @subscriber = Subscriber.new(path, adapter) end |
Instance Attribute Details
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
113 114 115 |
# File 'lib/test_prof/any_fixture/dump.rb', line 113 def digest @digest end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
113 114 115 |
# File 'lib/test_prof/any_fixture/dump.rb', line 113 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
113 114 115 |
# File 'lib/test_prof/any_fixture/dump.rb', line 113 def path @path end |
#subscriber ⇒ Object (readonly)
Returns the value of attribute subscriber.
113 114 115 |
# File 'lib/test_prof/any_fixture/dump.rb', line 113 def subscriber @subscriber end |
#success ⇒ Object (readonly) Also known as: success?
Returns the value of attribute success.
113 114 115 |
# File 'lib/test_prof/any_fixture/dump.rb', line 113 def success @success end |
Instance Method Details
#commit! ⇒ Object
158 159 160 |
# File 'lib/test_prof/any_fixture/dump.rb', line 158 def commit! subscriber.commit end |
#exists? ⇒ Boolean
144 145 146 |
# File 'lib/test_prof/any_fixture/dump.rb', line 144 def exists? File.exist?(path) end |
#force? ⇒ Boolean
148 149 150 |
# File 'lib/test_prof/any_fixture/dump.rb', line 148 def force? AnyFixture.config.force_matching_dumps.match?(name) end |
#load ⇒ Object
152 153 154 155 156 |
# File 'lib/test_prof/any_fixture/dump.rb', line 152 def load return import_via_active_record unless AnyFixture.config.import_dump_via_cli? adapter.import(path) || import_via_active_record end |
#within_prepared_env(before: nil, after: nil, import: false) ⇒ Object
162 163 164 165 166 167 168 169 |
# File 'lib/test_prof/any_fixture/dump.rb', line 162 def within_prepared_env(before: nil, after: nil, import: false) run_before_callbacks(callback: before, dump: self, import: false) yield.tap do @success = true end ensure run_after_callbacks(callback: after, dump: self, import: false) end |