lib/npr/concern/shallow_attributes.rb in npr-1.1.0 vs lib/npr/concern/shallow_attributes.rb in npr-1.2.0
- old
+ new
@@ -5,19 +5,19 @@
# node. Use this class method to define which attributes those
# are.
#
# Example:
#
-# { "link": { "$text": "www.google.com" } }
-#
-# shallow_attribute "link"
+# { "link": { "$text": "http://npr.org" } }
#
+# shallow_attribute "link"
+# @story.link # => "http://npr.org"
module NPR
module Concern
module ShallowAttributes
include AttrTypecast
-
+
def self.included(base)
base.extend ClassMethods
end
#-----------------
@@ -25,27 +25,27 @@
module ClassMethods
def shallow_attribute(*attrs)
_shallow_attributes.push *attrs
attr_accessor *attrs
end
-
+
#-----------------
-
+
def _shallow_attributes
@shallow_attributes ||= []
end
-
+
#-----------------
-
+
private
attr_writer :_shallow_attributes
end
-
+
#-----------------
-
+
private
-
+
#-----------------
# Extract the defined shallow_attributes from the JSON
# and set the corresponding attribute.
#
# If the JSON doesn't contain a key for an attribute,
@@ -66,6 +66,6 @@
end
end
end
end # ShallowAttribute
end # Concern
-end # NPR
\ No newline at end of file
+end # NPR