Class: MindReader

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

Defined Under Namespace

Classes: ConfigurableObject

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) {|@configuration| ... } ⇒ MindReader

Returns a new instance of MindReader.

Yields:

  • (@configuration)


5
6
7
8
9
10
# File 'lib/mind_reader.rb', line 5

def initialize(klass)
  @klass = klass
  @retrieve_all_when_no_value_is_given = false
  @configuration = ConfigurableObject.new
  yield @configuration if block_given?
end

Instance Attribute Details

#retrieve_all_when_no_value_is_givenObject

Returns the value of attribute retrieve_all_when_no_value_is_given.



12
13
14
# File 'lib/mind_reader.rb', line 12

def retrieve_all_when_no_value_is_given
  @retrieve_all_when_no_value_is_given
end

Instance Method Details

#execute(pairs) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/mind_reader.rb', line 14

def execute(pairs)
  @pairs = pairs
  process
  if @pairs.present? || @clause.first.present?
    @klass.where(@pairs).where(*@clause.try(:flatten))
  else
    retrieve_all_when_no_value_is_given ? @klass.find(:all) : nil
  end
end