lib/jsonity/attribute.rb in jsonity-1.0.4 vs lib/jsonity/attribute.rb in jsonity-1.0.5
- old
+ new
@@ -6,34 +6,58 @@
###
# Automatically export attributes to json
#
# @params {[String | Symbol]} *attrs
+ # @block - [optional]
###
- def attr_json(*attrs)
- @json_attributes ||= Set.new
- @json_attributes |= attrs.map(&:to_s)
+ def attr_json(*attrs, &block)
+ @json_attributes ||= []
+ @json_attributes += attrs.map(&:to_s)
+ @json_attributes.uniq!
+
+ @json_attribute_blocks ||= []
+ @json_attribute_blocks << block if block
end
###
# Get json attributes
#
# @return {[String]}
###
def json_attributes
- @json_attributes.to_a
+ @json_attributes || []
end
+
+ ###
+ # Get json attributes
+ #
+ # @return {[String]}
+ ###
+ def json_attribute_blocks
+ @json_attribute_blocks || []
+ end
+
end
module InstanceMethods
###
- # Get json attributes
+ # Get json attributes (delegates to self class)
#
# @return {[String]}
###
def json_attributes
self.class.json_attributes
+ end
+
+ ###
+ # Get json attributes (delegates to self class)
+ #
+ # @return {[String]}
+ ###
+ def json_attribute_blocks
+ self.class.json_attribute_blocks
end
end
end
end