Class: Cash::Config::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/cash/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(active_record, options = {}) ⇒ Config

Returns a new instance of Config.



49
50
51
# File 'lib/cash/config.rb', line 49

def initialize(active_record, options = {})
  @active_record, @options = active_record, options
end

Instance Attribute Details

#active_recordObject (readonly)

Returns the value of attribute active_record.



47
48
49
# File 'lib/cash/config.rb', line 47

def active_record
  @active_record
end

#optionsObject (readonly)

Returns the value of attribute options.



47
48
49
# File 'lib/cash/config.rb', line 47

def options
  @options
end

Instance Method Details

#indicesObject



66
67
68
# File 'lib/cash/config.rb', line 66

def indices
  @indices ||= active_record == ActiveRecord::Base ? [] : [Index.new(self, active_record, active_record.primary_key)]
end

#inherit(active_record) ⇒ Object



70
71
72
# File 'lib/cash/config.rb', line 70

def inherit(active_record)
  Cash::Config.create(active_record, @options, indices)
end

#repositoryObject



53
54
55
# File 'lib/cash/config.rb', line 53

def repository
  @options[:repository]
end

#ttlObject



57
58
59
60
# File 'lib/cash/config.rb', line 57

def ttl
  repository_ttl = repository.respond_to?(:default_ttl) ? repository.default_ttl : nil
  @ttl ||= @options[:ttl] || repository_ttl || 1.day
end

#versionObject



62
63
64
# File 'lib/cash/config.rb', line 62

def version
  @options[:version] || 1
end