Module: MultiGit::Config
- Extended by:
- Utils::AbstractMethods
- Includes:
- Enumerable
- Included in:
- GitBackend::Config, JGitBackend::Config, RuggedBackend::Config
- Defined in:
- lib/multi_git/config.rb,
lib/multi_git/config/schema.rb,
lib/multi_git/config/default_schema.rb
Defined Under Namespace
Constant Summary collapse
- DEFAULT_SCHEMA =
Schema.build do section 'core' do bool 'bare', false bool 'filemode', true bool 'logallrefupdates', false int 'repositoryformatversion', 0 end section 'remote' do any_section do array 'url' array 'pushurl' string 'fetch' end end end
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #default?(section, subsection, key) ⇒ Boolean
-
#each ⇒ Object
Expensive.
- #each_explicit_key {|section, subsection, key| ... } ⇒ Object
- #get(section, subsection, key) ⇒ Object private
- #qualified_key(section, subsection = nil, key) ⇒ Object
- #schema ⇒ Object
- #schema_for(section, subsection, key) ⇒ Object
- #section(section, subsection = nil) ⇒ Section
- #split_key(qualified_key) ⇒ Object
-
#to_h ⇒ Object
Expensive.
-
#with_schema(sch) ⇒ Object
private
Dups the object with a different schema.
Methods included from Utils::AbstractMethods
Instance Method Details
#[](section, subsection = nil, key) ⇒ Object #[](qualified_key) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/multi_git/config.rb', line 93 def []( *args ) case( args.size ) when 3 then get( *args ) when 2 then get( args[0], nil, args[1] ) when 1 then get( *split_key(args[0]) ) else raise ArgumentError, "wrong number of arguments (#{args.size} for 1..3)" end end |
#default?(section, subsection, key) ⇒ Boolean
79 80 81 |
# File 'lib/multi_git/config.rb', line 79 def default?( section, subsection, key ) get(section, subsection, key) == schema_for(section, subsection, key).default end |
#each ⇒ Object
Expensive. Use only for debug
139 140 141 142 143 144 145 |
# File 'lib/multi_git/config.rb', line 139 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 {|section, subsection, key| ... } ⇒ Object
111 |
# File 'lib/multi_git/config.rb', line 111 abstract :each_explicit_key |
#get(section, subsection, key) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
107 |
# File 'lib/multi_git/config.rb', line 107 abstract :get |
#qualified_key(section, subsection = nil, key) ⇒ Object
124 125 126 |
# File 'lib/multi_git/config.rb', line 124 def qualified_key( section, subsection = nil, key ) [section, DOT, subsection, subsection ? DOT : nil, key].join end |
#schema ⇒ Object
71 72 73 |
# File 'lib/multi_git/config.rb', line 71 def schema @schema ||= DEFAULT_SCHEMA end |
#schema_for(section, subsection, key) ⇒ Object
75 76 77 |
# File 'lib/multi_git/config.rb', line 75 def schema_for( section, subsection, key ) schema[section][subsection][key] end |
#section(section, subsection = nil) ⇒ Section
117 118 119 |
# File 'lib/multi_git/config.rb', line 117 def section(section, subsection = nil) Section.new(self, section, subsection) end |
#split_key(qualified_key) ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/multi_git/config.rb', line 128 def split_key( qualified_key ) split = qualified_key.split(DOT) case(split.size) when 2 then [ split[0], nil, split[1] ] when 3 then split else raise ArgumentError, "Expected the qualified key to be formatted as 'section[.subsection].key' got #{qualified_key}" end end |
#to_h ⇒ Object
Expensive. Use only for debug.
148 149 150 |
# File 'lib/multi_git/config.rb', line 148 def to_h Hash[each.to_a] end |
#with_schema(sch) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Dups the object with a different schema
161 162 163 164 165 166 167 |
# File 'lib/multi_git/config.rb', line 161 def with_schema(sch) d = dup d.instance_eval do @schema = sch end return d end |