Class: ActiveShard::Fixtures::Schema
- Inherits:
-
Object
- Object
- ActiveShard::Fixtures::Schema
- Defined in:
- lib/active_shard/fixtures.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #by_shard ⇒ Object
-
#initialize(schema, schema_fixtures_dir, *args) ⇒ Schema
constructor
A new instance of Schema.
- #reset! ⇒ Object
- #setup_fixture_accessors(obj) ⇒ Object
- #shards ⇒ Object
Constructor Details
#initialize(schema, schema_fixtures_dir, *args) ⇒ Schema
Returns a new instance of Schema.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_shard/fixtures.rb', line 44 def initialize(schema, schema_fixtures_dir, *args) @schema = schema shards = ActiveShard.shards_by_schema(schema).map{|s| s.name.to_sym} & Dir.entries(schema_fixtures_dir).map(&:to_sym) self.by_shard.merge!( shards.inject({}) do |hash, shard| hash[shard] = Shard.new(schema, shard, File.join(schema_fixtures_dir, shard.to_s), *args) hash end ) end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
42 43 44 |
# File 'lib/active_shard/fixtures.rb', line 42 def schema @schema end |
Instance Method Details
#[](key) ⇒ Object
69 70 71 |
# File 'lib/active_shard/fixtures.rb', line 69 def [](key) by_shard[key] end |
#by_shard ⇒ Object
61 62 63 |
# File 'lib/active_shard/fixtures.rb', line 61 def by_shard @by_shard ||= {} end |
#reset! ⇒ Object
57 58 59 |
# File 'lib/active_shard/fixtures.rb', line 57 def reset! shards.each(&:reset!) end |
#setup_fixture_accessors(obj) ⇒ Object
73 74 75 76 77 |
# File 'lib/active_shard/fixtures.rb', line 73 def setup_fixture_accessors obj shards.each do |shard| shard.setup_fixture_accessors obj end end |
#shards ⇒ Object
65 66 67 |
# File 'lib/active_shard/fixtures.rb', line 65 def shards by_shard.values end |