Sha256: e5cc1ffc9e8999635cee5aa4a3132d13787272bbd8c722852258808f7982c60f

Contents?: true

Size: 1.52 KB

Versions: 50

Compression:

Stored size: 1.52 KB

Contents

module Appfuel
  module Repository
    class SearchTransform <  ExprTransform


      rule(order_dir: simple(:n)) {
        value = n.to_s.downcase
        value == 'desc' ? 'desc' : 'asc'
      }

      rule(order_expr: subtree(:expr)) do |dict|
        expr = dict[:expr]
        domain_attr = expr[:domain_attr]
        order_dir = expr[:order_dir] || 'asc'
        OrderExpr.new(domain_attr, order_dir)
      end

      rule(attr_label: simple(:n)) { n.to_s }

      rule(domain_attr: simple(:n)) {
        list = n.is_a?(Array) ? n : [n]
        {domain_attr: list}
      }

      rule(domain_expr: subtree(:domain_expr)) do |dict|
        data = dict[:domain_expr]
        domain_attr = data[:domain_attr]
        op          = data[:op]
        value       = data[:value]
        Expr.new(domain_attr, op, value)
      end

      rule(search: subtree(:search)) do |dict|
        search  = dict[:search]
        domain  = search[:domain]
        filters = search[:filters]
        orders  = search[:order]
        limit   = search[:limit]

        if filters.is_a?(Hash) && filters.key?(:root)
          filters = filters[:root]
        end
        result  = {}
        result[:domain]  = "#{domain[:feature]}.#{domain[:basename]}"
        result[:filters] = filters
        unless limit.nil?
          result[:limit] = limit[:value]
        end

        unless orders.nil?
          orders = orders.is_a?(Array) ? orders : [orders]
          result[:order] = orders
        end
        {search: Criteria.build(result)}
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
appfuel-0.7.0 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.16 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.15 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.14 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.13 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.12 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.11 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.10 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.9 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.8 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.7 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.6 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.5 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.4 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.3 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.6.1 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.5.16 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.5.15 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.5.14 lib/appfuel/storage/repository/search_transform.rb
appfuel-0.5.13 lib/appfuel/storage/repository/search_transform.rb