Module: Mode::Commands::Helpers

Included in:
AnalyzeField, AnalyzeSchema, Connect, Import
Defined in:
lib/mode/commands/helpers.rb

Instance Method Summary collapse

Instance Method Details

#config_dirObject



9
10
11
# File 'lib/mode/commands/helpers.rb', line 9

def config_dir
  Mode::Config.default_dir
end

#config_exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mode/commands/helpers.rb', line 17

def config_exists?
  Mode::Config.exists?(config_dir)
end

#config_pathObject



13
14
15
# File 'lib/mode/commands/helpers.rb', line 13

def config_path
  Mode::Config.full_path(config_dir)
end

#configure_api_requests!Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mode/commands/helpers.rb', line 50

def configure_api_requests!
  config = Mode::Config.new(config_dir)

  Mode::API::Request.configure(
    config.environment, {            
      :credentials => {
        :username => config.username,
        :access_token => config.access_token
      }
    }
  )
end

#connect_config_exists?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mode/commands/helpers.rb', line 21

def connect_config_exists?
  Mode::Connector::Config.exists?(config_dir)
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_connect_config!Object



31
32
33
34
35
# File 'lib/mode/commands/helpers.rb', line 31

def require_connect_config!
  unless connect_config_exists?
    raise "No connect configuration file found."
  end
end

#require_credentials!Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/mode/commands/helpers.rb', line 37

def require_credentials!
  message = "Couldn't find Mode login credentials. Please use `mode login` before continuing."

  if config_exists?
    config = Mode::Config.new(config_dir)
    unless config.username && config.access_token
      raise message
    end
  else
    raise message
  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