Module: JsonapiAmsExtensions::ClassMethods

Defined in:
lib/jsonapi_ams_extensions.rb

Instance Method Summary collapse

Instance Method Details

#boolean_attribute(name, *args) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/jsonapi_ams_extensions.rb', line 44

def boolean_attribute(name, *args)
  is_method = :"is_#{name.to_s.sub('?', '')}"
  attribute(is_method, *args)

  define_method(is_method) do
    object.read_attribute_for_serialization(name)
  end
end

#boolean_attributes(*attributes) ⇒ Object



53
54
55
56
57
# File 'lib/jsonapi_ams_extensions.rb', line 53

def boolean_attributes(*attributes)
  attributes.each do |attr|
    boolean_attribute(attr)
  end
end

#extra_attribute(name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jsonapi_ams_extensions.rb', line 26

def extra_attribute(name)
  attribute name, if: :"allow_#{name}?"

  define_method :"allow_#{name}?" do
    if extra_fields = instance_options[:extra_fields]
      if extra_fields = extra_fields[ResourceType.for(self)]
        extra_fields.include?(name)
      end
    end
  end
end

#extra_attributes(*names) ⇒ Object



38
39
40
41
42
# File 'lib/jsonapi_ams_extensions.rb', line 38

def extra_attributes(*names)
  names.each do |name|
    extra_attribute(name)
  end
end