class Kamaze::Project::Tools::Shell

Provide a REPL (based on “Pry“)

Attributes

banner[W]

@type [String]

console[RW]

Console used for outputs (“stderr“ and “stdout“)

@type [Kamaze::Project::Tools::Console]

provider[RW]

REPL provider

Allowing to replace “Pry“ by “IRB“, or any REPL class or instance responding to a `start“ method.

@type [Pry|Class|Object]

Public Instance Methods

banner() click to toggle source

Get banner

@return [String]

setup() click to toggle source
# File lib/kamaze/project/tools/shell.rb, line 44
def setup
  @console ||= Kamaze.project.tools.fetch(:console)
  @provider ||= require_any(:pry) ? Object.const_get(:Pry) : nil
  @banner ||= nil
end
start() click to toggle source

Start REPL session

# File lib/kamaze/project/tools/shell.rb, line 51
def start
  require_any(:interesting_methods)
  console.stdout.puts(banner)
  provider.start
end

Protected Instance Methods

require_any(gem_name, requirements = nil) click to toggle source

Require any gem based on “Gem::Specification“

@param [String|Symbol] gem_name @param [Array|nil] requirements @return [Boolean]

# File lib/kamaze/project/tools/shell.rb, line 74
def require_any(gem_name, requirements = nil)
  gem_name = gem_name.to_s
  requirements ||= [gem_name]

  return false unless Gem::Specification.find_all_by_name(gem_name).any?

  requirements.each { |req| require req.to_s }

  true
end