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