Created
May 27, 2015 22:17
-
-
Save leoallen85/f8f7767eaf21f724bd18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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