Class: Moonshine::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/moonshine/filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **options, &block) ⇒ Filter

Returns a new instance of Filter.



6
7
8
9
10
# File 'lib/moonshine/filter.rb', line 6

def initialize(name, **options, &block)
  @name = name
  options[:call] ||= block || name
  @options = options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/moonshine/filter.rb', line 4

def name
  @name
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/moonshine/filter.rb', line 4

def options
  @options
end

#paramsObject

Returns the value of attribute params.



4
5
6
# File 'lib/moonshine/filter.rb', line 4

def params
  @params
end

Instance Method Details

#execute(subject) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/moonshine/filter.rb', line 12

def execute(subject)
  return subject unless to_execute?
  if options[:as_boolean]
    subject.send(options[:call])
  else
    if options[:call].is_a? Proc
      options[:call].call(subject, args)
    else
      subject.send(options[:call], args)
    end
  end
end

#to_execute?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/moonshine/filter.rb', line 25

def to_execute?
  !!default
end