Class: Curator::Repository::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/curator/repository/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_settings = {}) ⇒ Settings

Returns a new instance of Settings.



10
11
12
13
# File 'lib/curator/repository/settings.rb', line 10

def initialize(current_settings = {})
  @all = HashWithIndifferentAccess.new(current_settings)
  clear_dirty!
end

Instance Attribute Details

#allObject (readonly) Also known as: to_hash

Returns the value of attribute all.



7
8
9
# File 'lib/curator/repository/settings.rb', line 7

def all
  @all
end

#changedObject (readonly)

Returns the value of attribute changed.



7
8
9
# File 'lib/curator/repository/settings.rb', line 7

def changed
  @changed
end

Instance Method Details

#[](property) ⇒ Object



31
32
33
# File 'lib/curator/repository/settings.rb', line 31

def [](property)
  all[property]
end

#apply!(opts = {}) ⇒ Object



43
44
45
46
47
# File 'lib/curator/repository/settings.rb', line 43

def apply!(opts = {})
  data_store = opts.fetch(:data_store)
  collection_name = opts.fetch(:collection_name)
  clear_dirty! if data_store.update_settings!(collection_name, changed)
end

#clear_dirty!Object



39
40
41
# File 'lib/curator/repository/settings.rb', line 39

def clear_dirty!
  @changed = HashWithIndifferentAccess.new
end

#disable(property) ⇒ Object



27
28
29
# File 'lib/curator/repository/settings.rb', line 27

def disable(property)
  set(property, false)
end

#enable(property) ⇒ Object



23
24
25
# File 'lib/curator/repository/settings.rb', line 23

def enable(property)
  set(property, true)
end

#set(property, value) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/curator/repository/settings.rb', line 15

def set(property, value)
  original_value = all[property]
  unless value == original_value
    all[property] = value
    changed[property] = value
  end
end

#uncommitted?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/curator/repository/settings.rb', line 35

def uncommitted?
  changed.any?
end