Class: StoreConfigurable::DirtyTrackingOrderedOptions

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/store_configurable/dirty_options.rb

Overview

The heart of StoreConfigurable’s data store is this subclass of ActiveSupport’s OrderedOptions. They are the heart of Rails’ configurations and allow you to dynamically set and get hash keys and values using dot property notation vs the [] hash accessors.

However, instances of DirtyTrackingOrderedOptions use a recursive lambda via Hash’s block initialization syntax so that you get a dynamic and endless scope on config data. Instances of DirtyTrackingOrderedOptions also make sure that every sub instance of it self also has a handle back to your store’s owner. In this way when config attributes are added or values change, we can mark your ActiveRecord object as dirty/changed.

Constant Summary collapse

Recursive =
lambda { |h,k| h[k] = h.class.new(h.__store_configurable_owner__) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner) ⇒ DirtyTrackingOrderedOptions

Returns a new instance of DirtyTrackingOrderedOptions.



21
22
23
24
# File 'lib/store_configurable/dirty_options.rb', line 21

def initialize(owner)
  @__store_configurable_owner__ = owner
  super(&Recursive)
end

Instance Attribute Details

#__store_configurable_owner__Object

Returns the value of attribute store_configurable_owner.



19
20
21
# File 'lib/store_configurable/dirty_options.rb', line 19

def __store_configurable_owner__
  @__store_configurable_owner__
end

Instance Method Details

#[]=(key, value) ⇒ Object



26
27
28
29
# File 'lib/store_configurable/dirty_options.rb', line 26

def []=(key, value)
  _config_may_change!(key, value)
  super
end

#clearObject



54
55
56
57
# File 'lib/store_configurable/dirty_options.rb', line 54

def clear
  _config_will_change!
  super
end

#delete(key) ⇒ Object



31
32
33
34
35
# File 'lib/store_configurable/dirty_options.rb', line 31

def delete(key)
  name = key.to_sym
  _config_will_change! if has_key?(name)
  super
end

#delete_ifObject



37
38
39
# File 'lib/store_configurable/dirty_options.rb', line 37

def delete_if
  _with_config_keys_may_change! { super }
end

#dupObject Also known as: reject

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/store_configurable/dirty_options.rb', line 41

def dup
  raise NotImplementedError, 'the StoreConfigurable::Object does not support making a copy'
end

#merge(other) ⇒ Object



46
47
48
# File 'lib/store_configurable/dirty_options.rb', line 46

def merge(other)
  dup
end

#reject!Object



50
51
52
# File 'lib/store_configurable/dirty_options.rb', line 50

def reject!
  _with_config_keys_may_change! { super }
end