Class: MultiGit::Config::Section
- Inherits:
-
Object
- Object
- MultiGit::Config::Section
- Includes:
- Enumerable
- Defined in:
- lib/multi_git/config.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
Instance Method Summary collapse
- #[](key) ⇒ Object (also: #get)
- #default?(key) ⇒ Boolean
-
#each ⇒ Object
Expensive.
- #each_explicit_key ⇒ Object
-
#initialize(config, section, subsection) ⇒ Section
constructor
A new instance of Section.
- #schema_for(key) ⇒ Object
-
#to_h ⇒ Object
Expensive.
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
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
11 12 13 |
# File 'lib/multi_git/config.rb', line 11 def schema @schema end |
#section ⇒ Object (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
24 25 26 |
# File 'lib/multi_git/config.rb', line 24 def default?( key ) config.get(section, subsection, key) == schema_for(key).default end |
#each ⇒ Object
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_key ⇒ Object
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_h ⇒ Object
Expensive. Use only for debug.
51 52 53 |
# File 'lib/multi_git/config.rb', line 51 def to_h Hash[each.to_a] end |