Class: Shameless::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/shameless/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Store

Returns a new instance of Store.



9
10
11
12
13
# File 'lib/shameless/store.rb', line 9

def initialize(name, &block)
  @name = name
  @configuration = Configuration.new
  block.call(@configuration)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/shameless/store.rb', line 7

def name
  @name
end

Instance Method Details

#attach(model_class, name = nil) ⇒ Object



15
16
17
18
19
20
# File 'lib/shameless/store.rb', line 15

def attach(model_class, name = nil)
  model_class.extend(Model)
  model_class.attach_to(self, name)
  @models ||= []
  @models << model_class
end

#create_table!(table_name, &block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/shameless/store.rb', line 34

def create_table!(table_name, &block)
  each_shard do |shard|
    partition = find_partition_for_shard(shard)
    sharded_table_name = table_name_with_shard(table_name, shard)
    partition.create_table(sharded_table_name) { block.call(self) }
  end
end

#create_tables!Object



30
31
32
# File 'lib/shameless/store.rb', line 30

def create_tables!
  @models.each(&:create_tables!)
end

#padded_shard(shardable_value) ⇒ Object



42
43
44
45
# File 'lib/shameless/store.rb', line 42

def padded_shard(shardable_value)
  shard = find_shard(shardable_value)
  format_shard(shard)
end

#put(table_name, shardable_value, values) ⇒ Object



22
23
24
# File 'lib/shameless/store.rb', line 22

def put(table_name, shardable_value, values)
  find_table(table_name, shardable_value).insert(values)
end

#where(table_name, shardable_value, query) ⇒ Object



26
27
28
# File 'lib/shameless/store.rb', line 26

def where(table_name, shardable_value, query)
  find_table(table_name, shardable_value).where(query)
end