Class: Reflex::Packager::Config
- Inherits:
-
Object
- Object
- Reflex::Packager::Config
- Defined in:
- lib/reflex/packager/config.rb
Overview
Application project configuration loaded from ‘reflex.yml’.
Constant Summary collapse
- EXCLUDES =
%w[build dist]
Instance Attribute Summary collapse
-
#bundle_id ⇒ Object
readonly
Returns the value of attribute bundle_id.
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#macos ⇒ Object
readonly
Returns the value of attribute macos.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pods ⇒ Object
readonly
Returns the value of attribute pods.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
- .default_bundle_id(profile, name) ⇒ Object
- .defaults(profile, dir, hash) ⇒ Object
-
.load(profile, dir, path = nil) ⇒ Config
Load the config file in the project directory.
Instance Method Summary collapse
-
#app_files ⇒ Array<String>
Returns paths to be bundled into the application, relative to the project directory.
-
#initialize(profile, dir, hash = nil, stderr: $stderr) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(profile, dir, hash = nil, stderr: $stderr) ⇒ Config
Returns a new instance of Config.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/reflex/packager/config.rb', line 51 def initialize(profile, dir, hash = nil, stderr: $stderr) raise Error, "no such directory: '#{dir}'" unless File.directory? dir @profile = profile @dir = File. dir hash = symbolize_keys hash || {} hash = validate_input hash, Config.defaults(profile, @dir, hash), stderr: stderr @name = hash[:name] .to_s @bundle_id = hash[:bundle_id].to_s @version = hash[:version] .to_s @main = hash[:main] .to_s @icon = hash[:icon] &.to_s @files = hash[:files]&.then {Array(_1).map(&:to_s)} @pods = hash[:pods].transform_values &:compact @macos = MacOSConfig.new hash[:macos] validate end |
Instance Attribute Details
#bundle_id ⇒ Object (readonly)
Returns the value of attribute bundle_id.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def bundle_id @bundle_id end |
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def dir @dir end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def files @files end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def icon @icon end |
#macos ⇒ Object (readonly)
Returns the value of attribute macos.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def macos @macos end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def main @main end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def name @name end |
#pods ⇒ Object (readonly)
Returns the value of attribute pods.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def pods @pods end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def profile @profile end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
70 71 72 |
# File 'lib/reflex/packager/config.rb', line 70 def version @version end |
Class Method Details
.default_bundle_id(profile, name) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/reflex/packager/config.rb', line 91 def self.default_bundle_id(profile, name) id = name.downcase.gsub(/[^a-z0-9\-]+/, '') if id.empty? raise Error, "cannot derive a bundle_id from name '#{name}', " + "set 'bundle_id' in #{profile.config_files.first}" end "#{profile.bundle_id_prefix}.#{id}" end |
.defaults(profile, dir, hash) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/reflex/packager/config.rb', line 18 def self.defaults(profile, dir, hash) name = hash[:name]&.to_s || File.basename(dir) { name: name, bundle_id: hash[:bundle_id] || default_bundle_id(profile, name), version: '0.1.0', main: 'main.rb', icon: nil, files: nil, pods: { :cruby => {tag: nil, branch: nil, git: nil, path: nil}, profile.pod_key => {tag: nil, branch: nil, git: nil, path: nil} }, macos: MacOSConfig.defaults } end |
.load(profile, dir, path = nil) ⇒ Config
Load the config file in the project directory.
43 44 45 46 47 48 49 |
# File 'lib/reflex/packager/config.rb', line 43 def self.load(profile, dir, path = nil) raise Error, "config file not found: '#{path}'" if path && !File.file?(path) path ||= profile.config_files.map {File.join dir, _1}.find {File.file? _1} new profile, dir, (path ? YAML.safe_load(File.read(path), aliases: true) : nil) rescue Psych::SyntaxError => e raise Error, "failed to parse '#{path}': #{e.}" end |
Instance Method Details
#app_files ⇒ Array<String>
Returns paths to be bundled into the application, relative to the project directory.
78 79 80 81 82 83 84 85 |
# File 'lib/reflex/packager/config.rb', line 78 def app_files() excludes = EXCLUDES + @profile.config_files [@main, *@files] .flat_map {Dir.glob _1, base: @dir} .reject {_1.start_with?('.') || excludes.include?(_1)} .uniq .sort end |