-
Notifications
You must be signed in to change notification settings - Fork 6
/
helpers.rb
37 lines (32 loc) · 1.1 KB
/
helpers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Thor::Base.shell = Thor::Shell::Color
require 'yaml'
def truthy?(statement)
val = ask(statement)
['y', 'yes', ''].include?(val)
end
def eval_template(name)
instance_eval(File.read(File.dirname(__FILE__) + "/#{name}.rb"))
end
def update_config!(attrs)
config = File.exists?('.graphiticfg.yml') ? YAML.load_file('.graphiticfg.yml') : {}
config.merge!(attrs)
File.open('.graphiticfg.yml', 'w') { |f| f.write(config.to_yaml) }
end
def api_namespace
@api_namespace ||= begin
ns = prompt \
header: "What is your API namespace?",
description: "This will be used as a route prefix, e.g. if you want the route '/books_api/v1/authors' your namespace would be '/books_api/v1'",
default: '/api/v1'
update_config!('namespace' => ns)
ns
end
end
def prompt(header: nil, description: nil, default: nil)
say(set_color("\n#{header}", :magenta, :bold)) if header
say("\n#{description}") if description
answer = ask(set_color("\n(default: #{default}):", :magenta, :bold))
answer = default if answer.blank? && default != 'nil'
say(set_color("\nGot it!\n", :white, :bold))
answer
end