Sha256: fbfbc73e78a8e97a0fa8077dc3f47a642bd15631f031af6bfe387d7235b9645d

Contents?: true

Size: 767 Bytes

Versions: 12

Compression:

Stored size: 767 Bytes

Contents

require 'jsonapi/serializable/resource/conditional_fields'

module JsonapiCompliable
  module Extensions
    module ExtraAttribute
      def self.included(klass)
        klass.extend ClassMethods
      end

      module ClassMethods
        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
      end
    end
  end
end

JSONAPI::Serializable::Resource.class_eval do
  prepend JSONAPI::Serializable::Resource::ConditionalFields
  include JsonapiCompliable::Extensions::ExtraAttribute
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jsonapi_compliable-0.6.4 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.6.3 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.6.2 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.6.1 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.6.0 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.7 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.6 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.5 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.4 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.3 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.2 lib/jsonapi_compliable/extensions/extra_attribute.rb
jsonapi_compliable-0.5.1 lib/jsonapi_compliable/extensions/extra_attribute.rb