class SmartCollection::Config

Attributes

cache_manager[RW]
raw_config[R]

Public Class Methods

new(raw_config) click to toggle source
# File lib/smart_collection/config.rb, line 6
def initialize raw_config
  @raw_config = raw_config
  check_config
end

Public Instance Methods

cache_config() click to toggle source
# File lib/smart_collection/config.rb, line 27
def cache_config
  @raw_config[:cached_by]
end
cache_expires_in_proc() click to toggle source
# File lib/smart_collection/config.rb, line 54
def cache_expires_in_proc
  case @raw_config[:cache_expires_in]
  when Proc
    @raw_config[:cache_expires_in]
  when ActiveSupport::Duration
    -> (owner) { @raw_config[:cache_expires_in] }
  when Symbol
    -> (owner) { owner.send(@raw_config[:cache_expires_in]) }
  else
    raise "cache_expires_in option only accepts a Proc / ActiveSupport::Duration / Symbol"
  end
end
cache_table_name() click to toggle source
# File lib/smart_collection/config.rb, line 46
def cache_table_name
  if @raw_config[:cache_table] == :default
    :smart_collection_cached_items
  else
    @raw_config[:cache_table]
  end
end
check_config() click to toggle source
# File lib/smart_collection/config.rb, line 67
def check_config
  raise "items option must be provided" if items_name.nil?
  raise "item_class option must be provided" if item_class_name.nil?
  raise "scopes option must be provided" if @raw_config[:scopes].nil?
  raise "cache_table option must be provided" if @raw_config[:cache_table].nil?
  raise "cache_expires_in option must be provided" if @raw_config[:cache_expires_in].nil?
end
inverse_association() click to toggle source
# File lib/smart_collection/config.rb, line 42
def inverse_association
  @raw_config[:inverse_association]
end
item_class() click to toggle source
# File lib/smart_collection/config.rb, line 23
def item_class
  @item_class ||= item_class_name.constantize
end
item_class_name() click to toggle source
# File lib/smart_collection/config.rb, line 19
def item_class_name
  @raw_config[:item_class_name]
end
item_name() click to toggle source
# File lib/smart_collection/config.rb, line 15
def item_name
  items_name.to_s.singularize.to_sym
end
items_name() click to toggle source
# File lib/smart_collection/config.rb, line 11
def items_name
  @raw_config[:item_association]
end
scopes_proc() click to toggle source
# File lib/smart_collection/config.rb, line 31
def scopes_proc
  case @raw_config[:scopes]
  when Proc
    @raw_config[:scopes]
  when Symbol
    -> (owner) { owner.send(@raw_config[:scopes]) }
  else
    raise "scopes option only accepts a Proc / Symbol"
  end
end