Module: PoiseApplicationRuby::ServiceMixin::Provider

Includes:
PoiseApplication::ServiceMixin::Provider, AppMixin::Provider, PoiseRuby::BundlerMixin
Defined in:
lib/poise_application_ruby/service_mixin.rb

Overview

A helper mixin for Ruby service providers.

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#service_options(resource) ⇒ Object

Set up the service for running Ruby stuff.

Since:

  • 4.0.0



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/poise_application_ruby/service_mixin.rb', line 45

def service_options(resource)
  super
  # Closure scoping for #ruby_command below.
  self_ = self
  # Create a new singleton method that fills in Python for you.
  resource.define_singleton_method(:ruby_command) do |val|
    path = self_.new_resource.app_state_environment_ruby['PATH']
    cmd = if self_.new_resource.parent_bundle
      bundle_exec_command(val, path: path)
    else
      "#{self_.new_resource.ruby} #{PoiseLanguages::Utils.absolute_command(val, path: path)}"
    end
    resource.command(cmd)
  end
  # Include env vars as needed.
  resource.environment.update(new_resource.parent_ruby.ruby_environment) if new_resource.parent_ruby
  resource.environment['BUNDLE_GEMFILE'] = new_resource.parent_bundle.gemfile_path if new_resource.parent_bundle
end