Class: Shove::AppDirectory
- Inherits:
-
Object
- Object
- Shove::AppDirectory
- Defined in:
- lib/shove/app_directory.rb
Overview
Used for storing and accessing shove credentials from the command line utility
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#apps ⇒ Object
Returns the value of attribute apps.
Instance Method Summary collapse
- #default ⇒ Object
- #default=(app_id) ⇒ Object
- #get_config(app_id = nil) ⇒ Object
-
#initialize(io = STDIN, path = File.expand_path("~/.shove.yml")) ⇒ AppDirectory
constructor
A new instance of AppDirectory.
- #key(app_id) ⇒ Object
- #put(app_id, app_key) ⇒ Object
Constructor Details
#initialize(io = STDIN, path = File.expand_path("~/.shove.yml")) ⇒ AppDirectory
Returns a new instance of AppDirectory.
10 11 12 13 14 15 16 |
# File 'lib/shove/app_directory.rb', line 10 def initialize io=STDIN, path=File.("~/.shove.yml") @io = io @path = path @app = nil @apps = {} load! end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
8 9 10 |
# File 'lib/shove/app_directory.rb', line 8 def app @app end |
#apps ⇒ Object
Returns the value of attribute apps.
8 9 10 |
# File 'lib/shove/app_directory.rb', line 8 def apps @apps end |
Instance Method Details
#default ⇒ Object
35 36 37 |
# File 'lib/shove/app_directory.rb', line 35 def default @app ? get_config(@app) : get_config end |
#default=(app_id) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/shove/app_directory.rb', line 28 def default= app_id unless app_id.nil? @app = app_id save end end |
#get_config(app_id = nil) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shove/app_directory.rb', line 39 def get_config app_id=nil config = ENV["SHOVE_ENV"] == "development" ? { :api_url => "http://api.shove.dev:8080", :ws_url => "ws://shove.dev:9000" } : {} if !@app.nil? && app_id.nil? config[:app_id] = @app config[:app_key] = key(@app) elsif app_id.nil? || !@apps.key?(app_id) puts "We need some information to continue" if app_id.nil? config[:app_id] = getinput "Enter App Id" else config[:app_id] = app_id end loop do config[:app_key] = getinput "Enter App Key" Shove.configure config if Shove.valid? puts "App Settings accepted. Moving on..." break else puts "App Settings invalid, please try again" end end put config[:app_id], config[:app_key] else config[:app_id] = app_id config[:app_key] = @apps[app_id] end config end |
#key(app_id) ⇒ Object
24 25 26 |
# File 'lib/shove/app_directory.rb', line 24 def key app_id get_config(app_id)[:app_key] end |
#put(app_id, app_key) ⇒ Object
18 19 20 21 22 |
# File 'lib/shove/app_directory.rb', line 18 def put app_id, app_key @apps[app_id] = app_key @app = app_id if @app.nil? save end |