Class: PGit::Configuration
- Inherits:
-
Object
- Object
- PGit::Configuration
- Defined in:
- lib/pgit/configuration.rb
Instance Attribute Summary collapse
-
#config_path ⇒ Object
readonly
Returns the value of attribute config_path.
-
#yaml ⇒ Object
readonly
Returns the value of attribute yaml.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(config_path = '~/.pgit.rc.yml') ⇒ Configuration
constructor
A new instance of Configuration.
- #projects ⇒ Object
- #projects=(new_projects) ⇒ Object
- #save! ⇒ Object
- #to_hash ⇒ Object
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 = File.(config_path) @yaml = YAML::load_file() || {} @projs = @yaml.fetch("projects") { [] } rescue Exception => e if e..match(/No such file or directory/) f = File.new(, 'w'); f.close end end |
Instance Attribute Details
#config_path ⇒ Object (readonly)
Returns the value of attribute config_path.
28 29 30 |
# File 'lib/pgit/configuration.rb', line 28 def config_path @config_path end |
#yaml ⇒ Object (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_options ⇒ Object
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. { '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
#projects ⇒ Object
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(, 'w') YAML.dump(to_hash, file) file.close end |
#to_hash ⇒ Object
50 51 52 |
# File 'lib/pgit/configuration.rb', line 50 def to_hash { 'projects' => projects.map { |proj| proj.to_hash } } end |