Class: Batali::Source

Inherits:
Utility
  • Object
show all
Defined in:
lib/batali/source.rb,
lib/batali/source/git.rb,
lib/batali/source/path.rb,
lib/batali/source/site.rb,
lib/batali/source/chef_server.rb

Overview

Source of asset

Direct Known Subclasses

ChefServer, Path, Site

Defined Under Namespace

Classes: ChefServer, Git, Path, Site

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Source

Returns a new instance of Source.



17
18
19
20
# File 'lib/batali/source.rb', line 17

def initialize(args={})
  @cache_path = args.delete(:cache_path)
  super
end

Instance Attribute Details

#cache_pathString

Returns path to local cache.

Returns:

  • (String)

    path to local cache



13
14
15
# File 'lib/batali/source.rb', line 13

def cache_path
  @cache_path
end

Class Method Details

.build(args) ⇒ Source

Note:

uses ‘:type` to build concrete source

Build a source

Parameters:

  • args (Hash)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/batali/source.rb', line 78

def self.build(args)
  type = args.delete(:type)
  unless(type)
    raise ArgumentError.new 'Missing required option `:type`!'
  end
  unless(type.to_s.include?('::'))
    type = [name, Bogo::Utility.camel(type)].join('::')
  end
  klass = Bogo::Utility.constantize(type)
  unless(klass)
    raise TypeError.new "Unknown source type provided `#{type}`!"
  else
    klass.new(args.merge(:type => type))
  end
end

Instance Method Details

#==(s) ⇒ TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


48
49
50
51
52
53
54
# File 'lib/batali/source.rb', line 48

def ==(s)
  s.is_a?(Source) && attributes.map do |key, attr|
    key if attr[:equivalent]
  end.compact.all? do |key|
    attributes[key] == s.attributes[key]
  end
end

#assetString

Returns directory containing contents.

Returns:

  • (String)

    directory containing contents



33
34
35
# File 'lib/batali/source.rb', line 33

def asset
  raise NotImplementedError.new 'Abstract class'
end

#clean_asset(asset_path) ⇒ TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


38
39
40
41
42
43
44
45
# File 'lib/batali/source.rb', line 38

def clean_asset(asset_path)
  if(cache_path && asset_path.include?(cache_path) && File.exist?(asset_path))
    FileUtils.rm_rf(asset_path)
    true
  else
    false
  end
end

#diff(s) ⇒ Smash

Detect differences in equivalency

Parameters:

Returns:

  • (Smash)


60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/batali/source.rb', line 60

def diff(s)
  Smash.new.tap do |_diff|
    self.class.attributes.each do |k, v|
      if(v[:equivalent])
        s_attrs = s.respond_to?(:attributes) ? s.attributes : {}
        unless(attributes[k] == s_attrs[k])
          _diff[k] = [attributes[k], s_attrs[k]]
        end
      end
    end
  end
end

#unit_dependenciesArray<Array<name, constraints>>

Returns:

  • (Array<Array<name, constraints>>)


28
29
30
# File 'lib/batali/source.rb', line 28

def unit_dependencies
  raise NotImplementedError.new 'Abstract class'
end

#unit_versionString

Returns:

  • (String)


23
24
25
# File 'lib/batali/source.rb', line 23

def unit_version
  raise NotImplementedError.new 'Abstract class'
end