Sha256: 3476c5a4dc2d7a07f4a43059d0c4fcbc21375ba1c7812bb9e5563cfe1ba7a5bf

Contents?: true

Size: 671 Bytes

Versions: 2

Compression:

Stored size: 671 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

  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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rest-in-peace-1.1.0 lib/rest_in_peace.rb
rest-in-peace-1.0.0 lib/rest_in_peace.rb