Module: Graphiti::Extensions::ExtraAttribute::ClassMethods

Defined in:
lib/graphiti/extensions/extra_attribute.rb

Instance Method Summary collapse

Instance Method Details

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

Parameters:

  • name (Symbol)

    the name of the attribute

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

    the options passed on to vanilla to .attribute



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/graphiti/extensions/extra_attribute.rb', line 43

def extra_attribute(name, options = {}, &blk)
  allow_field = proc {
    if options[:if]
      next false unless instance_exec(&options[:if])
    end

    next false unless @extra_fields

    @extra_fields[@_type]&.include?(name) || @extra_fields[@resource&.type]&.include?(name)
  }

  attribute name, if: allow_field, &blk
end