Sha256: 769a9b0d2e7484aaf6abe4b899369ca878a9a20304d23a094a53951ecfdad4bd

Contents?: true

Size: 602 Bytes

Versions: 3

Compression:

Stored size: 602 Bytes

Contents

module ResourceKit
  class MethodFactory
    def self.construct(object, resource_collection, invoker = ActionInvoker)
      resource_collection.each do |action|
        if object.method_defined?(action.name)
          raise ArgumentError, "Action '#{action.name}' is already defined on `#{object}`"
        end
        method_block = method_for_action(action, invoker)

        object.send(:define_method, action.name, &method_block)
      end
    end

    def self.method_for_action(action, invoker)
      Proc.new do |*args|
        invoker.call(action, connection, *args)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
resource_kit-0.0.5 lib/resource_kit/method_factory.rb
resource_kit-0.0.3 lib/resource_kit/method_factory.rb
resource_kit-0.0.1 lib/resource_kit/method_factory.rb