lib/shamu/json_api/resource_builder.rb in shamu-0.0.4 vs lib/shamu/json_api/resource_builder.rb in shamu-0.0.5
- old
+ new
@@ -4,10 +4,12 @@
module JsonApi
# Used by a {Serilaizer} to write fields and relationships
class ResourceBuilder < BaseBuilder
+ include BuilderMethods::Identifier
+
# @overload attribute( attributes )
# @param [Hash] attributes to write.
# @overload attribute( name, value )
# @param [String, Symbol] name of the attribute.
# @param [Object] value that can be persited to a JSON primitive value.
@@ -24,10 +26,11 @@
name_or_hash.each do |n, v|
add_attribute n, v
end
end
end
+ alias_method :attributes, :attribute
# Build a relationship reference.
#
# ```
# relationship :author do |builder|
@@ -52,23 +55,10 @@
relationships = ( output[:relationships] ||= {} )
relationships[ name.to_sym ] = builder.compile
end
- # (see BaseBuilder#identifier)
- def identifier( * )
- super.tap do
- @type = output[:type]
- end
- end
-
private
-
- attr_reader :type
-
- def require_identifier!
- fail IdentifierRequiredError unless @type
- end
def add_attribute( name, value )
return unless context.include_field?( type, name )
attributes = ( output[:attributes] ||= {} )
\ No newline at end of file