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 =
lambda { |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
103 104 105 106 107 108 109 110 111 |
# File 'lib/adamantium/freezer.rb', line 103 def self.get(name) case name when :noop then Noop when :deep then Deep when :flat then Flat else raise 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
126 127 128 129 130 131 132 |
# File 'lib/adamantium/freezer.rb', line 126 def self.parse() keys = .keys - [:freezer] unless keys.empty? raise OptionError, "Unknown option key(s) for memoizer #{keys.inspect}" end get(.fetch(:freezer)) if .key?(:freezer) end |