Class: Necromancer::Context
- Inherits:
-
Object
- Object
- Necromancer::Context
- Extended by:
- Forwardable
- Defined in:
- lib/necromancer/context.rb
Overview
A class used by Necromancer to provide user interace
Instance Method Summary collapse
-
#can?(source, target) ⇒ Boolean
Check if this converter can convert source to target.
-
#configuration ⇒ Necromancer::Configuration
The configuration object.
-
#configure {|Necromancer::Configuration| ... } ⇒ Object
Yields global configuration to a block.
-
#convert(object = ConversionTarget::UndefinedValue, &block) ⇒ Object
Converts the object.
-
#initialize(&block) ⇒ Context
constructor
private
Create a context.
-
#inspect ⇒ Object
Inspect this context.
Constructor Details
#initialize(&block) ⇒ Context
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.
Create a context.
21 22 23 24 25 |
# File 'lib/necromancer/context.rb', line 21 def initialize(&block) block.(configuration) if block_given? @conversions = Conversions.new(configuration) @conversions.load end |
Instance Method Details
#can?(source, target) ⇒ Boolean
Check if this converter can convert source to target
74 75 76 77 78 |
# File 'lib/necromancer/context.rb', line 74 def can?(source, target) !conversions[source, target].nil? rescue NoTypeConversionAvailableError false end |
#configuration ⇒ Necromancer::Configuration
The configuration object.
36 37 38 |
# File 'lib/necromancer/context.rb', line 36 def configuration @configuration ||= Configuration.new end |
#configure {|Necromancer::Configuration| ... } ⇒ Object
Yields global configuration to a block.
51 52 53 |
# File 'lib/necromancer/context.rb', line 51 def configure yield configuration if block_given? end |
#convert(object = ConversionTarget::UndefinedValue, &block) ⇒ Object
Converts the object
60 61 62 |
# File 'lib/necromancer/context.rb', line 60 def convert(object = ConversionTarget::UndefinedValue, &block) ConversionTarget.for(conversions, object, block) end |
#inspect ⇒ Object
Inspect this context
83 84 85 |
# File 'lib/necromancer/context.rb', line 83 def inspect %(#<#{self.class}@#{object_id} @config=#{configuration}>) end |