Sha256: 873536df9e1404059ffeead14d1ef4ac5c2f94d28523011e10bc6dde212cca3a

Contents?: true

Size: 857 Bytes

Versions: 1

Compression:

Stored size: 857 Bytes

Contents

require 'rest_in_peace/definition_proxy'

module RESTinPeace

  def self.included(base)
    base.send :extend, ClassMethods
  end

  def api
    self.class.api
  end

  def initialize(attributes = {})
    update_from_hash(attributes)
  end

  def to_h
    Hash[each_pair.to_a]
  end

  def update_attributes(attributes)
    update_from_hash(attributes)
  end

  protected

  def update_from_hash(hash)
    hash.each do |key, value|
      next unless self.class.members.map(&:to_s).include?(key.to_s)
      send("#{key}=", value)
    end
  end

  module ClassMethods
    attr_accessor :api

    def rest_in_peace(&block)
      definition_proxy = RESTinPeace::DefinitionProxy.new(self)
      definition_proxy.instance_eval(&block)
    end

    def rip_registry
      @rip_registry ||= {
        resource: [],
        collection: [],
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rest-in-peace-1.4.0 lib/rest_in_peace.rb