class Bashly::Library

Attributes

args[RW]
config[R]
path[R]
upgrade_string[R]

Public Class Methods

new(path, config, upgrade_string: nil) click to toggle source
# File lib/bashly/library.rb, line 6
def initialize(path, config, upgrade_string: nil)
  @path = path.to_s
  @config = config
  @upgrade_string = upgrade_string
end

Public Instance Methods

files() click to toggle source
# File lib/bashly/library.rb, line 12
def files
  if custom_handler
    custom_handler.files

  else
    config['files'].map do |file|
      {
        path:    file['target'] % target_file_args,
        content: file_contents("#{path}/#{file['source']}"),
      }
    end
  end
end
find_file(path) click to toggle source
# File lib/bashly/library.rb, line 34
def find_file(path)
  files.find { |f| f[:path] == path }
end
post_install_message() click to toggle source
# File lib/bashly/library.rb, line 26
def post_install_message
  if custom_handler
    custom_handler.post_install_message
  else
    config['post_install_message']
  end
end

Private Instance Methods

custom_handler() click to toggle source
# File lib/bashly/library.rb, line 40
def custom_handler
  return nil unless config['handler']

  @custom_handler ||= Module.const_get(config['handler']).new(*args)
end
file_contents(path) click to toggle source
# File lib/bashly/library.rb, line 46
def file_contents(path)
  File.read(path).sub('[@bashly-upgrade]', "[@bashly-upgrade #{upgrade_string}]")
end
target_file_args() click to toggle source
# File lib/bashly/library.rb, line 50
def target_file_args
  {
    user_source_dir: Settings.source_dir,
    user_target_dir: Settings.target_dir,
    user_lib_dir:    Settings.full_lib_dir,
    user_ext:        Settings.partials_extension,
  }
end