Skip to content

Instantly share code, notes, and snippets.

@leoallen85
Created May 27, 2015 22:17
Show Gist options
  • Select an option

  • Save leoallen85/f8f7767eaf21f724bd18 to your computer and use it in GitHub Desktop.

Select an option

Save leoallen85/f8f7767eaf21f724bd18 to your computer and use it in GitHub Desktop.
require './lib/query'
require 'delegate'
module Mappable
extend Forwardable
attr_reader :attributes
delegate find: 'self.class'
def initialize(attributes)
@attributes = attributes.to_h
end
# Delegate to attributes to allow for easy access to underlying data
def method_missing(method, *arguments, &block)
attributes[method] || super
end
def respond_to_missing?(method, include_private = false)
attributes[method] || super
end
def ==(compare)
self.class == compare.class && attributes == compare.attributes
end
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def find(query, args)
Query.run(query, args)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment