Class: Anoubis::Etc::FieldOptions
- Inherits:
-
Object
- Object
- Anoubis::Etc::FieldOptions
- Defined in:
- app/controllers/anoubis/etc/field_options.rb
Overview
Definitions of fields options list for ‘checkbox’ and ‘listbox’ type.
Instance Attribute Summary collapse
-
#enum ⇒ Hash<Symbol, Sring>
Enum list from ActiveRecord.
-
#line ⇒ Hash
Defines selected line.
-
#list ⇒ Hash<Symbol, Sring>
Options list.
-
#model ⇒ Model
Defines model’s description for complex field.
-
#show ⇒ String
Describes when options shown in output for ‘edit’ and ‘new’ actions.
Instance Method Summary collapse
-
#generate_list ⇒ Object
Generate options list based on model.
-
#initialize(options = {}) ⇒ FieldOptions
constructor
Sets default parameters for field options.
-
#to_h ⇒ Hash
Generates hash representation of all class parameters,.
Constructor Details
#initialize(options = {}) ⇒ FieldOptions
Sets default parameters for field options
47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 47 def initialize( = {}) if .key? :show self.show = [:show] if %w[init never always update].include? [:show] end self.show = 'init' if !self.show || self.show == 'init' self.line = if .key? :line then [:line] else nil end self.list = if .key? :list then [:list] else nil end self.enum = if .key? :enum then [:enum] else nil end self.model = if .key? :model then Model.new([:model]) else nil end self.generate_list if !self.list && self.model end |
Instance Attribute Details
#enum ⇒ Hash<Symbol, Sring>
Enum list from ActiveRecord. Is defined for correct filtering.
23 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 23 class_attribute :enum, default: nil |
#line ⇒ Hash
Defines selected line. Default nil
28 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 28 class_attribute :line, default: nil |
#list ⇒ Hash<Symbol, Sring>
Options list.
18 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 18 class_attribute :list, default: nil |
#model ⇒ Model
Defines model’s description for complex field
Options:
-
:model (ActiveRecord) – model class
-
:title (Symbol) – field name is used for receive options titles (defaults to: :title)
-
:order (Symbol) – field name is used for order options (defaults to: :title option)
-
:select (Symbol) – special select statement (defaults to: nil)
-
:where (Hash) – where parameters for select data from model (defaults to: {})
40 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 40 class_attribute :model, default: nil |
#show ⇒ String
Describes when options shown in output for ‘edit’ and ‘new’ actions. Possible values of fields are:
-
‘init’ – Options shown only when time set to 0 in action
-
‘never’ – Options newer shown
-
‘always’ – Options always shown
-
‘update’ – Options shown when time less then updated_at time of options model
13 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 13 class_attribute :show, default: 'init' |
Instance Method Details
#generate_list ⇒ Object
Generate options list based on model
61 62 63 64 65 66 67 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 61 def generate_list self.list = {} self.model.model.where(self.model.where).order(self.model.order).each do |data| proc = format('%s', self.model.title) self.list[data.id.to_s.to_sym] = data.send proc end end |
#to_h ⇒ Hash
Generates hash representation of all class parameters,
72 73 74 75 76 77 78 |
# File 'app/controllers/anoubis/etc/field_options.rb', line 72 def to_h { show: self.show, enum: self.enum, list: self.list } end |