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.
-
#mofa_yml ⇒ Object
Returns the value of attribute mofa_yml.
-
#mofa_yml_local ⇒ Object
Returns the value of attribute mofa_yml_local.
-
#name ⇒ Object
Returns the value of attribute name.
-
#override_mofa_secrets ⇒ Object
Returns the value of attribute override_mofa_secrets.
-
#pkg_dir ⇒ Object
Returns the value of attribute pkg_dir.
-
#pkg_name ⇒ Object
Returns the value of attribute pkg_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.
17 18 19 |
# File 'lib/mofa/cookbook.rb', line 17 def cookbooks_url @cookbooks_url end |
#mofa_yml ⇒ Object
Returns the value of attribute mofa_yml.
18 19 20 |
# File 'lib/mofa/cookbook.rb', line 18 def mofa_yml @mofa_yml end |
#mofa_yml_local ⇒ Object
Returns the value of attribute mofa_yml_local.
19 20 21 |
# File 'lib/mofa/cookbook.rb', line 19 def mofa_yml_local @mofa_yml_local end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/mofa/cookbook.rb', line 10 def name @name end |
#override_mofa_secrets ⇒ Object
Returns the value of attribute override_mofa_secrets.
21 22 23 |
# File 'lib/mofa/cookbook.rb', line 21 def override_mofa_secrets @override_mofa_secrets end |
#pkg_dir ⇒ Object
Returns the value of attribute pkg_dir.
14 15 16 |
# File 'lib/mofa/cookbook.rb', line 14 def pkg_dir @pkg_dir end |
#pkg_name ⇒ Object
Returns the value of attribute pkg_name.
13 14 15 |
# File 'lib/mofa/cookbook.rb', line 13 def pkg_name @pkg_name end |
#pkg_uri ⇒ Object
Returns the value of attribute pkg_uri.
15 16 17 |
# File 'lib/mofa/cookbook.rb', line 15 def pkg_uri @pkg_uri end |
#source_uri ⇒ Object
Returns the value of attribute source_uri.
16 17 18 |
# File 'lib/mofa/cookbook.rb', line 16 def source_uri @source_uri end |
#token ⇒ Object
Returns the value of attribute token.
20 21 22 |
# File 'lib/mofa/cookbook.rb', line 20 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, override_mofa_secrets = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mofa/cookbook.rb', line 23 def self.create(cookbook_name_or_path, token, override_mofa_secrets = nil) cookbook = nil begin case when cookbook_name_or_path.match(/@/) raise "Did not find released Cookbook #{cookbook_name_or_path}!" unless ReleasedCookbook.exists?(cookbook_name_or_path) cookbook = ReleasedCookbook.new(cookbook_name_or_path, override_mofa_secrets) else cookbook = SourceCookbook.new(cookbook_name_or_path, override_mofa_secrets) end rescue RuntimeError => e raise 'Cookbook not found/detected: ' + e. end cookbook.token = token cookbook.autodetect_type cookbook.load_mofa_yml cookbook.load_mofa_yml_local cookbook end |
Instance Method Details
#autodetect_type ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mofa/cookbook.rb', line 45 def autodetect_type env_indicator = '^env_.*' base_indicator = '.*_base$' say 'Autodetecting Cookbook Architectural Type...' case when @name.match(env_indicator) @type = 'env' when @name.match(base_indicator) @type = 'base' else @type = 'application' end say "#{type.capitalize} Cookbook" end |
#error(detail) ⇒ Object
72 73 74 |
# File 'lib/mofa/cookbook.rb', line 72 def error(detail) say detail, :red end |
#ok(detail = nil) ⇒ Object
67 68 69 70 |
# File 'lib/mofa/cookbook.rb', line 67 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]=.
79 80 81 82 83 84 85 |
# File 'lib/mofa/cookbook.rb', line 79 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
62 63 64 65 |
# File 'lib/mofa/cookbook.rb', line 62 def say( = '', color = nil, force_new_line = (.to_s !~ /( |\t)$/)) color ||= :green super end |