Module: Showroom::Core::Configurable
- Included in:
- Showroom, Showroom::Client
- Defined in:
- lib/showroom/core/configurable.rb
Overview
Mixin that provides configuration DSL for the Showroom module and Client.
When extended into a module or class it adds ‘configure`, `reset!`, `options`, and `same_options?`, plus individual key accessors.
Constant Summary collapse
- KEYS =
Ordered list of all supported configuration keys.
%i[ store user_agent per_page pagination_depth open_timeout timeout middleware connection_options debug ].freeze
Instance Method Summary collapse
-
#configure {|self| ... } ⇒ self
Yields self for block-style configuration.
-
#options ⇒ Hash{Symbol => Object}
Returns a frozen hash snapshot of the current configuration.
-
#per_page=(value) ⇒ void
Clamps per_page so it never exceeds Default::MAX_PER_PAGE.
-
#reset! ⇒ void
Resets all keys to their defaults from Default.
-
#same_options?(other_options) ⇒ Boolean
Returns true when
other_optionsmatches the current configuration. - #store ⇒ String?
- #store=(value) ⇒ Object
Instance Method Details
#configure {|self| ... } ⇒ self
Yields self for block-style configuration.
41 42 43 44 |
# File 'lib/showroom/core/configurable.rb', line 41 def configure yield self self end |
#options ⇒ Hash{Symbol => Object}
Returns a frozen hash snapshot of the current configuration.
56 57 58 |
# File 'lib/showroom/core/configurable.rb', line 56 def KEYS.to_h { |key| [key, send(key)] }.freeze end |
#per_page=(value) ⇒ void
This method returns an undefined value.
Clamps per_page so it never exceeds Default::MAX_PER_PAGE.
72 73 74 |
# File 'lib/showroom/core/configurable.rb', line 72 def per_page=(value) @per_page = [value.to_i, Default::MAX_PER_PAGE].min end |
#reset! ⇒ void
This method returns an undefined value.
Resets all keys to their defaults from Default.
49 50 51 |
# File 'lib/showroom/core/configurable.rb', line 49 def reset! KEYS.each { |key| send(:"#{key}=", Default.public_send(key)) } end |
#same_options?(other_options) ⇒ Boolean
Returns true when other_options matches the current configuration.
64 65 66 |
# File 'lib/showroom/core/configurable.rb', line 64 def () == end |
#store ⇒ String?
35 |
# File 'lib/showroom/core/configurable.rb', line 35 KEYS.each { |key| attr_accessor key } |
#store=(value) ⇒ Object
35 |
# File 'lib/showroom/core/configurable.rb', line 35 KEYS.each { |key| attr_accessor key } |