Class: MRubyPortable::Config
- Inherits:
-
Object
- Object
- MRubyPortable::Config
- Defined in:
- lib/mruby_portable/config.rb
Constant Summary collapse
- CONFIG_FILENAMES =
["mruby-portable.yml", "mruby-p.yml"].freeze
- DEFAULT_MAIN =
"main.rb"- DEFAULT_ASSETS =
"assets"- DEFAULT_VERSION =
"01.00"- XMB_ASSET_KEYS =
%w[icon background preview preview_video].freeze
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#background ⇒ Object
readonly
Returns the value of attribute background.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#preview ⇒ Object
readonly
Returns the value of attribute preview.
-
#preview_video ⇒ Object
readonly
Returns the value of attribute preview_video.
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #assets_path ⇒ Object
- #background_path ⇒ Object
- #icon_path ⇒ Object
-
#initialize(project_dir, data) ⇒ Config
constructor
A new instance of Config.
- #main_path ⇒ Object
- #preview_path ⇒ Object
- #preview_video_path ⇒ Object
- #target_name ⇒ Object
Constructor Details
#initialize(project_dir, data) ⇒ Config
Returns a new instance of Config.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mruby_portable/config.rb', line 29 def initialize(project_dir, data) @project_dir = File.(project_dir) @name = string_value(data, "name") || File.basename(@project_dir) @title = string_value(data, "title") || @name @version = string_value(data, "version") || DEFAULT_VERSION @main = string_value(data, "main") || DEFAULT_MAIN @assets = string_value(data, "assets") || DEFAULT_ASSETS @icon = string_value(data, "icon") @background = string_value(data, "background") @preview = string_value(data, "preview") @preview_video = string_value(data, "preview_video") validate! end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def assets @assets end |
#background ⇒ Object (readonly)
Returns the value of attribute background.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def background @background end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def icon @icon end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def main @main end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def name @name end |
#preview ⇒ Object (readonly)
Returns the value of attribute preview.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def preview @preview end |
#preview_video ⇒ Object (readonly)
Returns the value of attribute preview_video.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def preview_video @preview_video end |
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def project_dir @project_dir end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def title @title end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
13 14 15 |
# File 'lib/mruby_portable/config.rb', line 13 def version @version end |
Class Method Details
.load(project_dir) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mruby_portable/config.rb', line 16 def self.load(project_dir) project_dir = File.(project_dir) path = CONFIG_FILENAMES.map { |name| File.join(project_dir, name) }.find { |candidate| File.file?(candidate) } raise Error, "mruby-portable.yml was not found in #{project_dir}" unless path data = YAML.safe_load(File.read(path), aliases: false) || {} raise Error, "#{File.basename(path)} must contain a mapping" unless data.is_a?(Hash) new(project_dir, data) rescue Psych::SyntaxError => e raise Error, "failed to parse project config: #{e.}" end |
Instance Method Details
#assets_path ⇒ Object
48 49 50 |
# File 'lib/mruby_portable/config.rb', line 48 def assets_path (assets) end |
#background_path ⇒ Object
56 57 58 |
# File 'lib/mruby_portable/config.rb', line 56 def background_path optional_project_path(background) end |
#icon_path ⇒ Object
52 53 54 |
# File 'lib/mruby_portable/config.rb', line 52 def icon_path optional_project_path(icon) end |
#main_path ⇒ Object
44 45 46 |
# File 'lib/mruby_portable/config.rb', line 44 def main_path (main) end |
#preview_path ⇒ Object
60 61 62 |
# File 'lib/mruby_portable/config.rb', line 60 def preview_path optional_project_path(preview) end |
#preview_video_path ⇒ Object
64 65 66 |
# File 'lib/mruby_portable/config.rb', line 64 def preview_video_path optional_project_path(preview_video) end |
#target_name ⇒ Object
68 69 70 71 72 73 |
# File 'lib/mruby_portable/config.rb', line 68 def target_name normalized = name.gsub(/[^0-9A-Za-z_]+/, "_").gsub(/\A_+|_+\z/, "") normalized = "game" if normalized.empty? normalized = "game_#{normalized}" unless normalized.match?(/\A[A-Za-z_]/) normalized end |