class Mongoid::Orderable::Configs::FieldConfig
Constants
- ALIASES
- CONFIG_OPTIONS
- FIELD_OPTIONS
- VALID_OPTIONS
Attributes
options[R]
orderable_class[R]
Public Class Methods
new(parent, options = {})
click to toggle source
# File lib/mongoid/orderable/configs/field_config.rb, line 26 def initialize(parent, options = {}) @orderable_class = parent assign_options(options) set_field_options set_orderable_scope end
Public Instance Methods
global_config()
click to toggle source
# File lib/mongoid/orderable/configs/field_config.rb, line 33 def global_config cfg = Mongoid::Orderable.config { field: cfg.field, as: cfg.as, index: cfg.index, base: cfg.base, use_transactions: cfg.use_transactions, transaction_max_retries: cfg.transaction_max_retries, lock_collection: cfg.lock_collection } end
Protected Instance Methods
assign_options(options)
click to toggle source
# File lib/mongoid/orderable/configs/field_config.rb, line 46 def assign_options(options) @options = global_config return unless options.is_a?(Hash) @options = @options.merge(options.symbolize_keys.transform_keys {|k| ALIASES[k] || k }).slice(*VALID_OPTIONS) end
set_field_options()
click to toggle source
# File lib/mongoid/orderable/configs/field_config.rb, line 52 def set_field_options @options[:field_options] = {} FIELD_OPTIONS.each do |key| next unless @options.key?(key) @options[:field_options][key] = @options.delete(key) end end
set_orderable_scope()
click to toggle source
# File lib/mongoid/orderable/configs/field_config.rb, line 60 def set_orderable_scope return unless @options[:scope].class.in?([Array, Symbol, String]) scope = Array(@options[:scope]) scope.map! do |value| case value when Symbol relation = @orderable_class.relations[@options[:scope].to_s]&.key&.to_sym relation || value when String value.to_sym else raise ArgumentError.new("Orderable :scope invalid: #{@options[:scope]}") end end @options[:scope] = scope end