class Rubysmith::Builder

:reek: TooManyMethods Provides common functionality necessary for all builders.

Constants

HELPERS
LOGGER

Public Class Methods

call(...) click to toggle source
# File lib/rubysmith/builder.rb, line 22
def self.call(...) = new(...)

def initialize configuration, helpers: HELPERS
  @configuration = configuration
  @helpers = helpers
end

def append content
  logger.info "Appending: #{relative_build_path}"
  build_path.rewrite { |body| body + content }
  self
end

def delete
  logger.info "Deleting: #{relative_build_path}"
  build_path.delete
  self
end

def insert_before pattern, content
  logger.info "Inserting content before pattern in: #{relative_build_path}"
  build_path.write inserter.new(build_path.readlines, :before).call(content, pattern).join
  self
end

def insert_after pattern, content
  logger.info "Inserting content after pattern in: #{relative_build_path}"
  build_path.write inserter.new(build_path.readlines, :after).call(content, pattern).join
  self
end

def permit mode
  logger.info "Changing permissions for: #{relative_build_path}"
  build_path.chmod mode
  self
end

def prepend content
  logger.info "Prepending content to: #{relative_build_path}"
  build_path.rewrite { |body| content + body }
  self
end

def rename name
  logger.info "Renaming: #{build_path.basename} to #{name}"
  build_path.rename build_path.parent.join(name)
  self
end

def render
  logger.info "Rendering: #{relative_build_path}"

  pathway.start_path.read.then do |content|
    build_path.make_ancestors.write renderer.call(content)
  end

  self
end

def replace pattern, content
  logger.info "Replacing content for patterns in: #{relative_build_path}"
  build_path.rewrite { |body| body.gsub pattern, content }
  self
end

def run *command
  logger.info "Running: #{command}"
  execute(*command)
  self
rescue StandardError => error
  logger.error error and self
end

def touch
  logger.info "Touching: #{relative_build_path}"
  build_path.make_ancestors.touch
  self
end

private

attr_reader :configuration, :helpers

def execute *command
  kernel.capture2e(*command).then do |result, status|
    logger.error result unless status.success?
  end
end

def inserter = helpers.fetch(__method__)

def renderer = helpers.fetch(__method__).new(configuration)

def kernel = helpers.fetch(__method__)

def logger = helpers.fetch(__method__)

def relative_build_path = build_path.relative_path_from(configuration.build_root)

def build_path
  pathway.end_path
         .gsub("%project_name%", configuration.project_name)
         .sub("%project_path%", configuration.project_path)
         .sub ".erb", ""
end

def pathway 
new(configuration, helpers: HELPERS) click to toggle source
# File lib/rubysmith/builder.rb, line 24
def initialize configuration, helpers: HELPERS
  @configuration = configuration
  @helpers = helpers
end

Public Instance Methods

append(content) click to toggle source
# File lib/rubysmith/builder.rb, line 29
def append content
  logger.info "Appending: #{relative_build_path}"
  build_path.rewrite { |body| body + content }
  self
end
build_path() click to toggle source
# File lib/rubysmith/builder.rb, line 121
def build_path
  pathway.end_path
         .gsub("%project_name%", configuration.project_name)
         .sub("%project_path%", configuration.project_path)
         .sub ".erb", ""
end
delete() click to toggle source
# File lib/rubysmith/builder.rb, line 35
def delete
  logger.info "Deleting: #{relative_build_path}"
  build_path.delete
  self
end
execute(*command) click to toggle source
# File lib/rubysmith/builder.rb, line 105
def execute *command
  kernel.capture2e(*command).then do |result, status|
    logger.error result unless status.success?
  end
end
insert_after(pattern, content) click to toggle source
# File lib/rubysmith/builder.rb, line 47
def insert_after pattern, content
  logger.info "Inserting content after pattern in: #{relative_build_path}"
  build_path.write inserter.new(build_path.readlines, :after).call(content, pattern).join
  self
end
insert_before(pattern, content) click to toggle source
# File lib/rubysmith/builder.rb, line 41
def insert_before pattern, content
  logger.info "Inserting content before pattern in: #{relative_build_path}"
  build_path.write inserter.new(build_path.readlines, :before).call(content, pattern).join
  self
end
inserter(= helpers.fetch(__method__)) click to toggle source
# File lib/rubysmith/builder.rb, line 111
def inserter = helpers.fetch(__method__)

def renderer = helpers.fetch(__method__).new(configuration)

def kernel = helpers.fetch(__method__)

def logger = helpers.fetch(__method__)

def relative_build_path = build_path.relative_path_from(configuration.build_root)

def build_path
  pathway.end_path
         .gsub("%project_name%", configuration.project_name)
         .sub("%project_path%", configuration.project_path)
         .sub ".erb", ""
end

def pathway = 
kernel(= helpers.fetch(__method__)) click to toggle source
# File lib/rubysmith/builder.rb, line 115
def kernel = helpers.fetch(__method__)

def logger = helpers.fetch(__method__)

def relative_build_path = build_path.relative_path_from(configuration.build_root)

def build_path
  pathway.end_path
         .gsub("%project_name%", configuration.project_name)
         .sub("%project_path%", configuration.project_path)
         .sub ".erb", ""
end

def pathway = configuration.to_pathway
logger(= helpers.fetch(__method__)) click to toggle source
# File lib/rubysmith/builder.rb, line 117
  def logger = helpers.fetch(__method__)

  def relative_build_path = build_path.relative_path_from(configuration.build_root)

  def build_path
    pathway.end_path
           .gsub("%project_name%", configuration.project_name)
           .sub("%project_path%", configuration.project_path)
           .sub ".erb", ""
  end

  def pathway = configuration.to_pathway
end
pathway(= configuration.to_pathway) click to toggle source
# File lib/rubysmith/builder.rb, line 128
  def pathway = configuration.to_pathway
end
permit(mode) click to toggle source
# File lib/rubysmith/builder.rb, line 53
def permit mode
  logger.info "Changing permissions for: #{relative_build_path}"
  build_path.chmod mode
  self
end
prepend(content) click to toggle source
# File lib/rubysmith/builder.rb, line 59
def prepend content
  logger.info "Prepending content to: #{relative_build_path}"
  build_path.rewrite { |body| content + body }
  self
end
relative_build_path(= build_path.relative_path_from(configuration.build_root)) click to toggle source
# File lib/rubysmith/builder.rb, line 119
    def relative_build_path = build_path.relative_path_from(configuration.build_root)

    def build_path
      pathway.end_path
             .gsub("%project_name%", configuration.project_name)
             .sub("%project_path%", configuration.project_path)
             .sub ".erb", ""
    end

    def pathway = configuration.to_pathway
  end
end
rename(name) click to toggle source
# File lib/rubysmith/builder.rb, line 65
def rename name
  logger.info "Renaming: #{build_path.basename} to #{name}"
  build_path.rename build_path.parent.join(name)
  self
end
render() click to toggle source
# File lib/rubysmith/builder.rb, line 71
def render
  logger.info "Rendering: #{relative_build_path}"

  pathway.start_path.read.then do |content|
    build_path.make_ancestors.write renderer.call(content)
  end

  self
end
renderer(= helpers.fetch(__method__).new(configuration)) click to toggle source
# File lib/rubysmith/builder.rb, line 113
def renderer = helpers.fetch(__method__).new(configuration)

def kernel = helpers.fetch(__method__)

def logger = helpers.fetch(__method__)

def relative_build_path = build_path.relative_path_from(configuration.build_root)

def build_path
  pathway.end_path
         .gsub("%project_name%", configuration.project_name)
         .sub("%project_path%", configuration.project_path)
         .sub ".erb", ""
end

def pathway = configuration.
replace(pattern, content) click to toggle source
# File lib/rubysmith/builder.rb, line 81
def replace pattern, content
  logger.info "Replacing content for patterns in: #{relative_build_path}"
  build_path.rewrite { |body| body.gsub pattern, content }
  self
end
run(*command) click to toggle source
# File lib/rubysmith/builder.rb, line 87
def run *command
  logger.info "Running: #{command}"
  execute(*command)
  self
rescue StandardError => error
  logger.error error and self
end
touch() click to toggle source
# File lib/rubysmith/builder.rb, line 95
def touch
  logger.info "Touching: #{relative_build_path}"
  build_path.make_ancestors.touch
  self
end