Module: Cany

Defined in:
lib/cany.rb,
lib/cany/dpkg.rb,
lib/cany/errors.rb,
lib/cany/recipe.rb,
lib/cany/version.rb,
lib/cany/dependency.rb,
lib/cany/dpkg/builder.rb,
lib/cany/dpkg/creator.rb,
lib/cany/recipes/rails.rb,
lib/cany/specification.rb,
lib/cany/recipes/bundler.rb,
lib/cany/specification/dsl.rb

Defined Under Namespace

Modules: Dpkg, Mixins, Recipes, VERSION Classes: CommandExecutionFailed, Dependency, Error, MissingSpecification, MultipleSpecifications, NoSystemRecipe, Recipe, Specification, UnknownHook, UnknownOption, UnknownRecipe, UnloadedRecipe, UnsupportedVersion

Class Method Summary collapse

Class Method Details

.create_loggerObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cany.rb', line 38

def self.create_logger
  logger = Logger.new(STDOUT)
  logger.level = Logger::INFO
  org_formatter = Logger::Formatter.new
  logger.formatter = proc do |severity, datetime, progname, msg|
    if severity == "INFO"
      "   #{msg}\n"
    else
      org_formatter.call severity, datetime, progname, msg
    end
  end
  logger
end

.hash_with_array_as_defaultObject

This methods creates a hash that returns an array as default value and also stores it directly inside the hash, so that the return value can be changed without additional actions.

Examples:

hash = hash_with_array_as_default
hash[:hans] << 'otto'
hash[:hash] == ['otto']


24
25
26
27
28
29
30
# File 'lib/cany.rb', line 24

def self.hash_with_array_as_default
  {}.tap do |hash|
    hash.default_proc = Proc.new do |_, key|
      hash[key] = []
    end
  end
end

.loggerLogger

Returns:

  • (Logger)


34
35
36
# File 'lib/cany.rb', line 34

def self.logger
  @logger ||= create_logger
end

.setup(directory = '.') ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
# File 'lib/cany.rb', line 7

def self.setup(directory='.')
  specs = Dir[directory + '/*.' + Specification::EXT]
  raise MissingSpecification.new(directory) if specs.size == 0
  raise MultipleSpecifications.new(directory) if specs.size > 1
  file = specs.first
  spec = eval File::read(file), binding, file
  spec.base_dir = directory
  spec
end