Class: Ready::Readyfile
- Inherits:
-
Object
- Object
- Ready::Readyfile
- Defined in:
- lib/ready/readyfile.rb
Overview
Reads the YAML readyfile and exposes the gems and executables it declares.
Defined Under Namespace
Classes: Executable
Instance Attribute Summary collapse
-
#build_dir ⇒ Object
readonly
Returns the value of attribute build_dir.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #each_executable ⇒ Object
- #each_executable_mapping ⇒ Object
- #executable_names ⇒ Object
- #executable_paths ⇒ Object
- #executables ⇒ Object
- #gem_names ⇒ Object
-
#initialize(config, build_dir:, path:) ⇒ Readyfile
constructor
A new instance of Readyfile.
- #to_path ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(config, build_dir:, path:) ⇒ Readyfile
Returns a new instance of Readyfile.
27 28 29 30 31 |
# File 'lib/ready/readyfile.rb', line 27 def initialize(config, build_dir:, path:) @path = path @config = config @build_dir = build_dir end |
Instance Attribute Details
#build_dir ⇒ Object (readonly)
Returns the value of attribute build_dir.
7 8 9 |
# File 'lib/ready/readyfile.rb', line 7 def build_dir @build_dir end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/ready/readyfile.rb', line 7 def config @config end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/ready/readyfile.rb', line 7 def path @path end |
Class Method Details
.open(path, build_dir:) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ready/readyfile.rb', line 9 def self.open(path, build_dir:) path = Pathname(path) # A missing, empty, or null readyfile is not an error: it simply declares # no gems or executables. YAML.parse_file returns false for an empty file, # and a document such as "---" parses to nil. # YAML.parse_file returns `false` for an empty file (not nil), so guard on # truthiness, not with `&.` -- false&.to_ruby would blow up. A "---" # document is truthy but to_ruby's to nil, which the `|| {}` folds to empty. document = (YAML.parse_file(path.to_s) if path.exist?) config = (document ? document.to_ruby : {}) || {} unless config.is_a?(Hash) raise Error, "#{path}: readyfile must be a YAML mapping of gems:/executables:, got #{config.class}" end new config, build_dir:, path: end |
Instance Method Details
#each_executable ⇒ Object
67 68 69 70 71 |
# File 'lib/ready/readyfile.rb', line 67 def each_executable return enum_for __method__ unless block_given? executables.each { yield it } end |
#each_executable_mapping ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/ready/readyfile.rb', line 59 def each_executable_mapping(&) return enum_for __method__ unless block_given? executables.flat_map(&:mapping).each do |mapping| yield(*mapping.to_a) end end |
#executable_names ⇒ Object
51 52 53 |
# File 'lib/ready/readyfile.rb', line 51 def executable_names executables.map(&:name) end |
#executable_paths ⇒ Object
55 56 57 |
# File 'lib/ready/readyfile.rb', line 55 def executable_paths executables.map(&:realpath) end |
#executables ⇒ Object
45 46 47 48 49 |
# File 'lib/ready/readyfile.rb', line 45 def executables config .fetch("executables", []) .map { Executable.new it, build_dir: } end |
#gem_names ⇒ Object
41 42 43 |
# File 'lib/ready/readyfile.rb', line 41 def gem_names config.fetch("gems", []) end |
#to_path ⇒ Object
33 34 35 |
# File 'lib/ready/readyfile.rb', line 33 def to_path path end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/ready/readyfile.rb', line 37 def to_s path.to_s end |