Class: ROM::Components::DSL::View Private

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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#relation_blockObject (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.



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

def relation_block
  @relation_block
end

#schema_blockObject (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.



13
14
15
# File 'lib/rom/components/dsl/view.rb', line 13

def schema_block
  @schema_block
end

Instance Method Details

#callObject

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.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rom/components/dsl/view.rb', line 35

def call
  # Nest view under relation ns
  config.join!({namespace: relation_id}, :right)

  if args.empty? && block.arity.positive?
    raise ArgumentError, "schema attribute names must be provided as the second argument"
  end

  # Capture schema and relation blocks if there are no args
  # otherwise assume args is a list of attributes to project
  if args.empty? && block
    instance_eval(&block)
  else
    schema { schema.project(*args.first) }
  end

  provider.schema(
    id: config.id,
    namespace: relation_id,
    relation: relation_id,
    view: true,
    &schema_block
  )

  components.add(
    key,
    config: config,
    relation_id: relation_id,
    # Default to the block because we assume the schema was set based on args
    relation_block: relation_block || block
  )
end

#relation(&block) ⇒ Object



29
30
31
32
# File 'lib/rom/components/dsl/view.rb', line 29

def relation(&block)
  @relation_block = block
  self
end

#schema(&block) ⇒ Object



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

def schema(&block)
  @schema_block = block
  self
end