Permalink
Browse files

Use ActiveSupport::Concern over old method

  • Loading branch information...
1 parent 68be571 commit 171eec9e3e97b6337f96928c8e5e62815b198de6 Chris Harper committed Jan 30, 2012
Showing with 10 additions and 14 deletions.
  1. +9 −13 lib/only_expose.rb
  2. +1 −1 lib/only_expose/version.rb
View
@@ -1,25 +1,21 @@
+require 'active_support/concern'
module OnlyExpose
+ extend ActiveSupport::Concern
- def self.included(base)
- base.extend ClassMethods
- end
-
- #Instance Methods
-
- def to_json(options = {})
- super(options.merge(:only => self.class.exposed_attributes))
- end
+ included do
+ def to_json(options = {})
+ super(options.merge(:only => self.class.exposed_attributes))
+ end
- def to_xml(options = {})
- super(options.merge(:only => self.class.exposed_attributes))
+ def to_xml(options = {})
+ super(options.merge(:only => self.class.exposed_attributes))
+ end
end
module ClassMethods
-
def only_expose(*args)
@exposed_attributes = *args
end
-
def exposed_attributes
if @exposed_attributes.nil? && self.superclass != ActiveRecord::Base
superclass.exposed_attributes
@@ -1,3 +1,3 @@
module OnlyExpose
- VERSION = '0.1.0'
+ VERSION = '0.2.0'
end

0 comments on commit 171eec9

Please sign in to comment.