Module: XBar::AssociationCollection

Defined in:
lib/xbar/association_collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/xbar/association_collection.rb', line 3

def self.included(base)
  if XBar.rails31?
    base.instance_eval do
      alias_method_chain :reader, :xbar
      alias_method_chain :writer, :xbar
      alias_method_chain :ids_reader, :xbar
      alias_method_chain :ids_writer, :xbar
      alias_method_chain :create, :xbar
      alias_method_chain :create!, :xbar
      alias_method_chain :build, :xbar
    end
  end
end

Instance Method Details

#build_with_xbar(*args) ⇒ Object



17
18
19
20
# File 'lib/xbar/association_collection.rb', line 17

def build_with_xbar(*args)
  owner.reload_connection
  build_without_xbar(*args)
end

#count(*args) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/xbar/association_collection.rb', line 56

def count(*args)
  if should_wrap_the_connection?
    XBar.using(@owner.current_shard) { super }
  else
    super
  end
end

#create_with_xbar(*args) ⇒ Object



42
43
44
45
# File 'lib/xbar/association_collection.rb', line 42

def create_with_xbar(*args)
  owner.reload_connection
  create_without_xbar(*args)
end

#create_with_xbar!(*args) ⇒ Object



47
48
49
50
# File 'lib/xbar/association_collection.rb', line 47

def create_with_xbar!(*args)
  owner.reload_connection
  create_without_xbar!(*args)
end

#ids_reader_with_xbar(*args) ⇒ Object



32
33
34
35
# File 'lib/xbar/association_collection.rb', line 32

def ids_reader_with_xbar(*args)
  owner.reload_connection
  ids_reader_without_xbar(*args)
end

#ids_writer_with_xbar(*args) ⇒ Object



37
38
39
40
# File 'lib/xbar/association_collection.rb', line 37

def ids_writer_with_xbar(*args)
  owner.reload_connection
  ids_writer_without_xbar(*args)
end

#reader_with_xbar(*args) ⇒ Object



22
23
24
25
# File 'lib/xbar/association_collection.rb', line 22

def reader_with_xbar(*args)
  owner.reload_connection
  reader_without_xbar(*args)
end

#should_wrap_the_connection?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/xbar/association_collection.rb', line 52

def should_wrap_the_connection?
  @owner.respond_to?(:current_shard) && @owner.current_shard != nil
end

#writer_with_xbar(*args) ⇒ Object



27
28
29
30
# File 'lib/xbar/association_collection.rb', line 27

def writer_with_xbar(*args)
  owner.reload_connection
  writer_without_xbar(*args)
end