Class: Vendorificator::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vendorificator/config.rb,
lib/vendorificator/vendor/git.rb,
lib/vendorificator/vendor/tool.rb,
lib/vendorificator/vendor/archive.rb,
lib/vendorificator/vendor/download.rb,
lib/vendorificator/vendor/chef_cookbook.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Config

Returns a new instance of Config.



36
37
38
39
40
# File 'lib/vendorificator/config.rb', line 36

def initialize(params = {})
  @fake_mode = check_fake_mode
  @configuration = self.class.defaults.merge(params)
  @metadata = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *args, &block) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/vendorificator/config.rb', line 76

def method_missing(method_symbol, *args, &block)
  if modules.keys.include? method_symbol
    modules[method_symbol].new(environment, args.delete_at(0).to_s, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



5
6
7
# File 'lib/vendorificator/config.rb', line 5

def environment
  @environment
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/vendorificator/config.rb', line 6

def 
  @metadata
end

#overlay_instanceObject (readonly)

Returns the value of attribute overlay_instance.



6
7
8
# File 'lib/vendorificator/config.rb', line 6

def overlay_instance
  @overlay_instance
end

Class Method Details

.defaultsObject



11
12
13
# File 'lib/vendorificator/config.rb', line 11

def self.defaults
  @defaults
end

.modulesObject



15
16
17
# File 'lib/vendorificator/config.rb', line 15

def self.modules
  @modules
end

.option(name, default = nil, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/vendorificator/config.rb', line 19

def self.option(name, default = nil, &block)
  define_method name do |*args|
    if args.size == 0
      @configuration[name.to_sym]
    elsif args.size == 1
      @configuration[name.to_sym] = args.first
    else
      raise 'Unsupported number of arguments (expected 0 or 1).'
    end
  end
  @defaults[name.to_sym] = default if default
end

.register_module(name, klass) ⇒ Object



32
33
34
# File 'lib/vendorificator/config.rb', line 32

def self.register_module(name, klass)
  @modules[name.to_sym] = klass
end

Instance Method Details

#[](key) ⇒ Object



60
61
62
# File 'lib/vendorificator/config.rb', line 60

def [](key)
  @configuration[key]
end

#[]=(key, value) ⇒ Object



64
65
66
# File 'lib/vendorificator/config.rb', line 64

def []=(key, value)
  @configuration[key] = value
end

#annotate(key, value) ⇒ Object



72
73
74
# File 'lib/vendorificator/config.rb', line 72

def annotate key, value
  @metadata.merge!({key => value})
end

#chef_berkshelf(args = {}, &block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/vendorificator/vendor/tool.rb', line 72

def chef_berkshelf(args={}, &block)
  args[:path] ||= 'cookbooks'
  args[:specs] ||= []
  args[:specs] |= [ 'Berksfile', 'Berksfile.lock' ]
  args[:command] = "berks install --path vendor/#{args[:path]}"
  tool 'cookbooks', args, &block
end

#configure(&block) ⇒ Object



56
57
58
# File 'lib/vendorificator/config.rb', line 56

def configure(&block)
  block.call @configuration
end

#fake_mode?Boolean

Public: Returns information whether we work in the fake mode.

Returns true/false.

Returns:

  • (Boolean)


97
98
99
# File 'lib/vendorificator/config.rb', line 97

def fake_mode?
  @fake_mode
end

#modulesObject



68
69
70
# File 'lib/vendorificator/config.rb', line 68

def modules
  self.class.modules
end

#overlay(name, options = {}, &block) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/vendorificator/config.rb', line 84

def overlay(name, options = {}, &block)
  @overlay_instance = Segment::Overlay.new(
    environment: environment, overlay_opts: options.merge(name: name)
  )
  environment.segments << @overlay_instance
  yield
ensure
  @overlay_instance = nil
end

#read_file(filename) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vendorificator/config.rb', line 42

def read_file(filename)
  pathname = Pathname.new(filename).cleanpath.expand_path

  @configuration[:vendorfile_path] = pathname
  @configuration[:root_dir] = if pathname.basename.to_s == 'vendor.rb' &&
                      pathname.dirname.basename.to_s == 'config'
      pathname.dirname.dirname
    else
      pathname.dirname
    end

  instance_eval(IO.read(filename), filename, 1)
end

#rubygems_bundler(&block) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/vendorificator/vendor/tool.rb', line 64

def rubygems_bundler(&block)
  tool 'rubygems',
       :path => 'cache', # Hardcoded, meh
       :specs => [ 'Gemfile', 'Gemfile.lock' ],
       :command => 'bundle package --all',
       &block
end