Class: App::UtilsRoutes
- Inherits:
-
Object
- Object
- App::UtilsRoutes
- Defined in:
- lib/core/utils_routes.rb
Class Method Summary collapse
-
.atleast_one_flag(opts) ⇒ Object
Will throw an error if no flags are set.
-
.flags_set(opts) ⇒ Object
Returns number of flags set for route (from @opts variable).
-
.max_one_flag(opts) ⇒ Object
Will throw an error if more than one flag is set.
Class Method Details
.atleast_one_flag(opts) ⇒ Object
Will throw an error if no flags are set.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/core/utils_routes.rb', line 45 def self.atleast_one_flag(opts) all_flags = [] opts.each_key do |key| unless key.to_s =~ /_given\z/i || key == :version || key == :help all_flags << key.to_s end end if flags_set(opts) <= 0 error_text = ['Available flags are:', nil] all_flags.each do |flag| error_text << " \x1B[38;5;244m--#{flag}\x1B[0m" end App::Terminal::error("You must set #{App::Terminal::format_highlight('atleast one')} flag", error_text) end end |
.flags_set(opts) ⇒ Object
Returns number of flags set for route (from @opts variable)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/core/utils_routes.rb', line 8 def self.flags_set(opts) flags_set = 0 opts.each do |key, value| # Only here to prevent code-inspector from complaining. key.strip! if key.nil? if value flags_set = flags_set + 1 end end if flags_set > 0 flags_set = flags_set / 2 end flags_set end |
.max_one_flag(opts) ⇒ Object
Will throw an error if more than one flag is set.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/core/utils_routes.rb', line 26 def self.max_one_flag(opts) all_flags = [] opts.each_key do |key| unless key.to_s =~ /_given\z/i || key == :version || key == :help all_flags << key.to_s end end if flags_set(opts) >= 2 error_text = ['Please set 1 one of the following flags:', nil] all_flags.each do |flag| error_text << " \x1B[38;5;244m--#{flag}\x1B[0m" end App::Terminal::error("You can set #{App::Terminal::format_highlight('only one')} flag at a time", error_text) end end |