Module: XBar

Defined in:
lib/xbar.rb,
lib/xbar/shard.rb,
lib/xbar/mapper.rb,
lib/xbar/version.rb,
lib/xbar/rails2/association.rb,
lib/xbar/rails2/persistence.rb,
lib/xbar/rails3/association.rb,
lib/xbar/rails3/persistence.rb

Defined Under Namespace

Modules: Association, AssociationCollection, HasAndBelongsToManyAssociation, Mapper, Migration, Model, Rails2, Rails3, SingularAssociation Classes: ConfigError, Logger, Proxy, RuntimeError, ScopeProxy, Shard

Constant Summary collapse

VERSION =
'0.4.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.debugObject

Returns the value of attribute debug.



19
20
21
# File 'lib/xbar.rb', line 19

def debug
  @debug
end

Class Method Details

.collect_stats?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/xbar.rb', line 50

def self.collect_stats?
  @stats ||= false
end

.configObject



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

def self.config
  XBar::Mapper.config
end

.directoryObject

Returns the Rails.root_to_s when you are using rails Running the current directory in a generic Ruby process



34
35
36
# File 'lib/xbar.rb', line 34

def self.directory
  @directory ||= defined?(Rails) ?  Rails.root.to_s : Dir.pwd
end

.directory=(dir) ⇒ Object



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

def self.directory=(dir)
  @directory = dir
end

.disable_statsObject



46
47
48
# File 'lib/xbar.rb', line 46

def self.disable_stats
  @stats = false
end

.enable_statsObject



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

def self.enable_stats
  @stats = true
end

.environmentsObject



64
65
66
# File 'lib/xbar.rb', line 64

def self.environments
  @environments || ['production', 'test', 'development']
end

.environments=(environments) ⇒ Object



60
61
62
# File 'lib/xbar.rb', line 60

def self.environments=(environments)
  @environments = environments.map { |element| element.to_s }
end

.rails31?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/xbar.rb', line 72

def self.rails31?
  ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1
end

.rails32?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/xbar.rb', line 76

def self.rails32?
  ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 2
end

.rails3?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/xbar.rb', line 68

def self.rails3?
  ActiveRecord::VERSION::MAJOR == 3
end

.rails?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/xbar.rb', line 80

def self.rails?
  defined?(Rails)
end

.rails_envObject

There is no corresponding ‘setter’ method because this is not how the Rails environment is set.



24
25
26
# File 'lib/xbar.rb', line 24

def self.rails_env
  defined?(Rails) ? Rails.env.to_s : nil
end

.setup {|_self| ... } ⇒ Object

This is the default way to do XBar Setup

Yields:

  • (_self)

Yield Parameters:

  • _self (XBar)

    the object that the method was called on



56
57
58
# File 'lib/xbar.rb', line 56

def self.setup
  yield self
end

.shards=(shards) ⇒ Object



84
85
86
# File 'lib/xbar.rb', line 84

def self.shards=(shards)
  XBar::Mapper.shards = shards
end

.using(shard, &block) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/xbar.rb', line 88

def self.using(shard, &block)
  conn = ActiveRecord::Base.connection
  if conn.is_a?(XBar::Proxy)
    conn.run_queries_on_shard(shard, &block)
  else
    yield
  end
end