Module: PoiseApplicationRuby::ServiceMixin::Provider

Includes:
PoiseApplication::ServiceMixin::Provider, AppMixin::Provider, PoiseRuby::BundlerMixin, PoiseRuby::RubyCommandMixin::Provider
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



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/poise_application_ruby/service_mixin.rb', line 46

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'] || ENV['PATH']
    cmd = if self_.new_resource.parent_bundle
      bundle_exec_command(val, path: path)
    else
      # Insert the gem executable directory at the front of the path.
      gem_environment = self_.send(:ruby_shell_out!, self_.new_resource.gem_binary, 'environment')
      matches = gem_environment.stdout.scan(/EXECUTABLE DIRECTORY: (.*)$/).first
      if matches
        Chef::Log.debug("[#{new_resource}] Prepending gem executable directory #{matches.first} to existing $PATH (#{path})")
        path = "#{matches.first}:#{path}"
      end
      "#{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