Class: Necromancer::ConversionTarget Private
- Inherits:
-
Object
- Object
- Necromancer::ConversionTarget
- Defined in:
- lib/necromancer/conversion_target.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A class responsible for wrapping conversion target
Constant Summary collapse
- UndefinedValue =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Used as a stand in for lack of value
Module.new
Class Method Summary collapse
Instance Method Summary collapse
-
#from(source) ⇒ ConversionType
Allows to specify conversion source type.
-
#initialize(conversions, object) ⇒ ConversionTarget
constructor
private
A new instance of ConversionTarget.
-
#inspect ⇒ Object
Inspect this conversion.
-
#to(target, options = {}) ⇒ Object
(also: #>>)
Runs a given conversion.
Constructor Details
#initialize(conversions, object) ⇒ ConversionTarget
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.
Returns a new instance of ConversionTarget.
13 14 15 16 |
# File 'lib/necromancer/conversion_target.rb', line 13 def initialize(conversions, object) @object = object @conversions = conversions end |
Class Method Details
.for(context, value, block) ⇒ Object
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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/necromancer/conversion_target.rb', line 19 def self.for(context, value, block) if UndefinedValue.equal?(value) unless block raise ArgumentError, "You need to pass either argument or a block to `convert`." end new(context, block.call) elsif block raise ArgumentError, "You cannot pass both an argument and a block to `convert`." else new(context, value) end end |
Instance Method Details
#from(source) ⇒ ConversionType
Allows to specify conversion source type
42 43 44 45 |
# File 'lib/necromancer/conversion_target.rb', line 42 def from(source) @source = source self end |
#inspect ⇒ Object
Inspect this conversion
68 69 70 |
# File 'lib/necromancer/conversion_target.rb', line 68 def inspect %(#<#{self.class}@#{object_id} @object=#{object}, @source=#{detect(object)}>) end |
#to(target, options = {}) ⇒ Object Also known as: >>
Runs a given conversion
59 60 61 62 |
# File 'lib/necromancer/conversion_target.rb', line 59 def to(target, = {}) conversion = conversions[source || detect(object, false), detect(target)] conversion.call(object, **) end |