Module: Deli::Param::Order

Included in:
Adapters::ActiveRecord::Order, Adapters::Cassandra::Order, Adapters::Mongoid::Order, Adapters::Neo4j::Order, Adapters::Simple::Order
Defined in:
lib/deli/param.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) order_hash(value)



116
117
118
119
120
121
122
123
# File 'lib/deli/param.rb', line 116

def order_hash(value)
  value.split(",").inject(ActiveSupport::OrderedHash.new) do |hash, string|
    string.scan(/([\w-]+[^\-\+])([\+\-])?/).each do |token, operator|
      hash[clean(token)] = operator == "-" ? "-" : "+"
    end
    hash
  end
end

- (Object) parse(value)



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/deli/param.rb', line 100

def parse(value)
  value.split(",").map do |string|
    string.scan(/([\w-]+[^\-\+])([\+\-])?/).map do |token, operator|
      operator = operator == "-" ? "-" : "+"
      token    = clean(token)
      
      if controller.present?
        param = controller.find(token)
        token = param.table_key
      end

      {:namespace => namespace, :key => token, :operators => [operator]}
    end
  end.flatten
end