Module: Viaduct::Toolkit

Defined in:
lib/viaduct/toolkit.rb,
lib/viaduct/toolkit/helpers.rb,
lib/viaduct/toolkit/version.rb

Defined Under Namespace

Modules: Helpers Classes: Error

Constant Summary collapse

VERSION =
'1.0.8'

Class Method Summary collapse

Class Method Details

.add_commandsObject



40
41
42
43
44
# File 'lib/viaduct/toolkit.rb', line 40

def add_commands
  Dir[File.expand_path(File.join('..', 'toolkit', 'commands', '*.rb'), __FILE__)].each do |file|
    require file
  end
end

.apiObject



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/viaduct/toolkit.rb', line 46

def api
  @api ||= begin
    if $dev
      Viaduct::API.host = 'localhost'
      Viaduct::API.port = 5000
      Viaduct::API.ssl = false
      Viaduct::API.application_token = 'example'
    end
    Viaduct::API::Client.new(env_config['token'], env_config['secret'])
  end
end

.binaryObject



22
23
24
# File 'lib/viaduct/toolkit.rb', line 22

def binary
  File.expand_path(File.join('..', '..', '..', 'bin', 'viaduct'), __FILE__)
end

.cliObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/viaduct/toolkit.rb', line 26

def cli
  @cli ||= begin
    c = Commander::Runner.instance
    c.program :name, "Viaduct Toolkit"
    c.program :version, Viaduct::Toolkit::VERSION
    c.program :description, "A CLI toolkit for Viaduct developers"
    c.global_option('-c', '--config FILE', 'The config file to store local credentials within') { |file| $config_file_path = file }
    c.global_option('--app NAME', 'The application to work on') { |name| $app = name }
    c.global_option('--dev', 'Connect to local development installation of Viaduct (dev only)') { $dev = true }
    c.default_command :help
    c
  end
end

.configObject



70
71
72
73
74
75
76
77
78
# File 'lib/viaduct/toolkit.rb', line 70

def config
  @config ||= begin
    if File.exist?(config_file_path)
      YAML.load_file(config_file_path) || {}
    else
      {}
    end
  end
end

.config_file_pathObject



62
63
64
# File 'lib/viaduct/toolkit.rb', line 62

def config_file_path
  $config_file_path || File.join(ENV['HOME'], '.viaduct')
end

.env_configObject



66
67
68
# File 'lib/viaduct/toolkit.rb', line 66

def env_config
  config[$dev ? 'dev' : 'live'] ||= {}
end

.reset_apiObject



58
59
60
# File 'lib/viaduct/toolkit.rb', line 58

def reset_api
  @api = nil
end

.save_configObject



80
81
82
83
84
# File 'lib/viaduct/toolkit.rb', line 80

def save_config
  File.open(config_file_path, 'w') do |f|
    f.write self.config.to_yaml
  end
end