Sha256: b3153c476adab6d5d7420dcc70ffd325beb800ccd5a66e254f08f8891e0f1d6d

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

require_relative "../skala"

class Skala::Transformation
  require_relative "./transformation/step"

  #
  # class methods
  #
  class << self
    attr_accessor :steps
  end

  # since a transformation can have many steps, writing a "require" for each is tedious
  def self.require_directory(directory)
    Dir.glob("#{File.expand_path(directory)}/*.rb").each do |filename|
      require filename
    end
  end

  # convenience wrapper for @steps setter to enhance readability
  def self.sequence(value)
    self.steps = value
  end

  #
  # instance methods
  #
  attr_accessor :source
  attr_accessor :target

  def apply(options = {})
    if (@source = options[:source] ||= options[:to]).nil?
      raise ArgumentError, "No source given to apply transformation to!"
    end

    @target = options[:target]

    self.class.steps.flatten.each do |step|
      break if @__aborted

      if step.is_a?(Class)
        step.new(self).call
      else
        step.call(self)
      end
    end

    return @target
  end

  def abort!
    @__aborted = true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
skala-0.3.0 lib/skala/transformation.rb
skala-0.2.0 lib/skala/transformation.rb