Class: LeapCli::Config::Filter
Instance Method Summary collapse
-
#initialize(filters, options, manager) ⇒ Filter
constructor
filter – array of strings, each one a filter options – hash, possible keys include :nopin – disregard environment pinning :local – if false, disallow local nodes.
-
#nodes ⇒ Object
actually run the filter, returns a filtered list of nodes.
Constructor Details
#initialize(filters, options, manager) ⇒ Filter
filter – array of strings, each one a filter options – hash, possible keys include
:nopin -- disregard environment pinning
:local -- if false, disallow local nodes
A nil value in the filters array indicates the default environment. This is in order to support calls like ‘manager.filter(environments)`
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/leap_cli/config/filter.rb', line 37 def initialize(filters, , manager) @filters = filters.nil? ? [] : filters.dup @environments = [] @options = @manager = manager # split filters by pulling out items that happen # to be environment names. if LeapCli.leapfile.environment.nil? || @options[:nopin] @environments = [] else @environments = [LeapCli.leapfile.environment] end @filters.select! do |filter| if filter.nil? @environments << nil unless @environments.include?(nil) false else filter_text = filter.sub(/^\+/,'') if is_environment?(filter_text) if filter_text == LeapCli.leapfile.environment # silently ignore already pinned environments elsif (filter =~ /^\+/ || @filters.first == filter) && !@environments.empty? LeapCli::Util.bail! do LeapCli::Util.log "Environments are exclusive: no node is in two environments." do LeapCli::Util.log "Tried to filter on '#{@environments.join('\' AND \'')}' AND '#{filter_text}'" end end else @environments << filter_text end false else true end end end # don't let the first filter have a + prefix if @filters[0] =~ /^\+/ @filters[0] = @filters[0][1..-1] end end |
Instance Method Details
#nodes ⇒ Object
actually run the filter, returns a filtered list of nodes
82 83 84 85 86 87 88 |
# File 'lib/leap_cli/config/filter.rb', line 82 def nodes() if @filters.empty? return nodes_for_empty_filter else return nodes_for_filter end end |