Sha256: ed2ccb131eb55490039d66249821c463d92f14d93b92baf81a65fb8860e053a4

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

module Faalis
  module Generators
    module Concerns

      # 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:
      #
      # ```javascript
      # ...
      # "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.
      module Where
        private

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

        # Return a hash of parameters to pass to where method
        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
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
faalis-2.0.0.rc6 lib/faalis/generators/concerns/where.rb
faalis-2.0.0.rc5 lib/faalis/generators/concerns/where.rb
faalis-2.0.0.rc4 lib/faalis/generators/concerns/where.rb
faalis-2.0.0.rc3 lib/faalis/generators/concerns/where.rb
faalis-2.0.0.rc2 lib/faalis/generators/concerns/where.rb
faalis-1.0.0 lib/faalis/generators/concerns/where.rb
faalis-1.0.0.alpha4 lib/faalis/generators/concerns/where.rb
faalis-1.0.0.alpha3 lib/faalis/generators/concerns/where.rb
faalis-1.0.0.alpha2 lib/faalis/generators/concerns/where.rb
faalis-1.0.0.alpha1 lib/faalis/generators/concerns/where.rb