Class: Appfuel::Repository::OrderExpr

Inherits:
Expr
  • Object
show all
Defined in:
lib/appfuel/storage/repository/order_expr.rb

Instance Attribute Summary

Attributes inherited from Expr

#attr_list, #domain_attr, #domain_basename, #feature, #op, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#conjunction?, #domain_name, #global?, #qualified?, #qualify_feature, #qualify_global, #validate_as_fully_qualified

Constructor Details

#initialize(domain_attr, op = nil) ⇒ OrderExpr

Returns a new instance of OrderExpr.



29
30
31
32
33
34
35
36
37
# File 'lib/appfuel/storage/repository/order_expr.rb', line 29

def initialize(domain_attr, op = nil)
  op ||= 'asc'

  super(domain_attr, op, nil)
  @op = @op.downcase
  unless ['asc', 'desc'].include?(@op)
    fail "order direction must be either asc or desc"
  end
end

Class Method Details

.build(data) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/appfuel/storage/repository/order_expr.rb', line 5

def self.build(data)
  return [data] if data.instance_of?(self)
  data = [data] if data.is_a?(String)
  unless data.respond_to?(:each)
    fail "order must be a string or implement :each"
  end

  results = []
  data.each do |item|
    item = parse_order_string(item) if item.is_a?(String)
    if item.instance_of?(self)
      results << item
      next
    end

    if !item.is_a?(Hash)
      fail "order array must be a list of strings or hashes"
    end
    domain_attr, dir = item.first
    results << self.new(domain_attr, dir)
  end
  results
end

Instance Method Details

#to_sObject



39
40
41
# File 'lib/appfuel/storage/repository/order_expr.rb', line 39

def to_s
  "#{attr_list.join('.')} #{op}"
end