Sha256: d3b2abac56501ab0112129cc3dc5521aa96dac1d2791e6eb1394fb67c3c30328

Contents?: true

Size: 867 Bytes

Versions: 1

Compression:

Stored size: 867 Bytes

Contents

module JYRon
  class Mediator
    attr_accessor :object
    include JYRon::Adapters
    include JYRon::Filters
    include JYRon::Outputs
    include JYRon::Inputs

    class MediatorOptionsFailure < Exception; end

    def initialize(options = {})
      @adapters = []
      if options[:adapters] then
        @adapters.push(options[:adapters]).flatten! if options[:adapters]
        options.delete(:adapters)
      end
      from = INPUTS_LIST & options.keys
      raise MediatorOptionsFailure if from.size > 2
      self.send from.first, options[from.first] if from.size == 1
      adapt unless @object.nil?
    end



    def from_obj(obj)
      @object = obj
      adapt
      return self
    end


    def to_obj
      return @object
    end


    private
    def adapt
      @adapters.each do |adapter|
        self.send adapter
      end
    end



  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jyron-0.1 lib/jyron/mediator.rb