Module: Hashish

Extended by:
Configuration
Defined in:
lib/acts_as_hashish.rb,
lib/acts_as_hashish/hashish.rb,
lib/acts_as_hashish/version.rb,
lib/acts_as_hashish/configuration.rb,
lib/acts_as_hashish/private_class_methods.rb

Defined Under Namespace

Modules: ClassMethods, Configuration, PrivateClassMethods

Constant Summary collapse

VERSION =
'0.4.3'

Instance Attribute Summary

Attributes included from Configuration

#redis_connection, #redis_namespace, #redis_search_keys_ttl

Instance Method Summary collapse

Methods included from Configuration

configure

Instance Method Details

#acts_as_hashish(options = {}) ⇒ Object



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

def acts_as_hashish(options = {})
  unless options.keys.all?{|k| k.is_a?(Symbol)} and options.values.all?{|v| v.is_a?(String) or v.is_a?(Hash)}
    raise "Keys can only be Symbol, values can only be String or Hash" 
  end
  raise "Cannot act as hashish without a redis connection" unless Hashish.redis_connection
  options[:key_prefix] ||= Hashish.redis_namespace + ':' + self.to_s
  raise "Please specify a primary index via the :key option" unless options[:key]
  options[:indexes] ||= {}
  options[:sorters] ||= {}
  
  @options = options
  extend ClassMethods
  extend PrivateClassMethods
end