Class: MultiGit::Config::Section

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/multi_git/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, section, subsection) ⇒ Section

Returns a new instance of Section.



13
14
15
16
17
18
# File 'lib/multi_git/config.rb', line 13

def initialize(config, section, subsection)
  @config = config
  @section = section
  @subsection = subsection
  @schema = config.schema[section][subsection]
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



11
12
13
# File 'lib/multi_git/config.rb', line 11

def schema
  @schema
end

#sectionObject (readonly)

Returns the value of attribute section.



10
11
12
# File 'lib/multi_git/config.rb', line 10

def section
  @section
end

Instance Method Details

#[](key) ⇒ Object Also known as: get



28
29
30
# File 'lib/multi_git/config.rb', line 28

def [](key)
  config.get(section, subsection, key)
end

#default?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/multi_git/config.rb', line 24

def default?( key )
  config.get(section, subsection, key) == schema_for(key).default
end

#eachObject

Expensive. Use only for debug



42
43
44
45
46
47
48
# File 'lib/multi_git/config.rb', line 42

def each
  return to_enum unless block_given?
  each_explicit_key do |key|
    next if default?(key)
    yield key, get(key)
  end
end

#each_explicit_keyObject



34
35
36
37
38
39
# File 'lib/multi_git/config.rb', line 34

def each_explicit_key
  return to_enum(:each_explicit_key) unless block_given?
  config.each_explicit_key do |sec, subsec, key|
    yield(key) if sec == section && subsec == subsection
  end
end

#schema_for(key) ⇒ Object



20
21
22
# File 'lib/multi_git/config.rb', line 20

def schema_for( key )
  schema[key]
end

#to_hObject

Expensive. Use only for debug.



51
52
53
# File 'lib/multi_git/config.rb', line 51

def to_h
  Hash[each.to_a]
end