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.



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

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.



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

def __store_configurable_owner__
  @__store_configurable_owner__
end

Instance Method Details

#[]=(key, value) ⇒ Object



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

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

#clearObject



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

def clear
  _config_will_change!
  super
end

#delete(key) ⇒ Object



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

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

#delete_ifObject



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

def delete_if
  _with_config_keys_may_change! { super }
end

#dupObject Also known as: reject

Raises:

  • (NotImplementedError)


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

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

#merge(other) ⇒ Object



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

def merge(other)
  dup
end

#reject!Object



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

def reject!
  _with_config_keys_may_change! { super }
end