class SimpleJsonapi::Definition::Attribute
Represents a single attribute in a resource's attributes
collection @!attribute [r] name
@return [Symbol]
@!attribute [r] data_type
@return [Symbol]
@!attribute [r] array
@return [Boolean]
@!attribute [r] description
@return [String]
Attributes
array[R]
data_type[R]
description[R]
name[R]
value_proc[R]
@visibility private
Public Class Methods
new(name, *args, type: nil, array: false, description: nil, **options, &block)
click to toggle source
@overload initialize(name, type: nil, description: nil, **options, &block) @overload initialize(name, value, type: nil, description: nil, **options) @param type [Symbol] data type @param description [String] @yieldparam resource [Object] @yieldreturn [Object] @option (see Definition::Base#initialize)
Calls superclass method
SimpleJsonapi::Definition::Base::new
# File lib/simple_jsonapi/definition/attribute.rb, line 22 def initialize(name, *args, type: nil, array: false, description: nil, **options, &block) raise ArgumentError, "A name is required" if name.blank? super @name = name.to_sym @data_type = type&.to_sym @array = array @description = description.to_s.presence if args.none? && !block_given? @value_proc = wrap_in_proc { |resource| resource.public_send(name) } else @value_proc = wrap_in_proc(*args, &block) end end
Private Instance Methods
initialize_dup(new_def)
click to toggle source
Calls superclass method
SimpleJsonapi::Definition::Base#initialize_dup
# File lib/simple_jsonapi/definition/attribute.rb, line 40 def initialize_dup(new_def) super # name is a symbol, can't be duped new_def.instance_variable_set(:@value_proc, @value_proc.dup) end