Class: Batali::Source
- 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
Defined Under Namespace
Classes: ChefServer, Git, Path, Site
Instance Attribute Summary collapse
-
#cache_path ⇒ String
Path to local cache.
Class Method Summary collapse
-
.build(args) ⇒ Source
Build a source.
Instance Method Summary collapse
- #==(s) ⇒ TrueClass, FalseClass
-
#asset ⇒ String
Directory containing contents.
- #clean_asset(asset_path) ⇒ TrueClass, FalseClass
-
#diff(s) ⇒ Smash
Detect differences in equivalency.
-
#initialize(args = {}) ⇒ Source
constructor
A new instance of Source.
- #unit_dependencies ⇒ Array<Array<name, constraints>>
- #unit_version ⇒ String
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_path ⇒ String
Returns 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
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
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 |
#asset ⇒ String
Returns 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
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
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_dependencies ⇒ Array<Array<name, constraints>>
28 29 30 |
# File 'lib/batali/source.rb', line 28 def unit_dependencies raise NotImplementedError.new 'Abstract class' end |
#unit_version ⇒ String
23 24 25 |
# File 'lib/batali/source.rb', line 23 def unit_version raise NotImplementedError.new 'Abstract class' end |