Module: JsonapiCompliable::Extensions::BooleanAttribute::ClassMethods

Defined in:
lib/jsonapi_compliable/extensions/boolean_attribute.rb

Instance Method Summary collapse

Instance Method Details

#boolean_attribute(name, options = {}, &blk) ⇒ Object

Register a boolean attribute

Parameters:

  • name

    the corresponding ? method

  • options (Hash) (defaults to: {})

    Normal .attribute options



21
22
23
24
25
# File 'lib/jsonapi_compliable/extensions/boolean_attribute.rb', line 21

def boolean_attribute(name, options = {}, &blk)
  blk ||= proc { @object.public_send(name) }
  field_name = :is_#{name.to_s.gsub('?', '')}"
  attribute field_name, options, &blk
end