Class: Cookbook
- Inherits:
-
Object
- Object
- Cookbook
- Includes:
- FileUtils, Thor::Actions, Thor::Base
- Defined in:
- lib/mofa/cookbook.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cookbooks_url ⇒ Object
Returns the value of attribute cookbooks_url.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pkg_uri ⇒ Object
Returns the value of attribute pkg_uri.
-
#source_uri ⇒ Object
Returns the value of attribute source_uri.
-
#token ⇒ Object
Returns the value of attribute token.
-
#type ⇒ Object
Returns the value of attribute type.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #autodetect_type ⇒ Object
- #error(detail) ⇒ Object
- #ok(detail = nil) ⇒ Object
-
#run(cmd, *args) ⇒ Object
Enforce silent system calls, unless the –verbose option is passed.
- #say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
Instance Attribute Details
#cookbooks_url ⇒ Object
Returns the value of attribute cookbooks_url.
15 16 17 |
# File 'lib/mofa/cookbook.rb', line 15 def cookbooks_url @cookbooks_url end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/mofa/cookbook.rb', line 10 def name @name end |
#pkg_uri ⇒ Object
Returns the value of attribute pkg_uri.
13 14 15 |
# File 'lib/mofa/cookbook.rb', line 13 def pkg_uri @pkg_uri end |
#source_uri ⇒ Object
Returns the value of attribute source_uri.
14 15 16 |
# File 'lib/mofa/cookbook.rb', line 14 def source_uri @source_uri end |
#token ⇒ Object
Returns the value of attribute token.
16 17 18 |
# File 'lib/mofa/cookbook.rb', line 16 def token @token end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/mofa/cookbook.rb', line 12 def type @type end |
#version ⇒ Object
Returns the value of attribute version.
11 12 13 |
# File 'lib/mofa/cookbook.rb', line 11 def version @version end |
Class Method Details
.create(cookbook_name_or_path = '.', token = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mofa/cookbook.rb', line 18 def self.create(cookbook_name_or_path='.', token=nil) cb = nil begin case when cookbook_name_or_path.match(/:/) fail "Did not find released Cookbook #{cookbook_name_or_path}!" unless ReleasedCookbook.exists?(cookbook_name_or_path) fail "Did not find Version #{cookbook_version} of released Cookbook #{cookbook_name_or_path}!" unless ReleasedCookbook.exists?(cookbook_name_or_path, cookbook_version) cb = ReleasedCookbook.new(cookbook_name_or_path) else cb = SourceCookbook.new(cookbook_name_or_path) end rescue RuntimeError => e error e. raise "Cookbook not found/detected!" end cb.token = token cb.autodetect_type cb end |
Instance Method Details
#autodetect_type ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mofa/cookbook.rb', line 42 def autodetect_type env_indicator = Mofa::Config.config['cookbook_type_indicator']['env'] wrapper_indicator = Mofa::Config.config['cookbook_type_indicator']['wrapper'] base_indicator = Mofa::Config.config['cookbook_type_indicator']['base'] say "Autodetecting Cookbook Architectural Type... " case when @name.match(env_indicator) @type = 'env' when @name.match(wrapper_indicator) @type = 'wrapper' when @name.match(base_indicator) @type = 'base' else @type = 'application' end say "#{type.capitalize} Cookbook" end |
#error(detail) ⇒ Object
71 72 73 |
# File 'lib/mofa/cookbook.rb', line 71 def error(detail) say detail, :red end |
#ok(detail = nil) ⇒ Object
66 67 68 69 |
# File 'lib/mofa/cookbook.rb', line 66 def ok(detail=nil) text = detail ? "OK, #{detail}." : "OK." say text, :green end |
#run(cmd, *args) ⇒ Object
Enforce silent system calls, unless the –verbose option is passed. One may either pass -v, –verbose or –[v|verbose]=.
78 79 80 81 82 83 84 |
# File 'lib/mofa/cookbook.rb', line 78 def run(cmd, *args) args = args.empty? ? {} : args.pop verbose = (Mofa::CLI::option_debug) ? true : false #verbose = !!(options[:verbose] && options[:verbose].to_s.match(/(verbose|true|t|yes|y|1)$/i)) exit_code = super(cmd, args.merge(:verbose => verbose)) fail "Failed to run #{cmd.inspect}!" unless exit_code == true end |
#say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)$/)) ⇒ Object
61 62 63 64 |
# File 'lib/mofa/cookbook.rb', line 61 def say( = "", color = nil, force_new_line = (.to_s !~ /( |\t)$/)) color ||= :green super end |