Class: PGit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/pgit/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = '~/.pgit.rc.yml') ⇒ Configuration

Returns a new instance of Configuration.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pgit/configuration.rb', line 30

def initialize(config_path = '~/.pgit.rc.yml')
  @config_path = config_path
  @expanded_path = File.expand_path(config_path)
  @yaml = YAML::load_file(@expanded_path) || {}
  @projs = @yaml.fetch("projects") { [] }
rescue Exception => e
  if e.message.match(/No such file or directory/)
    f = File.new(@expanded_path, 'w');
    f.close
  end
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



28
29
30
# File 'lib/pgit/configuration.rb', line 28

def config_path
  @config_path
end

#yamlObject (readonly)

Returns the value of attribute yaml.



28
29
30
# File 'lib/pgit/configuration.rb', line 28

def yaml
  @yaml
end

Class Method Details

.default_optionsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pgit/configuration.rb', line 11

def self.default_options
  {
    'projects' => [
      {
        'api_token' => 'somepivotalatoken124',
        'id' => '12345',
        "path" => "~/some/path/to/a/pivotal-git/project"
      },
      {
        'api_token' => 'somepivotalatoken124',
        'id' => '23429070',
        "path" => "~/some/other/pivotal-git/project"
      }
    ]
  }
end

Instance Method Details

#projectsObject



46
47
48
# File 'lib/pgit/configuration.rb', line 46

def projects
  @projs.map {|proj| PGit::Project.new(self, proj) }
end

#projects=(new_projects) ⇒ Object



42
43
44
# File 'lib/pgit/configuration.rb', line 42

def projects=(new_projects)
  @projs = new_projects.map {|p| p.to_hash}
end

#save!Object



54
55
56
57
58
# File 'lib/pgit/configuration.rb', line 54

def save!
  file = File.new(@expanded_path, 'w')
  YAML.dump(to_hash, file)
  file.close
end

#to_hashObject



50
51
52
# File 'lib/pgit/configuration.rb', line 50

def to_hash
  { 'projects' => projects.map { |proj| proj.to_hash } }
end