Sha256: 3964328d7e41c4ff8b1b43f4b0e2ebefd9a3260dc5ae5405e95815e53eca24cd

Contents?: true

Size: 780 Bytes

Versions: 4

Compression:

Stored size: 780 Bytes

Contents

module Koine
  module Hydrator
    class Hydrator
      def hydrate(data, object)
        data.each do |key, value|
          method = "#{key}="
          object.send(method, value) if object.respond_to?(method)
        end
      end

      def extract(object)
        data = {}

        entity_methods(object).each do |method|
          if object.method(method).arity == 0
            data[method] = object.send(method)
          end
        end

        data
      end

      private

      # disconsiders methods that are inherited from Object class
      def entity_methods(object)
        reject_methods = Object.public_instance_methods

        object.public_methods(true).reject do |method|
          reject_methods.include?(method)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
koine-repository-1.1.1 lib/koine/hydrator/hydrator.rb
koine-repository-1.1 lib/koine/hydrator/hydrator.rb
koine-repository-1.0 lib/koine/hydrator/hydrator.rb
koine-repository-0.9.0 lib/koine/hydrator/hydrator.rb