module Shift::Transformable

Mixin for things that should be transformable by Shift. Classes using the mixin should implement two methods:

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.

Attributes

format[RW]
format=[RW]
name[RW]
path[RW]
path=[RW]

Public Instance Methods

can?(*args) click to toggle source
# 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) click to toggle source

Get the default interface class for this transformable.

@param [Symbol] action The action to perform.

Sample: `:compress`

@param [String] name_override Use the specified file name or

extension rather than `#name`

@return [Shift::Interface] The preferred available default

interface

@raise [UnknownFormatError] when a type is needed but cannot

be determined.

@raise [UnknownActionError] when no such action exists. @raise [DependencyError] when required interfaces are

not available.
# 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
method_missing(*args) click to toggle source
Calls superclass method
# File lib/shift/string.rb, line 64
def method_missing(*args)
  can?(*args) ? process(*args) : super
end
process(action=:default, name_override=nil) click to toggle source

Process the string with one of the Shift interfaces. @return [Shift::String] transformed Shift string. (see Shift::String#interface)

# 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) click to toggle source
Calls superclass method
# File lib/shift/string.rb, line 68
def respond_to?(method)
  super || can?(method)
end

Private Instance Methods

name_error() click to toggle source
# File lib/shift/string.rb, line 74
def name_error
  raise(UnknownFormatError, 'cannot determine format without clues.')
end