Class: PackageFacts
- Inherits:
-
Object
- Object
- PackageFacts
- Defined in:
- lib/lace/package/facts.rb
Instance Attribute Summary collapse
-
#facts_file ⇒ Object
readonly
Returns the value of attribute facts_file.
Instance Method Summary collapse
- #config_files ⇒ Object
- #flavor!(the_flavor) ⇒ Object
- #flavor_with(the_flavor) ⇒ Object
- #flavors ⇒ Object
- #has_flavors? ⇒ Boolean
- #has_key?(key) ⇒ Boolean
- #homepage ⇒ Object
-
#initialize(package_path) ⇒ PackageFacts
constructor
A new instance of PackageFacts.
- #inspect ⇒ Object
- #post(hook_point) ⇒ Object
- #setup_files ⇒ Object
- #unflavor! ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(package_path) ⇒ PackageFacts
Returns a new instance of PackageFacts.
11 12 13 14 15 16 17 |
# File 'lib/lace/package/facts.rb', line 11 def initialize package_path @package_path = Pathname.new(package_path) @facts_file = @package_path/".lace.yml" raise PackageFactsNotFound.new(@package_path) unless @facts_file.exist? @facts = facts_file_to_hash @unflavorable_facts = facts_file_to_hash end |
Instance Attribute Details
#facts_file ⇒ Object (readonly)
Returns the value of attribute facts_file.
5 6 7 |
# File 'lib/lace/package/facts.rb', line 5 def facts_file @facts_file end |
Instance Method Details
#config_files ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/lace/package/facts.rb', line 27 def config_files if @unflavorable_facts.nil? or @facts["config_files"].nil? [] else @facts["config_files"].flatten.map do |file| @package_path + file end end end |
#flavor!(the_flavor) ⇒ Object
65 66 67 68 |
# File 'lib/lace/package/facts.rb', line 65 def flavor! the_flavor raise PackageFlavorDoesNotExist.new(the_flavor, flavors) unless flavors.include? the_flavor @facts = @unflavorable_facts["flavors"][the_flavor] end |
#flavor_with(the_flavor) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/lace/package/facts.rb', line 19 def flavor_with the_flavor if has_flavors? && the_flavor.nil? raise FlavorArgumentRequired.new flavors elsif has_flavors? && the_flavor != false flavor! the_flavor end end |
#flavors ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/lace/package/facts.rb', line 57 def flavors if @unflavorable_facts && @unflavorable_facts.key?("flavors") @unflavorable_facts["flavors"].keys.sort else [] end end |
#has_flavors? ⇒ Boolean
37 38 39 |
# File 'lib/lace/package/facts.rb', line 37 def has_flavors? @unflavorable_facts && !@unflavorable_facts["flavors"].nil? end |
#has_key?(key) ⇒ Boolean
41 42 43 |
# File 'lib/lace/package/facts.rb', line 41 def has_key? key @unflavorable_facts && @unflavorable_facts.has_key?(key) end |
#homepage ⇒ Object
53 54 55 |
# File 'lib/lace/package/facts.rb', line 53 def homepage @unflavorable_facts["homepage"] if @unflavorable_facts.key? "homepage" end |
#inspect ⇒ Object
7 8 9 |
# File 'lib/lace/package/facts.rb', line 7 def inspect "#<Facts:#{@package_path}>" end |
#post(hook_point) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/lace/package/facts.rb', line 74 def post hook_point if @unflavorable_facts.nil? or !@facts.key? "post" [] else post_hook = @facts["post"] (post_hook[hook_point.to_s] || []).flatten end end |
#setup_files ⇒ Object
49 50 51 |
# File 'lib/lace/package/facts.rb', line 49 def setup_files @facts["setup"].flatten rescue [] end |
#unflavor! ⇒ Object
70 71 72 |
# File 'lib/lace/package/facts.rb', line 70 def unflavor! @facts = @unflavorable_facts end |
#version ⇒ Object
45 46 47 |
# File 'lib/lace/package/facts.rb', line 45 def version @unflavorable_facts["version"] if @unflavorable_facts.key? "version" end |