From c5fdc93bc85b71efd59f422029aa282a6a04bdd0 Mon Sep 17 00:00:00 2001 From: Daniel Sullivan Date: Thu, 10 Aug 2017 08:29:44 +0900 Subject: [PATCH] Fix for https://github.com/jsonapi-rb/jsonapi-serializable/issues/80 --- lib/jsonapi/serializable/resource/conditional_fields.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/jsonapi/serializable/resource/conditional_fields.rb b/lib/jsonapi/serializable/resource/conditional_fields.rb index a0b9e8c..2d37979 100644 --- a/lib/jsonapi/serializable/resource/conditional_fields.rb +++ b/lib/jsonapi/serializable/resource/conditional_fields.rb @@ -22,14 +22,16 @@ def self.prepended(klass) end def self.extended(klass) - klass.class_eval do - include InstanceMethods + klass.module_eval do + prepend InstanceMethods + class << self attr_accessor :field_condition_blocks attr_accessor :link_condition_blocks end self.field_condition_blocks ||= {} self.link_condition_blocks ||= {} + end end @@ -49,6 +51,8 @@ def attribute(name, options = {}, &block) _register_condition(field_condition_blocks, name, options) end + + # Handle the `if` and `unless` options for relationships (has_one, # belongs_to, has_many). #