Sha256: 0ad16ac7a783e32d792d6d17c4bbb219d1a0f01670d0d620ce0a1e25eaf4cfd0
Contents?: true
Size: 1.3 KB
Versions: 11
Compression:
Stored size: 1.3 KB
Contents
module Graphiti module GeneratorMixin 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 def api_namespace @api_namespace ||= begin ns = graphiti_config['namespace'] if ns.blank? 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'", default: 'api' update_config!('namespace' => ns) end ns end end def actions @options['actions'] || %w(index show create update destroy) end def actions?(*methods) methods.any? { |m| actions.include?(m) } end def graphiti_config File.exists?('.graphiticfg.yml') ? YAML.load_file('.graphiticfg.yml') : {} end def update_config!(attrs) config = graphiti_config.merge(attrs) File.open('.graphiticfg.yml', 'w') { |f| f.write(config.to_yaml) } end end end
Version data entries
11 entries across 11 versions & 1 rubygems