module Katapult::GeneratorGoodies

This module holds methods that are shared between Katapult's element generators and the Rails generators it uses (e.g. BasicsGenerator)

Public Instance Methods

file_contains?(path, content) click to toggle source
# File lib/katapult/support/generator_goodies.rb, line 11
def file_contains?(path, content)
  file_content = File.read(path)
  file_content.include? content
end
yarn(*args) click to toggle source
# File lib/katapult/support/generator_goodies.rb, line 6
def yarn(*args)
  command =  'bin/yarn --silent --non-interactive ' + args.join(' ')
  run command
end

Private Instance Methods

app_name(kind = nil) click to toggle source
# File lib/katapult/support/generator_goodies.rb, line 18
def app_name(kind = nil)
  machine_name = File.basename(Dir.pwd)
  human_name = machine_name.tr('_', ' ').gsub(/\w+/, &:capitalize)

  case kind.to_s
    when ''       then machine_name
    when 'human'  then human_name
    else raise ArgumentError, "Unknown formatting: #{kind.inspect}"
  end
end
rake(command, config = {}) click to toggle source

Override Thor method

# File lib/katapult/support/generator_goodies.rb, line 39
def rake(command, config = {})
  command.prepend 'bundle exec rake '
  run command, config
end
run(command, config={}) click to toggle source

Override Thor method

Calls superclass method
# File lib/katapult/support/generator_goodies.rb, line 30
def run(command, config={})
  config[:capture] ||= false # false = return boolean instead of cmd output

  Bundler.with_clean_env do
    super(command, config) or exit(1)
  end
end