Module: Serega::SeregaConfig::SeregaConfigInstanceMethods
- Included in:
- Serega::SeregaConfig
- Defined in:
- lib/serega/config.rb
Overview
SeregaConfig Instance methods
Instance Attribute Summary collapse
-
#opts ⇒ Hash
readonly
Shows current config as Hash.
Instance Method Summary collapse
-
#attribute_keys ⇒ Array<Symbol>
Returns options names allowed in
Serega.attributemethod. -
#auto_preload ⇒ Hash
Auto_preload option.
-
#auto_preload=(value) ⇒ Hash
Validates and sets auto_preload option.
-
#auto_preload_excluded_methods ⇒ Array<Symbol>
Returns :auto_preload_excluded_methods config option — methods that are never auto-preloaded, as they return the serialized object itself and not an association.
-
#auto_preload_excluded_methods=(value) ⇒ Array<Symbol>
Sets :auto_preload_excluded_methods config option — methods that are never auto-preloaded.
-
#base_serializer ⇒ Class?
Returns :base_serializer config option — the parent class for nested serializers defined with attribute blocks.
-
#base_serializer=(value) ⇒ Class
Sets :base_serializer config option — the parent class for nested serializers defined with attribute blocks.
-
#batch_id_option ⇒ Object
Returns current batch_id_option.
-
#batch_id_option=(value) ⇒ Symbol
Sets :batch_id_option config option.
-
#check_attribute_name ⇒ Object
Returns whether attributes names check is disabled.
-
#check_attribute_name=(value) ⇒ Boolean
Sets :check_attribute_name config option.
-
#check_initiate_params ⇒ Boolean
Returns :check_initiate_params config option.
-
#check_initiate_params=(value) ⇒ Boolean
Sets :check_initiate_params config option.
-
#delegate_default_allow_nil ⇒ Boolean
Returns :delegate_default_allow_nil config option.
-
#delegate_default_allow_nil=(value) ⇒ Boolean
Sets :delegate_default_allow_nil config option.
-
#hash_access ⇒ Serega::SeregaConfig::HashAccessConfig
Returns the hash_access config object.
-
#hide_by_default ⇒ Boolean, Symbol
Returns :hide_by_default config option.
-
#hide_by_default=(value) ⇒ Boolean, Symbol
Sets :hide_by_default config option.
-
#initialize(opts = nil) ⇒ Object
Initializes new config instance.
-
#initiate_keys ⇒ Array<Symbol>
Returns options names allowed in
Serega#newmethod. -
#max_cached_plans_per_serializer_count ⇒ Boolean
Returns :max_cached_plans_per_serializer_count config option.
-
#max_cached_plans_per_serializer_count=(value) ⇒ Boolean
Sets :max_cached_plans_per_serializer_count config option.
-
#plugins ⇒ Array
Shows used plugins.
-
#serialize_keys ⇒ Array<Symbol>
Returns options names allowed in
call, to_hmethods.
Instance Attribute Details
#opts ⇒ Hash (readonly)
Shows current config as Hash
51 52 53 |
# File 'lib/serega/config.rb', line 51 def opts @opts end |
Instance Method Details
#attribute_keys ⇒ Array<Symbol>
Returns options names allowed in Serega.attribute method
80 81 82 |
# File 'lib/serega/config.rb', line 80 def attribute_keys opts.fetch(:attribute_keys) end |
#auto_preload ⇒ Hash
Returns auto_preload option.
191 192 193 |
# File 'lib/serega/config.rb', line 191 def auto_preload opts.fetch(:auto_preload) end |
#auto_preload=(value) ⇒ Hash
Validates and sets auto_preload option
197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/serega/config.rb', line 197 def auto_preload=(value) opts[:auto_preload] = case value when true then {has_delegate_option: true, has_serializer_option: true} when false then {has_delegate_option: false, has_serializer_option: false} when Hash SeregaValidations::Utils::CheckAllowedKeys.call(value, %i[has_delegate_option has_serializer_option], "auto_preload") {has_delegate_option: !!value[:has_delegate_option], has_serializer_option: !!value[:has_serializer_option]} else raise SeregaError, "Must have boolean value or Hash, #{value.inspect} provided" end end |
#auto_preload_excluded_methods ⇒ Array<Symbol>
Returns :auto_preload_excluded_methods config option — methods that are never auto-preloaded, as they return the serialized object itself and not an association
126 127 128 |
# File 'lib/serega/config.rb', line 126 def auto_preload_excluded_methods opts.fetch(:auto_preload_excluded_methods) end |
#auto_preload_excluded_methods=(value) ⇒ Array<Symbol>
Sets :auto_preload_excluded_methods config option — methods that are
never auto-preloaded. Applies to the :method option of attributes
with a serializer and to the delegate: {to: ...} option.
137 138 139 140 141 142 143 |
# File 'lib/serega/config.rb', line 137 def auto_preload_excluded_methods=(value) unless value.is_a?(Array) && value.all?(Symbol) raise SeregaError, "Must be an Array of Symbols, #{value.inspect} provided" end opts[:auto_preload_excluded_methods] = value end |
#base_serializer ⇒ Class?
Returns :base_serializer config option — the parent class for nested serializers defined with attribute blocks
148 149 150 |
# File 'lib/serega/config.rb', line 148 def base_serializer opts.fetch(:base_serializer) end |
#base_serializer=(value) ⇒ Class
Sets :base_serializer config option — the parent class for nested
serializers defined with attribute blocks. Usually a settings-only
serializer, e.g. config.base_serializer = self in an application
base serializer class.
160 161 162 163 164 |
# File 'lib/serega/config.rb', line 160 def base_serializer=(value) raise SeregaError, "Must be a Serega subclass, #{value.inspect} provided" if !value.is_a?(Class) || !(value <= Serega) opts[:base_serializer] = value end |
#batch_id_option ⇒ Object
Returns current batch_id_option
248 249 250 |
# File 'lib/serega/config.rb', line 248 def batch_id_option opts.fetch(:batch_id_option) end |
#batch_id_option=(value) ⇒ Symbol
Sets :batch_id_option config option
257 258 259 260 |
# File 'lib/serega/config.rb', line 257 def batch_id_option=(value) raise SeregaError, "Must have Symbol value, #{value.inspect} provided" unless value.is_a?(Symbol) opts[:batch_id_option] = value end |
#check_attribute_name ⇒ Object
Returns whether attributes names check is disabled
233 234 235 |
# File 'lib/serega/config.rb', line 233 def check_attribute_name opts.fetch(:check_attribute_name) end |
#check_attribute_name=(value) ⇒ Boolean
Sets :check_attribute_name config option
242 243 244 245 |
# File 'lib/serega/config.rb', line 242 def check_attribute_name=(value) raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false) opts[:check_attribute_name] = value end |
#check_initiate_params ⇒ Boolean
Returns :check_initiate_params config option
92 93 94 |
# File 'lib/serega/config.rb', line 92 def check_initiate_params opts.fetch(:check_initiate_params) end |
#check_initiate_params=(value) ⇒ Boolean
Sets :check_initiate_params config option
101 102 103 104 |
# File 'lib/serega/config.rb', line 101 def check_initiate_params=(value) raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false) opts[:check_initiate_params] = value end |
#delegate_default_allow_nil ⇒ Boolean
Returns :delegate_default_allow_nil config option
108 109 110 |
# File 'lib/serega/config.rb', line 108 def delegate_default_allow_nil opts.fetch(:delegate_default_allow_nil) end |
#delegate_default_allow_nil=(value) ⇒ Boolean
Sets :delegate_default_allow_nil config option
117 118 119 120 |
# File 'lib/serega/config.rb', line 117 def delegate_default_allow_nil=(value) raise SeregaError, "Must have boolean value, #{value.inspect} provided" if (value != true) && (value != false) opts[:delegate_default_allow_nil] = value end |
#hash_access ⇒ Serega::SeregaConfig::HashAccessConfig
Returns the hash_access config object
212 213 214 |
# File 'lib/serega/config.rb', line 212 def hash_access @hash_access ||= HashAccessConfig.new(opts.fetch(:hash_access)) end |
#hide_by_default ⇒ Boolean, Symbol
Returns :hide_by_default config option
168 169 170 |
# File 'lib/serega/config.rb', line 168 def hide_by_default opts.fetch(:hide_by_default) end |
#hide_by_default=(value) ⇒ Boolean, Symbol
Sets :hide_by_default config option
180 181 182 183 184 185 186 187 188 |
# File 'lib/serega/config.rb', line 180 def hide_by_default=(value) opts[:hide_by_default] = case value when true, false, :auto value else raise SeregaError, "Must have true, false, or :auto, #{value.inspect} provided" end end |
#initialize(opts = nil) ⇒ Object
Initializes new config instance.
58 59 60 61 |
# File 'lib/serega/config.rb', line 58 def initialize(opts = nil) opts ||= DEFAULTS @opts = SeregaUtils::EnumDeepDup.call(opts) end |
#initiate_keys ⇒ Array<Symbol>
Returns options names allowed in Serega#new method
74 75 76 |
# File 'lib/serega/config.rb', line 74 def initiate_keys opts.fetch(:initiate_keys) end |
#max_cached_plans_per_serializer_count ⇒ Boolean
Returns :max_cached_plans_per_serializer_count config option
218 219 220 |
# File 'lib/serega/config.rb', line 218 def max_cached_plans_per_serializer_count opts.fetch(:max_cached_plans_per_serializer_count) end |
#max_cached_plans_per_serializer_count=(value) ⇒ Boolean
Sets :max_cached_plans_per_serializer_count config option
227 228 229 230 |
# File 'lib/serega/config.rb', line 227 def max_cached_plans_per_serializer_count=(value) raise SeregaError, "Must have Integer value, #{value.inspect} provided" unless value.is_a?(Integer) opts[:max_cached_plans_per_serializer_count] = value end |
#plugins ⇒ Array
Shows used plugins
68 69 70 |
# File 'lib/serega/config.rb', line 68 def plugins opts.fetch(:plugins) end |
#serialize_keys ⇒ Array<Symbol>
Returns options names allowed in call, to_h methods
86 87 88 |
# File 'lib/serega/config.rb', line 86 def serialize_keys opts.fetch(:serialize_keys) end |