Guest User

Untitled

a guest
Jul 16th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. module Decorators
  2.  
  3. class Base < BasicObject
  4. # perhaps make this include ActiveModel and behave like the underlying ActiveRecord
  5.  
  6. attr_reader :decorated
  7.  
  8. def initialize(decorated)
  9. @decorated = decorated
  10. end
  11.  
  12. def method_missing(method, *args)
  13. args.empty? ? decorated.send(method) : decorated.send(method, args)
  14. end
  15. end
  16.  
  17. module Api
  18.  
  19. class User < Decorators::Base
  20. def attributes=(attrs)
  21. # filter out disallowed attributes
  22. end
  23.  
  24. def as_json
  25. { :id => decorated.id }
  26. end
  27. end
  28.  
  29. end
  30.  
  31.  
  32. end
  33.  
  34. user = User.find(123)
  35. @user = Decorators::Api::User.new(user)
Add Comment
Please, Sign In to add comment