Module: Faalis::Generators::Concerns::Where

Included in:
DashboardScaffold
Defined in:
lib/faalis/generators/concerns/where.rb

Overview

This module is dedicated to filter resource object based on a condition or query. For example if you want to filter a resource objects to those which belongs to current logged in user you can do like:

...
"where": {
    "user": "current_user"
}
...

where value is an object which each key is a ruby model field name and its value is the actual value that you want to use to check the field against that.

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) where_cond? (private)

Returns:

  • (Boolean)


24
25
26
27
28
29
# File 'lib/faalis/generators/concerns/where.rb', line 24

def where_cond?
  if resource_data.include? 'where'
    return true unless resource_data['where'].empty?
  end
  false
end

- (Object) where_conditions (private)

Return a hash of parameters to pass to where method



32
33
34
35
36
37
38
39
40
# File 'lib/faalis/generators/concerns/where.rb', line 32

def where_conditions
  if has_where_cond?
    flat_array = resource_data['where'].map do |field, value|
      [field.to_sym, value]
    end
    Hash[flat_array]
  end
  {}
end