Class: Gloo::App::Args
- Inherits:
-
Object
- Object
- Gloo::App::Args
- Defined in:
- lib/gloo/app/args.rb
Constant Summary collapse
- QUIET =
'quiet'.freeze
- GLOO_ENV =
'GLOO_ENV'.freeze
Instance Attribute Summary collapse
-
#app_path ⇒ Object
readonly
Returns the value of attribute app_path.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#switches ⇒ Object
readonly
Returns the value of attribute switches.
Instance Method Summary collapse
-
#app? ⇒ Boolean
Is the app switch set?.
-
#cli? ⇒ Boolean
Is the cli switch set?.
-
#detect_mode ⇒ Object
Detect the mode to be run in.
-
#embed? ⇒ Boolean
Is the embed switch set?.
-
#help? ⇒ Boolean
Is the help switch set?.
-
#initialize(engine, params = []) ⇒ Args
constructor
Create arguments and setup.
-
#quiet? ⇒ Boolean
Was the –quiet arg passed?.
-
#verify_app_mode ⇒ Object
Make sure that if we are running in App mode that the app path has been set and is a valid path.
-
#version? ⇒ Boolean
Is the version switch set?.
Constructor Details
#initialize(engine, params = []) ⇒ Args
Create arguments and setup.
22 23 24 25 26 27 28 29 30 |
# File 'lib/gloo/app/args.rb', line 22 def initialize( engine, params = [] ) @engine = engine @switches = [] @files = [] @app_path = nil params.each { |o| process_one_arg( o ) } ARGV.each { |o| process_one_arg( o ) } end |
Instance Attribute Details
#app_path ⇒ Object (readonly)
Returns the value of attribute app_path.
17 18 19 |
# File 'lib/gloo/app/args.rb', line 17 def app_path @app_path end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
17 18 19 |
# File 'lib/gloo/app/args.rb', line 17 def files @files end |
#switches ⇒ Object (readonly)
Returns the value of attribute switches.
17 18 19 |
# File 'lib/gloo/app/args.rb', line 17 def switches @switches end |
Instance Method Details
#app? ⇒ Boolean
Is the app switch set?
42 43 44 |
# File 'lib/gloo/app/args.rb', line 42 def app? @switches.include?( Gloo::App::Mode::APP.to_s ) end |
#cli? ⇒ Boolean
Is the cli switch set?
84 85 86 |
# File 'lib/gloo/app/args.rb', line 84 def cli? @switches.include?( Gloo::App::Mode::CLI.to_s ) end |
#detect_mode ⇒ Object
Detect the mode to be run in. Start by seeing if a mode is specified. Then look for the presence of files. Then finally use the default: embedded mode.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/gloo/app/args.rb', line 101 def detect_mode mode = if ENV[ GLOO_ENV ] == Gloo::App::Mode::TEST.to_s Mode::TEST elsif app? Mode::APP elsif version? Mode::VERSION elsif help? Mode::HELP elsif cli? Mode::CLI elsif Mode::EMBED elsif @files.count.positive? Mode::SCRIPT else Mode.default_mode end mode = Mode::CLI unless verify_app_mode @engine.log.debug "running in #{mode} mode" return mode end |
#embed? ⇒ Boolean
Is the embed switch set?
91 92 93 |
# File 'lib/gloo/app/args.rb', line 91 def @switches.include?( Gloo::App::Mode::EMBED.to_s ) end |
#help? ⇒ Boolean
Is the help switch set?
77 78 79 |
# File 'lib/gloo/app/args.rb', line 77 def help? @switches.include?( Gloo::App::Mode::HELP.to_s ) end |
#quiet? ⇒ Boolean
Was the –quiet arg passed?
35 36 37 |
# File 'lib/gloo/app/args.rb', line 35 def quiet? return @switches.include?( QUIET ) end |
#verify_app_mode ⇒ Object
Make sure that if we are running in App mode that the app path has been set and is a valid path.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gloo/app/args.rb', line 50 def verify_app_mode return true unless app? if @app_path.nil? @engine.err "App Path required to run in App mode." return false end unless File.directory? @app_path @engine.err "'#{@app_path}' is not a valid directory." return false end @engine.log.info "App root directory: '#{@app_path}'." return true end |