Created
December 3, 2010 01:14
-
-
Save steveh/726420 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
| module Decorators | |
| class Base < BasicObject | |
| # perhaps make this include ActiveModel and behave like the underlying ActiveRecord | |
| attr_reader :decorated | |
| def initialize(decorated) | |
| @decorated = decorated | |
| end | |
| def method_missing(method, *args) | |
| args.empty? ? decorated.send(method) : decorated.send(method, args) | |
| end | |
| end | |
| module Api | |
| class User < Decorators::Base | |
| def attributes=(attrs) | |
| # filter out disallowed attributes | |
| end | |
| def as_json | |
| { :id => decorated.id } | |
| end | |
| end | |
| end | |
| end | |
| user = User.find(123) | |
| @user = Decorators::Api::User.new(user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment