Class: Openbox::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/openbox/runtime.rb

Overview

Detection application runtime

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(dependencies = []) ⇒ Runtime

Returns a new instance of Runtime.

Parameters:

  • dependencies (Array<Bundler::Dependency>) (defaults to: [])

Since:

  • 0.1.0



13
14
15
# File 'lib/openbox/runtime.rb', line 13

def initialize(dependencies = [])
  @dependencies = dependencies
end

Instance Method Details

#groupsArray<Symbol>

Groups to detect

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0



50
51
52
# File 'lib/openbox/runtime.rb', line 50

def groups
  @groups ||= [:default, ENV['RAILS_ENV'], ENV['RACK_ENV']].compact.map(&:to_sym)
end

#has?(*names) ⇒ TrueClass|FalseClass

Check for rubygmes exists

Returns:

  • (TrueClass|FalseClass)

Since:

  • 0.1.0



41
42
43
# File 'lib/openbox/runtime.rb', line 41

def has?(*names)
  select(*names).any?
end

#rails?TrueClass|FalseClass

Check for Rails environment

Returns:

  • (TrueClass|FalseClass)

Since:

  • 0.1.0



22
23
24
# File 'lib/openbox/runtime.rb', line 22

def rails?
  has?('rails')
end

#select(*names) ⇒ Array<Bundler::Dependency>

Select desired rubygems

Returns:

  • (Array<Bundler::Dependency>)

Since:

  • 0.1.0



31
32
33
34
# File 'lib/openbox/runtime.rb', line 31

def select(*names)
  @dependencies
    .select { |dep| names.include?(dep.name) && (dep.groups & groups).any? }
end