Method: Pit.set
- Defined in:
- lib/pit.rb
.set(name, opts = {}) ⇒ Object
Set name setting to current profile. If not opts specified, this opens $EDITOR with current profile setting. If ‘data` specified, this just sets it to current profile. If `config` specified, this opens $EDITOR with merged hash with specified hash and current profile.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pit.rb', line 17 def self.set(name, opts={}) profile = self.load if opts.key?(:data) result = opts[:data] else if ENV["EDITOR"].nil? || !$stdout.tty? return {} end c = (opts[:config] || self.get(name)).to_yaml t = Tempfile.new("pit") t << c t.close system(ENV["EDITOR"], t.path) t.open result = t.read if result == c warn "No Changes" return profile[name] end result = YAML.load(result) end profile[name] = result @@profile.open("w") {|f| YAML.dump(profile, f) } result end |