Module: Mode::Commands::Helpers
- Included in:
- AnalyzeField, AnalyzeSchema, Connect, Import
- Defined in:
- lib/mode/commands/helpers.rb
Instance Method Summary collapse
- #config ⇒ Object
- #config_dir ⇒ Object
- #config_exists? ⇒ Boolean
- #configure_api_requests! ⇒ Object
- #drivers_dir ⇒ Object
- #load_drivers! ⇒ Object
- #require_config! ⇒ Object
- #require_credentials! ⇒ Object
- #timer_block(&block) ⇒ Object
- #validate_config! ⇒ Object
Instance Method Details
#config ⇒ Object
21 22 23 |
# File 'lib/mode/commands/helpers.rb', line 21 def config @config ||= Mode::Config.new(config_dir) end |
#config_dir ⇒ Object
9 10 11 |
# File 'lib/mode/commands/helpers.rb', line 9 def config_dir Mode::Config.default_dir end |
#config_exists? ⇒ Boolean
17 18 19 |
# File 'lib/mode/commands/helpers.rb', line 17 def config_exists? Mode::Config.exists?(config_dir) end |
#configure_api_requests! ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mode/commands/helpers.rb', line 57 def configure_api_requests! Mode::API::Request.configure( config.environment, { 'credentials' => { 'username' => config.username, 'password' => config.access_token_password }, 'access_token' => config.access_token } ) end |
#drivers_dir ⇒ Object
13 14 15 |
# File 'lib/mode/commands/helpers.rb', line 13 def drivers_dir File.join(config_dir, 'drivers') end |
#load_drivers! ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/mode/commands/helpers.rb', line 49 def load_drivers! if RUBY_PLATFORM == 'java' Dir[File.join(drivers_dir, '*.jar')].each do |driver| load driver end end end |
#require_config! ⇒ Object
25 26 27 28 29 |
# File 'lib/mode/commands/helpers.rb', line 25 def require_config! unless config_exists? raise "Couldn't find Mode configuration. Please use `mode login` before continuing." end end |
#require_credentials! ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mode/commands/helpers.rb', line 31 def require_credentials! = "Couldn't find Mode login credentials. Please use `mode login` before continuing." if config_exists? unless config.username && config.access_token raise end else raise end end |
#timer_block(&block) ⇒ Object
4 5 6 7 |
# File 'lib/mode/commands/helpers.rb', line 4 def timer_block(&block) started_at = Time.now return yield, (Time.now.to_f - started_at.to_f) end |
#validate_config! ⇒ Object
43 44 45 46 47 |
# File 'lib/mode/commands/helpers.rb', line 43 def validate_config! require_config! require_credentials! configure_api_requests! end |