Class: Shortorder::Command::CustomService
- Inherits:
-
Shortorder::Command
- Object
- Bogo::Cli::Command
- Shortorder::Command
- Shortorder::Command::CustomService
- Defined in:
- lib/shortorder/command/custom_service.rb
Instance Attribute Summary collapse
-
#callback_class ⇒ Object
readonly
Returns the value of attribute callback_class.
-
#callback_name ⇒ Object
readonly
Returns the value of attribute callback_name.
-
#full_class ⇒ Object
readonly
Returns the value of attribute full_class.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#root_class ⇒ Object
readonly
Returns the value of attribute root_class.
-
#root_name ⇒ Object
readonly
Returns the value of attribute root_name.
-
#service_path ⇒ Object
readonly
Returns the value of attribute service_path.
-
#task_class ⇒ Object
readonly
Returns the value of attribute task_class.
-
#task_name ⇒ Object
readonly
Returns the value of attribute task_name.
Instance Method Summary collapse
-
#execute! ⇒ Object
Generate custom service scaffold.
Instance Attribute Details
#callback_class ⇒ Object (readonly)
Returns the value of attribute callback_class.
11 12 13 |
# File 'lib/shortorder/command/custom_service.rb', line 11 def callback_class @callback_class end |
#callback_name ⇒ Object (readonly)
Returns the value of attribute callback_name.
11 12 13 |
# File 'lib/shortorder/command/custom_service.rb', line 11 def callback_name @callback_name end |
#full_class ⇒ Object (readonly)
Returns the value of attribute full_class.
12 13 14 |
# File 'lib/shortorder/command/custom_service.rb', line 12 def full_class @full_class end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
12 13 14 |
# File 'lib/shortorder/command/custom_service.rb', line 12 def full_name @full_name end |
#root_class ⇒ Object (readonly)
Returns the value of attribute root_class.
9 10 11 |
# File 'lib/shortorder/command/custom_service.rb', line 9 def root_class @root_class end |
#root_name ⇒ Object (readonly)
Returns the value of attribute root_name.
9 10 11 |
# File 'lib/shortorder/command/custom_service.rb', line 9 def root_name @root_name end |
#service_path ⇒ Object (readonly)
Returns the value of attribute service_path.
13 14 15 |
# File 'lib/shortorder/command/custom_service.rb', line 13 def service_path @service_path end |
#task_class ⇒ Object (readonly)
Returns the value of attribute task_class.
10 11 12 |
# File 'lib/shortorder/command/custom_service.rb', line 10 def task_class @task_class end |
#task_name ⇒ Object (readonly)
Returns the value of attribute task_name.
10 11 12 |
# File 'lib/shortorder/command/custom_service.rb', line 10 def task_name @task_name end |
Instance Method Details
#execute! ⇒ Object
Generate custom service scaffold.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shortorder/command/custom_service.rb', line 16 def execute! unless(arguments.size == 1) raise ArgumentError.new('Single argument name of service is required!') end @root_name = Bogo::Utility.snake(config[:root].tr('-.', '_')) @root_class = Bogo::Utility.camel(root_name) @task_name = Bogo::Utility.snake(arguments.first.tr('-.', '_')) @task_class = Bogo::Utility.camel(task_name) @callback_name = Bogo::Utility.snake(config[:callback].tr('-.', '_')) @callback_class = Bogo::Utility.camel(callback_name) @full_name = "#{root_name}-#{task_name}".tr('_', '-') @full_class = "#{root_class}::#{task_class}" @service_path = File.join(config[:service_path], full_name) run_action 'Validating service directory' do if(File.directory?(service_path)) ui.puts ui.color('path exists', :yellow) ui.confirm 'Overwrite existing contents of service path' ui.info 'Validating service directory... ', :nonewline end FileUtils.mkdir_p(service_path) nil end run_action 'Generating service directory structure' do FileUtils.mkdir_p(File.join(service_path, 'lib', full_name)) nil end run_action 'Writing service scaffolding files' do write_gemspec! write_version! write_loader! write_callback! write_readme! nil end run_action 'Writing Gemfile for local bundle' do write_gemfile! nil end run_action 'Writing service configuration file' do write_config! nil end ui.info "Created new custom service `#{ui.color(task_name, :green, :bold)}` at #{service_path}" ui.puts " To get started, change directory to: #{ui.color(service_path, :bold)}" ui.puts " Install the bundle: #{ui.color('bundle install', :bold)}" ui.puts " Start the service: #{ui.color('bundle exec jackal -c config.json', :bold)}" end |