Class: Evertils::Controller::Config
- Defined in:
- lib/evertils/controllers/config.rb
Constant Summary
Constants inherited from Base
Base::OK, Base::QUIT, Base::QUIT_SOFT
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#can_exec?, #exec, #initialize, #post_exec, #sample
Constructor Details
This class inherits a constructor from Evertils::Controller::Base
Instance Method Details
#pre_exec ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/evertils/controllers/config.rb', line 9 def pre_exec conf = contents_of('~/.evertils/config.yml') @token = conf['gist_token'] unless conf['gist_token'].nil? @updating = Gist.gist_exists?(@token) # if the requested gist doesn't exist, ignore it and generate a new one @token = nil unless @updating Gist.login! unless has_auth_already? end |
#pull ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/evertils/controllers/config.rb', line 32 def pull # TODO: refactor this crap files = Gist.download(@token) FileUtils.mv(File.('~/.evertils'), File.('~/.evertils.old')) FileUtils.mkdir_p(File.('~/.evertils/templates/type')) dir = {} t_pfx = '~/.evertils/templates/type' c_pfx = '~/.evertils' root_files = ['config.yml'] files.each_pair do |_, file| dir["#{t_pfx}/#{file['filename']}"] = file['content'] unless file['filename'] == 'config.yml' dir["#{c_pfx}/#{file['filename']}"] = file['content'] if root_files.include?(file['filename']) end dir.each_pair do |path, contents| File.open(File.(path), 'w') { |f| f.write(contents) } end end |
#push ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/evertils/controllers/config.rb', line 19 def push = { public: false } .merge!(update: @token) unless @token.nil? resp = Gist.multi_gist(payload, ) @token = resp['id'] if resp.key?('id') Notify.success((resp['html_url'])) if store_token? end |