Module: Shift::Transformable
- Included in:
- String
- Defined in:
- lib/shift/string.rb
Overview
Mixin for things that should be transformable by Shift. Classes using the mixin should implement two methods:
#datathe data to be processed#namethe file or extension name of the data
This is needed for the mappings to work, even if the type is not a string, and/or is not persisted to disk. In this respect, the name is actually the name of the type.
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #path, #format)
Returns the value of attribute name.
Instance Method Summary collapse
- #can?(*args) ⇒ Boolean
-
#interface(action = :default, name_override = nil) ⇒ Shift::Interface
Get the default interface class for this transformable.
- #method_missing(*args) ⇒ Object
-
#process(action = :default, name_override = nil) ⇒ Shift::String
Process the string with one of the Shift interfaces.
- #respond_to?(method) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
64 65 66 |
# File 'lib/shift/string.rb', line 64 def method_missing(*args) can?(*args) ? process(*args) : super end |
Instance Attribute Details
#name ⇒ Object Also known as: path, format
Returns the value of attribute name.
18 19 20 |
# File 'lib/shift/string.rb', line 18 def name @name end |
Instance Method Details
#can?(*args) ⇒ Boolean
43 44 45 46 47 48 49 50 |
# File 'lib/shift/string.rb', line 43 def can?(*args) begin interface(*args) rescue LookupError return false end true end |
#interface(action = :default, name_override = nil) ⇒ Shift::Interface
Get the default interface class for this transformable.
38 39 40 41 42 |
# File 'lib/shift/string.rb', line 38 def interface(action=:default, name_override=nil) return action if action.is_a?(Shift::Interface) iface = Shift[name_override || name, action] || name_error iface.new end |
#process(action = :default, name_override = nil) ⇒ Shift::String
Process the string with one of the Shift interfaces. (see Shift::String#interface)
56 57 58 59 60 61 62 |
# File 'lib/shift/string.rb', line 56 def process(action=:default, name_override=nil) iface = interface(action, name_override) self.class.new( iface.process(data), iface.rename(name_override || name) ) end |
#respond_to?(method) ⇒ Boolean
68 69 70 |
# File 'lib/shift/string.rb', line 68 def respond_to?(method) super || can?(method) end |