Class: Jei::Relationship

Inherits:
Field
  • Object
show all
Defined in:
lib/jei/relationship.rb

Direct Known Subclasses

BelongsToRelationship, HasManyRelationship

Instance Attribute Summary collapse

Attributes inherited from Field

#name

Instance Method Summary collapse

Methods inherited from Field

#evaluate

Constructor Details

#initialize(name, value = name, options = {}) ⇒ Relationship

Returns a new instance of Relationship.

Parameters:

  • name (Symbol)
  • value (Proc, Symbol) (defaults to: name)
  • options (Hash<Symbol, Object>) (defaults to: {})

Options Hash (options):

  • :data (Boolean) — default: true

    whether to include data in the relationship

  • :links (Proc)

    a ‘Proc` that evaulates to a list of links

  • :serializer (Class)

    override the default serializer used for related resources



14
15
16
17
18
# File 'lib/jei/relationship.rb', line 14

def initialize(name, value = name, options = {})
  super(name, value)
  options[:data] = options.fetch(:data, true)
  @options = options
end

Instance Attribute Details

#optionsHash<Symbol, Object> (readonly)

Returns options.

Returns:

  • (Hash<Symbol, Object>)

    options



4
5
6
# File 'lib/jei/relationship.rb', line 4

def options
  @options
end

Instance Method Details

Parameters:

Returns:



22
23
24
# File 'lib/jei/relationship.rb', line 22

def links(serializer)
  serializer.instance_exec(&options[:links])
end