class Might::FilterParameters

Constants

FilterError

Attributes

parameters[R]

Public Class Methods

new(parameters = nil) click to toggle source

@param [<Might::FilterParameter>]

# File lib/might/filter_parameters.rb, line 14
def initialize(parameters = nil)
  @parameters = Set.new(parameters)
end

Public Instance Methods

+(other) click to toggle source

param other [Might::FilterParameters]

# File lib/might/filter_parameters.rb, line 76
def +(other)
  self.class.new(parameters.merge(other.parameters))
end
-(other) click to toggle source

param other [Might::FilterParameters]

# File lib/might/filter_parameters.rb, line 71
def -(other)
  self.class.new(parameters - other.parameters)
end
<<(value)
Alias for: add
<=>(other) click to toggle source
# File lib/might/filter_parameters.rb, line 90
def <=>(other)
  parameters <=> other.parameters
end
[](name, predicate = nil) click to toggle source

Find filter by name @param name [String] @param predicate [String] @return [Might::FilterParameter, nil]

# File lib/might/filter_parameters.rb, line 35
def [](name, predicate = nil)
  parameters.detect do |filter|
    filter.name == name && (predicate.nil? || filter.predicate == predicate)
  end
end
add(value) click to toggle source

param value [Might::FilterParameter]

# File lib/might/filter_parameters.rb, line 60
def add(value)
  self.class.new(parameters.add(value))
end
Also aliased as: <<
delete(name, predicate = nil) click to toggle source

Delete filter by name and predicate @param name [String] @param predicate [String] @return [Might::FilterParameter, nil]

# File lib/might/filter_parameters.rb, line 84
def delete(name, predicate = nil)
  filter_parameter = self[name, predicate]
  parameters.delete(filter_parameter) if filter_parameter
  filter_parameter
end
fetch(name, predicate = nil) { |name| ... } click to toggle source

Find filter by name or raise error @param name [String] @param predicate [String] @yieldparam name [String]

block value will be returned if no `FilterParameter` found with specified name

@return [Might::FilterParameter] @raise FilterError

# File lib/might/filter_parameters.rb, line 49
def fetch(name, predicate = nil)
  if (filter = self[name, predicate])
    filter
  elsif block_given?
    yield(name)
  else
    fail FilterError, "filter not found: #{name.inspect}"
  end
end
initialize_clone(orig) click to toggle source

Clone internal set.

Calls superclass method
# File lib/might/filter_parameters.rb, line 25
def initialize_clone(orig)
  super
  @parameters = orig.parameters.clone
end
initialize_dup(orig) click to toggle source

Dup internal set.

Calls superclass method
# File lib/might/filter_parameters.rb, line 19
def initialize_dup(orig)
  super
  @parameters = orig.parameters.dup
end
map(&block) click to toggle source
# File lib/might/filter_parameters.rb, line 66
def map(&block)
  self.class.new(parameters.map(&block))
end