Class: Anoubis::Etc::FieldOrder

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/anoubis/etc/field_order.rb

Overview

Definitions of fields order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FieldOrder

Sets default parameters for field order

Parameters:

  • options (Hash) (defaults to: {})

    initial model options

Options Hash (options):

  • :field (String, Array, Symbol)

    describes field or fields name for order

  • :order (Symbol)

    default order type (:asc or :desc)

  • :default (Boolean)

    if this field default in order list



27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/anoubis/etc/field_order.rb', line 27

def initialize(options = {})
  self.default = false
  if options.key? :default
    self.default = true if options[:default].class == TrueClass
  end
  self.order = :asc
  if options.key? :order
    self.order = :desc if options[:order] == :desc || options[:order].to_s.downcase == 'desc'
  end
  self.field = if options.key? :field then options[:field] else nil end
end

Instance Attribute Details

#defaultBoolean

Defines if this field order by default.

Returns:

  • (Boolean)

    Defines if this field order by default



19
# File 'app/controllers/anoubis/etc/field_order.rb', line 19

class_attribute :default, default: false

#fieldString, ...

Returns order field (or array of fields)

Returns:

  • (String, Array, Symbol)

    field or field list.



9
# File 'app/controllers/anoubis/etc/field_order.rb', line 9

class_attribute :field, default: nil

#orderSymbol

Field default order.

Returns:

  • (Symbol)

    default order



14
# File 'app/controllers/anoubis/etc/field_order.rb', line 14

class_attribute :order, default: :asc

Instance Method Details

#to_hHash

Generates hash representation of all class parameters,

Returns:

  • (Hash)

    hash representation of all data



42
43
44
45
46
47
48
# File 'app/controllers/anoubis/etc/field_order.rb', line 42

def to_h
  {
      field: self.field,
      order: self.order,
      default: self.default
  }
end