module JsonapiCompliable::Extensions::ExtraAttribute::ClassMethods

Public Instance Methods

extra_attribute(name, options = {}, &blk) click to toggle source

@param [Symbol] name the name of the attribute @param [Hash] options the options passed on to vanilla to .attribute

# File lib/jsonapi_compliable/extensions/extra_attribute.rb, line 43
def extra_attribute(name, options = {}, &blk)
  allow_field = proc {
    if options[:if]
      next false unless instance_eval(&options[:if])
    end

    @extra_fields[@_type] && @extra_fields[@_type].include?(name)
  }

  attribute name, if: allow_field, &blk
end