Class: Adamantium::Freezer
- Inherits:
-
Object
- Object
- Adamantium::Freezer
- Defined in:
- lib/adamantium/freezer.rb
Overview
Abstract base class for freezers
TODO: Use dkubb/abstract_class?
Better pattern for singleton inheritance/shared code
Defined Under Namespace
Classes: Deep, Flat, OptionError, UnknownFreezerError
Constant Summary collapse
- Noop =
->(object) { object }.freeze
Class Method Summary collapse
-
.call(object) ⇒ Object
Attempt to freeze an object.
-
.get(name) ⇒ #call
private
Return freezer for name.
-
.parse(options) ⇒ #call?
private
Parse freezer options.
Class Method Details
.call(object) ⇒ Object
Attempt to freeze an object
29 30 31 32 33 34 35 36 |
# File 'lib/adamantium/freezer.rb', line 29 def self.call(object) case object when Numeric, TrueClass, FalseClass, NilClass, Symbol, Class, Module, UnboundMethod, Method object else freeze_value(object) end end |
.get(name) ⇒ #call
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return freezer for name
111 112 113 114 115 |
# File 'lib/adamantium/freezer.rb', line 111 def self.get(name) @freezers.fetch(name) do fail UnknownFreezerError, "Freezer with name #{name.inspect} is unknown" end end |
.parse(options) ⇒ #call?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse freezer options
130 131 132 133 134 135 136 |
# File 'lib/adamantium/freezer.rb', line 130 def self.parse() keys = .keys - [:freezer] unless keys.empty? fail OptionError, "Unknown option key(s) for memoizer #{keys.inspect}" end get(.fetch(:freezer)) if .key?(:freezer) end |