Sha256: 93cbbca969f2b55347276af596fc9c53ab81d02fcff2619d58568110a38e75aa

Contents?: true

Size: 596 Bytes

Versions: 9

Compression:

Stored size: 596 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, self, *args)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
resource_kit-0.1.8 lib/resource_kit/method_factory.rb
resource_kit-0.1.7 lib/resource_kit/method_factory.rb
resource_kit-0.1.6 lib/resource_kit/method_factory.rb
resource_kit-0.1.5 lib/resource_kit/method_factory.rb
resource_kit-0.1.4 lib/resource_kit/method_factory.rb
resource_kit-0.1.3 lib/resource_kit/method_factory.rb
resource_kit-0.1.2 lib/resource_kit/method_factory.rb
resource_kit-0.1.1 lib/resource_kit/method_factory.rb
resource_kit-0.1.0 lib/resource_kit/method_factory.rb