Class: Safrano::Order

Inherits:
OrderBase show all
Defined in:
lib/odata/collection_order.rb

Direct Known Subclasses

MultiOrder

Constant Summary

Constants inherited from OrderBase

Safrano::OrderBase::EmptyOrder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OrderBase

factory, #parse_error?

Constructor Details

#initialize(ostr, jh) ⇒ Order

Returns a new instance of Order.



34
35
36
37
38
39
# File 'lib/odata/collection_order.rb', line 34

def initialize(ostr, jh)
  ostr.strip!
  @orderp = ostr
  @jh = jh
  build_oarg if @orderp
end

Instance Attribute Details

#oargObject (readonly)

Returns the value of attribute oarg.



32
33
34
# File 'lib/odata/collection_order.rb', line 32

def oarg
  @oarg
end

Instance Method Details

#apply_to_dataset(dtcx) ⇒ Object



45
46
47
48
49
# File 'lib/odata/collection_order.rb', line 45

def apply_to_dataset(dtcx)
  # Warning, we need order_append, simply order(oarg) overwrites
  # previous one !
  dtcx.order_append(@oarg)
end

#build_oargObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/odata/collection_order.rb', line 51

def build_oarg
  field, ord = @orderp.split(' ')
  oargu = if field.include?('/')
            @assoc, field = field.split('/')
            @jh.add @assoc

            Sequel[@jh.start_model.get_alias_sym(@assoc)][field.strip.to_sym]
          else
            Sequel[field.strip.to_sym]
          end

  @oarg = if ord == 'desc'
            Sequel.desc(oargu)
          else
            Sequel.asc(oargu)
          end
end

#empty?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/odata/collection_order.rb', line 41

def empty?
  false
end