Class: SmartCollection::Config
- Inherits:
-
Object
- Object
- SmartCollection::Config
- Defined in:
- lib/smart_collection/config.rb
Instance Attribute Summary collapse
-
#cache_manager ⇒ Object
Returns the value of attribute cache_manager.
-
#raw_config ⇒ Object
readonly
Returns the value of attribute raw_config.
Instance Method Summary collapse
- #cache_config ⇒ Object
- #cache_expires_in_proc ⇒ Object
- #cache_table_name ⇒ Object
- #check_config ⇒ Object
-
#initialize(raw_config) ⇒ Config
constructor
A new instance of Config.
- #inverse_association ⇒ Object
- #item_class ⇒ Object
- #item_class_name ⇒ Object
- #item_name ⇒ Object
- #items_name ⇒ Object
- #scopes_proc ⇒ Object
Constructor Details
#initialize(raw_config) ⇒ Config
Returns a new instance of Config.
6 7 8 9 |
# File 'lib/smart_collection/config.rb', line 6 def initialize raw_config @raw_config = raw_config check_config end |
Instance Attribute Details
#cache_manager ⇒ Object
Returns the value of attribute cache_manager.
3 4 5 |
# File 'lib/smart_collection/config.rb', line 3 def cache_manager @cache_manager end |
#raw_config ⇒ Object (readonly)
Returns the value of attribute raw_config.
4 5 6 |
# File 'lib/smart_collection/config.rb', line 4 def raw_config @raw_config end |
Instance Method Details
#cache_config ⇒ Object
27 28 29 |
# File 'lib/smart_collection/config.rb', line 27 def cache_config @raw_config[:cached_by] end |
#cache_expires_in_proc ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# 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 ⇒ Object
46 47 48 49 50 51 52 |
# 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 ⇒ Object
67 68 69 70 71 72 73 |
# 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 ⇒ Object
42 43 44 |
# File 'lib/smart_collection/config.rb', line 42 def inverse_association @raw_config[:inverse_association] end |
#item_class ⇒ Object
23 24 25 |
# File 'lib/smart_collection/config.rb', line 23 def item_class @item_class ||= item_class_name.constantize end |
#item_class_name ⇒ Object
19 20 21 |
# File 'lib/smart_collection/config.rb', line 19 def item_class_name @raw_config[:item_class_name] end |
#item_name ⇒ Object
15 16 17 |
# File 'lib/smart_collection/config.rb', line 15 def item_name items_name.to_s.singularize.to_sym end |
#items_name ⇒ Object
11 12 13 |
# File 'lib/smart_collection/config.rb', line 11 def items_name @raw_config[:item_association] end |
#scopes_proc ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# 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 |