Class: Glimmer::Launcher
- Inherits:
-
Object
- Object
- Glimmer::Launcher
- Defined in:
- lib/glimmer/launcher.rb
Overview
Launcher of glimmer applications and main entry point for the ‘glimmer` command.
Constant Summary collapse
- TEXT_USAGE =
TODO update the verbiage below for Glimmer DSL for LibUI
"Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development Cross-Platform Native GUI Library) - Ruby Gem: glimmer-dsl-libui v\#{File.read(File.expand_path('../../../VERSION', __FILE__))}\nUsage: glimmer [--bundler] [--pd] [--quiet] [--debug] [--log-level=VALUE] [[ENV_VAR=VALUE]...] [[-ruby-option]...] (application.rb or task[task_args])\n\nRuns Glimmer applications and tasks.\n\nWhen applications are specified, they are run using Ruby,\nautomatically preloading the glimmer-dsl-libui Ruby gem.\n\nOptionally, extra Glimmer options, Ruby options, and/or environment variables may be passed in.\n\nGlimmer options:\n- \"--bundler=GROUP\" : Activates gems in Bundler default group in Gemfile\n- \"--pd=BOOLEAN\" : Requires puts_debuggerer to enable pd method\n- \"--quiet=BOOLEAN\" : Does not announce file path of Glimmer application being launched\n- \"--debug\" : Displays extra debugging information and enables debug logging\n- \"--log-level=VALUE\" : Sets Glimmer's Ruby logger level (\"ERROR\" / \"WARN\" / \"INFO\" / \"DEBUG\"; default is none)\n\nTasks are run via rake. Some tasks take arguments in square brackets (surround with double-quotes if using Zsh).\n\nAvailable tasks are below (if you do not see any, please add `require 'glimmer/rake_task'` to Rakefile and rerun or run rake -T):\n \n"- GLIMMER_LIB_GEM =
'glimmer-dsl-libui'- GLIMMER_LIB_LOCAL =
File.(File.join('lib', "#{GLIMMER_LIB_GEM}.rb"))
- GLIMMER_OPTIONS =
%w[--log-level --quiet --bundler --pd]- GLIMMER_OPTION_ENV_VAR_MAPPING =
{ '--log-level' => 'GLIMMER_LOGGER_LEVEL' , '--bundler' => 'GLIMMER_BUNDLER_SETUP' , '--pd' => 'PD' , }
- REGEX_RAKE_TASK_WITH_ARGS =
/^([^\[]+)\[?([^\]]*)\]?$/
Instance Attribute Summary collapse
-
#application_paths ⇒ Object
readonly
Returns the value of attribute application_paths.
-
#env_vars ⇒ Object
readonly
Returns the value of attribute env_vars.
-
#glimmer_options ⇒ Object
readonly
Returns the value of attribute glimmer_options.
-
#ruby_options ⇒ Object
readonly
Returns the value of attribute ruby_options.
Class Method Summary collapse
- .dev_mode? ⇒ Boolean
- .glimmer_lib ⇒ Object
- .glimmer_option_env_vars(glimmer_options) ⇒ Object
- .is_arm64? ⇒ Boolean
- .launch(application, ruby_options: [], env_vars: {}, glimmer_options: {}) ⇒ Object
- .load_env_vars(env_vars) ⇒ Object
Instance Method Summary collapse
-
#initialize(raw_options) ⇒ Launcher
constructor
A new instance of Launcher.
- #launch ⇒ Object
Constructor Details
#initialize(raw_options) ⇒ Launcher
Returns a new instance of Launcher.
137 138 139 140 141 142 143 144 |
# File 'lib/glimmer/launcher.rb', line 137 def initialize() << '--quiet' if !caller.join("\n").include?('/bin/glimmer:') && !.join.include?('--quiet=') << '--log-level=DEBUG' if .join.include?('--debug') && !.join.include?('--log-level=') @application_path = extract_application_path() @env_vars = extract_env_vars() = () = end |
Instance Attribute Details
#application_paths ⇒ Object (readonly)
Returns the value of attribute application_paths.
132 133 134 |
# File 'lib/glimmer/launcher.rb', line 132 def application_paths @application_paths end |
#env_vars ⇒ Object (readonly)
Returns the value of attribute env_vars.
133 134 135 |
# File 'lib/glimmer/launcher.rb', line 133 def env_vars @env_vars end |
#glimmer_options ⇒ Object (readonly)
Returns the value of attribute glimmer_options.
134 135 136 |
# File 'lib/glimmer/launcher.rb', line 134 def end |
#ruby_options ⇒ Object (readonly)
Returns the value of attribute ruby_options.
135 136 137 |
# File 'lib/glimmer/launcher.rb', line 135 def end |
Class Method Details
.dev_mode? ⇒ Boolean
84 85 86 |
# File 'lib/glimmer/launcher.rb', line 84 def dev_mode? glimmer_lib == GLIMMER_LIB_LOCAL end |
.glimmer_lib ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/glimmer/launcher.rb', line 73 def glimmer_lib unless @glimmer_lib @glimmer_lib = GLIMMER_LIB_GEM if File.exist?(GLIMMER_LIB_LOCAL) @glimmer_lib = GLIMMER_LIB_LOCAL puts "[DEVELOPMENT MODE] (detected #{@glimmer_lib})" end end @glimmer_lib end |
.glimmer_option_env_vars(glimmer_options) ⇒ Object
88 89 90 91 92 |
# File 'lib/glimmer/launcher.rb', line 88 def glimmer_option_env_vars() GLIMMER_OPTION_ENV_VAR_MAPPING.reduce({}) do |hash, pair| [pair.first] ? hash.merge(GLIMMER_OPTION_ENV_VAR_MAPPING[pair.first] => [pair.first]) : hash end end |
.is_arm64? ⇒ Boolean
68 69 70 71 |
# File 'lib/glimmer/launcher.rb', line 68 def is_arm64? host_cpu = OS.host_cpu.downcase host_cpu.include?('aarch64') || host_cpu.include?('arm') end |
.launch(application, ruby_options: [], env_vars: {}, glimmer_options: {}) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/glimmer/launcher.rb', line 100 def launch(application, ruby_options: [], env_vars: {}, glimmer_options: {}) = .join(' ') + ' ' if .any? env_vars = env_vars.merge(glimmer_option_env_vars()) env_vars.each do |k,v| ENV[k] = v end the_glimmer_lib = glimmer_lib require 'puts_debuggerer' if the_glimmer_lib == GLIMMER_LIB_LOCAL is_rake_task = !application.end_with?('.rb') rake_tasks = [] if is_rake_task load File.('./Rakefile') if File.exist?(File.('./Rakefile')) && caller.join("\n").include?('/bin/glimmer:') require_relative 'rake_task' rake_tasks = Rake.application.tasks.map(&:to_s).map {|t| t.sub('glimmer:', '')} potential_rake_task_parts = application.match(REGEX_RAKE_TASK_WITH_ARGS) application = potential_rake_task_parts[1] rake_task_args = potential_rake_task_parts[2].split(',') end if rake_tasks.include?(application) load_env_vars(glimmer_option_env_vars()) rake_task = "glimmer:#{application}" puts "Running Glimmer rake task: #{rake_task}" if .to_s.include?('--debug') Rake::Task[rake_task].invoke(*rake_task_args) else puts "Launching Glimmer Application: #{application}" if .to_s.include?('--debug') || ['--quiet'].to_s.downcase != 'true' require the_glimmer_lib load File.(application) end end |
.load_env_vars(env_vars) ⇒ Object
94 95 96 97 98 |
# File 'lib/glimmer/launcher.rb', line 94 def load_env_vars(env_vars) env_vars.each do |key, value| ENV[key] = value end end |
Instance Method Details
#launch ⇒ Object
146 147 148 149 150 151 152 |
# File 'lib/glimmer/launcher.rb', line 146 def launch if @application_path.nil? display_usage else launch_application end end |