class CreateRubyApp::Actions::GenerateFiles

Constants

TEMPLATES_DIR
TRIM_MODE

Attributes

app[R]

Public Class Methods

call(app) click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 13
def self.call(app)
  new(app).call
end
new(app) click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 9
def initialize(app)
  @app = app
end

Public Instance Methods

call() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 17
def call
  generate_files
end
gemfile() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 40
def gemfile
  generate_file(file: "Gemfile.erb", locals: { gems: app.gems.sort })
end
lib_file() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 25
def lib_file
  generate_file(file: "lib_file.erb", locals: { app: app.classify_name })
end
ruby_version_file() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 33
def ruby_version_file
  generate_file(
    file: "ruby-version.erb",
    locals: { version: app.version }
  )
end
script_file() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 21
def script_file
  generate_file(file: "script_file.erb", locals: {})
end
spec_helper_file() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 29
def spec_helper_file
  generate_file(file: "spec_helper.erb", locals: { app: app.name })
end

Private Instance Methods

create_file(path:, content:) click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 52
def create_file(path:, content:)
  File.write("#{app.name}/#{path}", content)
end
files() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 69
def files
  {
    "bin/#{app.name}" => script_file,
    "lib/#{app.name}.rb" => lib_file,
    "spec/spec_helper.rb" => spec_helper_file,
    ".ruby-version" => ruby_version_file,
    "Gemfile" => gemfile
  }
end
generate_file(file:, locals: []) click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 56
def generate_file(file:, locals: [])
  ERB
    .new(read_file(file), trim_mode: TRIM_MODE)
    .result_with_hash(locals: locals)
end
generate_files() click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 48
def generate_files
  files.each {|path, content| create_file(path: path, content: content) }
end
read_file(file) click to toggle source
# File lib/create_ruby_app/actions/generate_files.rb, line 62
def read_file(file)
  Pathname.new(__FILE__)
    .dirname
    .join("#{TEMPLATES_DIR}/#{file}")
    .read
end