Module: SimpleAMS::Options::Concerns::Filterable

Included in:
Fields, Forms, Generics, Includes, Links, Metas
Defined in:
lib/simple_ams/options/concerns/filterable.rb

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

for optimizing performance, ask only the first element other idea is to create another module just for (Name)ValueHash objects



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_ams/options/concerns/filterable.rb', line 7

def &(other)
  other_is_object = (other[0].respond_to?(:name) && other[0].class != Symbol)

  self.class.new(
    self.select do |m|
      if other_is_object
        other.include?(m.name)
      else
        other.include?(m)
      end
    end
  )
end

#include?(member) ⇒ Boolean

for optimizing performance, ask only the first element of self and save it as state

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
# File 'lib/simple_ams/options/concerns/filterable.rb', line 22

def include?(member)
  @self_is_object = self[0].respond_to?(:name) && self[0].class != Symbol unless defined?(@self_is_object)

  if @self_is_object
    any? { |s| s.name == member }
  else
    super
  end
end

#rawObject



32
33
34
35
36
37
38
# File 'lib/simple_ams/options/concerns/filterable.rb', line 32

def raw
  if self[0].respond_to?(:raw)
    map(&:raw)
  else
    map { |i| i }
  end
end