Class: ActiveShard::Fixtures::Schema

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#schemaObject (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_shardObject



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

#shardsObject



65
66
67
# File 'lib/active_shard/fixtures.rb', line 65

def shards
  by_shard.values
end