Class: Junoser::Display::ConfigStore

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/junoser/display/config_store.rb

Constant Summary collapse

OFFSET =
'    '

Instance Attribute Summary collapse

Attributes included from Enumerable

#in_from, #in_group, #in_then

Instance Method Summary collapse

Methods included from Enumerable

#to_enum

Constructor Details

#initialize(depth = 0) ⇒ ConfigStore

Returns a new instance of ConfigStore.



14
15
16
17
18
# File 'lib/junoser/display/config_store.rb', line 14

def initialize(depth = 0)
  @hash = {}
  @depth = depth
  @deactivated = false
end

Instance Attribute Details

#deactivatedObject

Returns the value of attribute deactivated.



12
13
14
# File 'lib/junoser/display/config_store.rb', line 12

def deactivated
  @deactivated
end

Instance Method Details

#deactivate(deactivated_line) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/junoser/display/config_store.rb', line 30

def deactivate(deactivated_line)
  statement, store = match(deactivated_line)

  if statement
    if statement == deactivated_line
      store.deactivated = true
    else
      store.deactivate(deactivated_line.sub(/^#{statement} */, ''))
    end
  else
    statement, store = inverse_match(deactivated_line)
    store.deactivated = true if statement
  end
end

#each_with_inactive(str = '') ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/junoser/display/config_store.rb', line 45

def each_with_inactive(str = '')
  each do |k, v|
    k = "inactive: #{k}" if v.deactivated
    yield k, v, str
  end

  str
end

#push(str) ⇒ Object Also known as: <<



20
21
22
23
24
25
26
27
# File 'lib/junoser/display/config_store.rb', line 20

def push(str)
  store = self

  join_arg(str).split("\n").each_with_index do |element, index|
    store[element] ||= self.class.new(index + 1)
    store = store[element]
  end
end

#to_sObject



54
55
56
# File 'lib/junoser/display/config_store.rb', line 54

def to_s
  each_with_inactive(+'', &method(:hash_item_to_s))
end