Class: Plutonium::Query::AdhocBlock

Inherits:
Base
  • Object
show all
Defined in:
lib/plutonium/query/adhoc_block.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Definition::Presentable

#description, #icon, #label

Constructor Details

#initialize(body) ⇒ AdhocBlock

Initializes a AdhocBlock with a given block of code.

Parameters:

  • body (Proc)

    The block of code for the query.



9
10
11
12
# File 'lib/plutonium/query/adhoc_block.rb', line 9

def initialize(body)
  super()
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/plutonium/query/adhoc_block.rb', line 4

def body
  @body
end

Instance Method Details

#apply(scope, context: nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/plutonium/query/adhoc_block.rb', line 14

def apply(scope, context: nil, **)
  if context
    context.instance_exec(scope, **, &body)
  else
    body.call(scope, **)
  end
end