Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Add Comment
Please, Sign In to add comment