Class: Anoubis::Etc::Model

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

Overview

Definitions of model options. Class is used for define attached model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Model

Sets default parameters for field

Parameters:

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

    initial model options

Options Hash (options):

  • :model (ActiveRecord)

    model class

  • :title (Symbol)

    field name is used for receive options titles

  • :order (Symbol)

    field name is used for order options

  • :where (Hash)

    where parameters for select data from model



44
45
46
47
48
49
50
51
# File 'app/controllers/anoubis/etc/model.rb', line 44

def initialize(options = {})
  self.model = options[:model]
  self.title = if options.key? :title then options[:title] else :title end
  self.order = if options.key? :order then options[:order] else self.title end
  self.where = if options.key? :where then options[:where] else {} end
  self.select = if options.key? :select then options[:select] else nil end
  self.updated_at = 0
end

Instance Attribute Details

#modelActiveRecord

Defines model class. This field is required.

Returns:

  • (ActiveRecord)

    model’s class.



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

class_attribute :model, default: nil

#orderBoolean

Field name is used for defines order field when data selected from model. By default uses field daefined as (#title)

Returns:

  • (Boolean)

    field’s name



20
# File 'app/controllers/anoubis/etc/model.rb', line 20

class_attribute :order, default: :title

#selectString

Special select parameters.

Returns:

  • (String)

    string of special select or nil



30
# File 'app/controllers/anoubis/etc/model.rb', line 30

class_attribute :select, default: nil

#titleSymbol

Field name is used for defines title when data selected from model.

Returns:

  • (Symbol)

    field’s name



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

class_attribute :title, default: :title

#updated_atNumber

Timestamp of last changes in the model.

Returns:

  • (Number)

    timestamp of last changes in model.



35
# File 'app/controllers/anoubis/etc/model.rb', line 35

class_attribute :updated_at, default: {}

#whereHash

Where parameters are used when data selected from model.

Returns:

  • (Hash)

    hash of where’s parameters



25
# File 'app/controllers/anoubis/etc/model.rb', line 25

class_attribute :where, default: {}

Instance Method Details

#to_hHash

Generates hash representation of all class parameters,

Returns:

  • (Hash)

    hash representation of all data



56
57
58
59
60
61
62
63
64
# File 'app/controllers/anoubis/etc/model.rb', line 56

def to_h
  {
      model: self.model,
      title: self.title,
      order: self.order,
      where: self.where,
      updated_at: self.updated_at
  }
end