Class: ActiveShard::Fixtures

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shard/fixtures.rb

Defined Under Namespace

Classes: Schema, Shard

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



30
31
32
# File 'lib/active_shard/fixtures.rb', line 30

def [](key)
  by_schema[key]
end

.by_schemaObject



22
23
24
# File 'lib/active_shard/fixtures.rb', line 22

def by_schema
  @by_schema ||= {}
end

.create_fixtures(fixtures_dir, *args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/active_shard/fixtures.rb', line 5

def create_fixtures(fixtures_dir, *args)
  schemas = ActiveShard.schemas.map(&:to_sym) & Dir.entries(fixtures_dir).map(&:to_sym)

  self.by_schema.merge!(
    schemas.inject({}) do |hash, schema|
      hash[schema] = Schema.new(schema, File.join(fixtures_dir, schema.to_s), *args)
      hash
    end
  )
end

.reset!Object



16
17
18
19
20
# File 'lib/active_shard/fixtures.rb', line 16

def reset!
  schemas.each(&:reset!)

  @by_schema = {}
end

.schemasObject



26
27
28
# File 'lib/active_shard/fixtures.rb', line 26

def schemas
  by_schema.values
end

.setup_fixture_accessors(obj) ⇒ Object



34
35
36
37
38
# File 'lib/active_shard/fixtures.rb', line 34

def setup_fixture_accessors obj
  schemas.each do |schema|
    schema.setup_fixture_accessors obj
  end
end