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

Classes: Schema, Section

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

Methods included from Utils::AbstractMethods

abstract

Instance Method Details

#[](section, subsection = nil, key) ⇒ Object #[](qualified_key) ⇒ Object

Overloads:

  • #[](section, subsection = nil, key) ⇒ Object

    Returns value.

    Parameters:

    • section (String)
    • subsection (String, nil) (defaults to: nil)
    • key (String)

    Returns:

    • value

  • #[](qualified_key) ⇒ Object

    Returns value.

    Parameters:

    • qualified_key (String)

      the fully-qualified key, seperated by dots

    Returns:

    • value



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

Returns:

  • (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

#eachObject

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

Yields:



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

#schemaObject



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

Parameters:

  • section (String)
  • subsection (String, nil) (defaults to: nil)

Returns:



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_hObject

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