Class: Moonrope::DSL::FilterableDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/moonrope/dsl/filterable_dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ FilterableDSL

Returns a new instance of FilterableDSL.



5
6
7
# File 'lib/moonrope/dsl/filterable_dsl.rb', line 5

def initialize(action)
  @action = action
end

Instance Method Details

#attribute(name, options = {}, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/moonrope/dsl/filterable_dsl.rb', line 9

def attribute(name, options = {}, &block)
  if options[:type] == Integer || options[:type] == Float
    # Numbers
    options[:operators] ||= [:eq, :not_eq, :gt, :gte, :lt, :lte, :in, :not_in]
  elsif options[:type] == String
    # Strings
    options[:operators] ||= [:eq, :not_eq, :starts_with, :ends_with, :in, :not_in]
  elsif options[:type] == :timestamp
    # Times
    options[:operators] ||= [:eq, :not_eq, :gt, :gte, :lt, :lte]
  else
    # Everything else
    options[:operators] ||= [:eq, :not_eq]
  end
  @action.filters[name] = options.merge(:name => name, :block => block)
end