Class: ArCache::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_cache/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#cache_storeObject (readonly)

Returns the value of attribute cache_store.



8
9
10
# File 'lib/ar_cache/configuration.rb', line 8

def cache_store
  @cache_store
end

#coderObject (readonly)

Returns the value of attribute coder.



8
9
10
# File 'lib/ar_cache/configuration.rb', line 8

def coder
  @coder
end

#column_lengthObject

Returns the value of attribute column_length.



7
8
9
# File 'lib/ar_cache/configuration.rb', line 7

def column_length
  @column_length
end

#disabledObject

Returns the value of attribute disabled.



7
8
9
# File 'lib/ar_cache/configuration.rb', line 7

def disabled
  @disabled
end

#expires_inObject

Returns the value of attribute expires_in.



7
8
9
# File 'lib/ar_cache/configuration.rb', line 7

def expires_in
  @expires_in
end

#read_uncommittedObject

Returns the value of attribute read_uncommitted.



7
8
9
# File 'lib/ar_cache/configuration.rb', line 7

def read_uncommitted
  @read_uncommitted
end

#select_disabledObject

Returns the value of attribute select_disabled.



7
8
9
# File 'lib/ar_cache/configuration.rb', line 7

def select_disabled
  @select_disabled
end

#tables_optionsObject (readonly)

Returns the value of attribute tables_options.



8
9
10
# File 'lib/ar_cache/configuration.rb', line 8

def tables_options
  @tables_options
end

Class Method Details

.cache_store=(cache_store) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/ar_cache/configuration.rb', line 14

def self.cache_store=(cache_store)
  unless cache_store.is_a?(ActiveSupport::Cache::Store)
    raise ArgumentError, 'The cache_store must be an ActiveSupport::Cache::Store object'
  end

  @cache_store = cache_store
end

.coder=(coder) ⇒ Object

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/ar_cache/configuration.rb', line 34

def self.coder=(coder)
  raise ArgumentError, 'The coder only support use YAML or JSON' unless [::YAML, ::JSON].include?(coder)

  @coder = coder
end

.configureObject



10
11
12
# File 'lib/ar_cache/configuration.rb', line 10

def self.configure
  block_given? ? yield(self) : self
end

.get_table_options(name) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/ar_cache/configuration.rb', line 40

def self.get_table_options(name)
  options = tables_options[name.to_sym] || {}
  options[:disabled] = disabled unless options.key?(:disabled)
  options[:select_disabled] = select_disabled unless options.key?(:select_disabled)
  options[:unique_indexes] = Array(options[:unique_indexes]).map { |index| Array(index).map(&:to_s).uniq }.uniq
  options
end

.tables_options=(options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ar_cache/configuration.rb', line 22

def self.tables_options=(options)
  options.each do |name, hash|
    raise ArgumentError, "The #{name.inspect} must be converted to Symbol type" unless name.is_a?(Symbol)

    hash.each_key do |k|
      raise ArgumentError, "The #{k.inspect} must be converted to Symbol type" unless k.is_a?(Symbol)
    end
  end

  @tables_options = options
end