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.attribute` method.
-
#auto_hide ⇒ Hash
Auto_hide option.
-
#auto_hide=(value) ⇒ Hash
Validates and sets auto_hide option.
-
#auto_preload ⇒ Hash
Auto_preload option.
-
#auto_preload=(value) ⇒ Hash
Validates and sets auto_preload 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.
-
#from_json ⇒ #call
Returns current ‘from_json` adapter.
-
#from_json=(value) ⇒ #call
Sets current ‘from_json` adapter.
-
#initialize(opts = nil) ⇒ Object
Initializes new config instance.
-
#initiate_keys ⇒ Array<Symbol>
Returns options names allowed in ‘Serega#new` method.
-
#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 ‘to_h, to_json, as_json` methods.
-
#to_json ⇒ #call
Returns current ‘to_json` adapter.
-
#to_json=(value) ⇒ #call
Sets current ‘to_json` adapter.
Instance Attribute Details
#opts ⇒ Hash (readonly)
Shows current config as Hash
52 53 54 |
# File 'lib/serega/config.rb', line 52 def opts @opts end |
Instance Method Details
#attribute_keys ⇒ Array<Symbol>
Returns options names allowed in ‘Serega.attribute` method
81 82 83 |
# File 'lib/serega/config.rb', line 81 def attribute_keys opts.fetch(:attribute_keys) end |
#auto_hide ⇒ Hash
Returns auto_hide option.
124 125 126 |
# File 'lib/serega/config.rb', line 124 def auto_hide opts.fetch(:auto_hide) end |
#auto_hide=(value) ⇒ Hash
Validates and sets auto_hide option
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/serega/config.rb', line 130 def auto_hide=(value) opts[:auto_hide] = case value when true then {has_preload_option: true, has_batch_option: true} when false then {has_preload_option: false, has_batch_option: false} when Hash SeregaValidations::Utils::CheckAllowedKeys.call(value, %i[has_preload_option has_batch_option], "auto_hide") {has_preload_option: !!value[:has_preload_option], has_batch_option: !!value[:has_batch_option]} else raise SeregaError, "Must have boolean value or Hash, #{value.inspect} provided" end end |
#auto_preload ⇒ Hash
Returns auto_preload option.
144 145 146 |
# File 'lib/serega/config.rb', line 144 def auto_preload opts.fetch(:auto_preload) end |
#auto_preload=(value) ⇒ Hash
Validates and sets auto_preload option
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/serega/config.rb', line 150 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 |
#check_attribute_name ⇒ Object
Returns whether attributes names check is disabled
180 181 182 |
# File 'lib/serega/config.rb', line 180 def check_attribute_name opts.fetch(:check_attribute_name) end |
#check_attribute_name=(value) ⇒ Boolean
Sets :check_attribute_name config option
189 190 191 192 |
# File 'lib/serega/config.rb', line 189 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
93 94 95 |
# File 'lib/serega/config.rb', line 93 def check_initiate_params opts.fetch(:check_initiate_params) end |
#check_initiate_params=(value) ⇒ Boolean
Sets :check_initiate_params config option
102 103 104 105 |
# File 'lib/serega/config.rb', line 102 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
109 110 111 |
# File 'lib/serega/config.rb', line 109 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
118 119 120 121 |
# File 'lib/serega/config.rb', line 118 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 |
#from_json ⇒ #call
Returns current ‘from_json` adapter
209 210 211 |
# File 'lib/serega/config.rb', line 209 def from_json opts.fetch(:from_json) end |
#from_json=(value) ⇒ #call
Sets current ‘from_json` adapter
216 217 218 |
# File 'lib/serega/config.rb', line 216 def from_json=(value) opts[:from_json] = value end |
#initialize(opts = nil) ⇒ Object
Initializes new config instance.
59 60 61 62 |
# File 'lib/serega/config.rb', line 59 def initialize(opts = nil) opts ||= DEFAULTS @opts = SeregaUtils::EnumDeepDup.call(opts) end |
#initiate_keys ⇒ Array<Symbol>
Returns options names allowed in ‘Serega#new` method
75 76 77 |
# File 'lib/serega/config.rb', line 75 def initiate_keys opts.fetch(:initiate_keys) end |
#max_cached_plans_per_serializer_count ⇒ Boolean
Returns :max_cached_plans_per_serializer_count config option
165 166 167 |
# File 'lib/serega/config.rb', line 165 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
174 175 176 177 |
# File 'lib/serega/config.rb', line 174 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
69 70 71 |
# File 'lib/serega/config.rb', line 69 def plugins opts.fetch(:plugins) end |
#serialize_keys ⇒ Array<Symbol>
Returns options names allowed in ‘to_h, to_json, as_json` methods
87 88 89 |
# File 'lib/serega/config.rb', line 87 def serialize_keys opts.fetch(:serialize_keys) end |
#to_json ⇒ #call
Returns current ‘to_json` adapter
196 197 198 |
# File 'lib/serega/config.rb', line 196 def to_json opts.fetch(:to_json) end |
#to_json=(value) ⇒ #call
Sets current ‘to_json` adapter
203 204 205 |
# File 'lib/serega/config.rb', line 203 def to_json=(value) opts[:to_json] = value end |