Class: App::UtilsRoutes

Inherits:
Object
  • Object
show all
Defined in:
lib/core/utils_routes.rb

Class Method Summary collapse

Class Method Details

.flags_set(opts) ⇒ Object

Returns number of flags set for route (from @opts variable)

Parameters:

  • Array (@opts)

Returns:

  • int



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

Parameters:

  • Array (@opts)

Returns:

  • void



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 only set one #{App::Terminal::format_highlight('flag')} at a time", error_text)
    end
end