Class: ROM::Components::View

Inherits:
Core
  • Object
show all
Defined in:
lib/rom/components/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#relation_blockProc (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Block used for view method definition.

Returns:

  • (Proc)

    Block used for view method definition



17
# File 'lib/rom/components/view.rb', line 17

option :relation_block

#relation_idSymbol (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Relation runtime identifier.

Returns:

  • (Symbol)

    Relation runtime identifier



12
# File 'lib/rom/components/view.rb', line 12

option :relation_id

Instance Method Details

#buildROM::Relation

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



22
23
24
# File 'lib/rom/components/view.rb', line 22

def build
  registry.relations[relation_id].public_send(config.id)
end

#define(constant) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Symbol)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rom/components/view.rb', line 29

def define(constant)
  _name = config.id
  _relation_block = relation_block

  if relation_block&.arity&.positive?
    constant.class_eval do
      auto_curry_guard do
        define_method(_name, &_relation_block)

        auto_curry(_name) do
          schemas[_name].(self)
        end
      end
    end
  else
    constant.class_eval do
      define_method(_name) do
        schemas[_name].(instance_eval(&_relation_block))
      end
    end
  end

  _name
end