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.
9 10 11 12 13 14 15 |
# File 'lib/shove/app_directory.rb', line 9 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.
7 8 9 |
# File 'lib/shove/app_directory.rb', line 7 def app @app end |
#apps ⇒ Object
Returns the value of attribute apps.
7 8 9 |
# File 'lib/shove/app_directory.rb', line 7 def apps @apps end |
Instance Method Details
#default ⇒ Object
34 35 36 |
# File 'lib/shove/app_directory.rb', line 34 def default @app ? get_config(@app) : get_config end |
#default=(app_id) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/shove/app_directory.rb', line 27 def default= app_id unless app_id.nil? @app = app_id save end end |
#get_config(app_id = nil) ⇒ Object
38 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 |
# File 'lib/shove/app_directory.rb', line 38 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
23 24 25 |
# File 'lib/shove/app_directory.rb', line 23 def key app_id get_config(app_id)[:app_key] end |
#put(app_id, app_key) ⇒ Object
17 18 19 20 21 |
# File 'lib/shove/app_directory.rb', line 17 def put app_id, app_key @apps[app_id] = app_key @app = app_id if @app.nil? save end |