Class: RVGP::Utilities::Yaml::PsychProc

Inherits:
Object
  • Object
show all
Defined in:
lib/rvgp/utilities/yaml.rb

Overview

This class wraps proc types, in the yaml, and offers us the ability to execute the code in these blocks.

Instance Method Summary collapse

Constructor Details

#initialize(proc_as_string) ⇒ PsychProc

Declare a proc, given the provided proc_as_string code

Parameters:

  • proc_as_string (String)

    Ruby code, that this block will call.



55
56
57
# File 'lib/rvgp/utilities/yaml.rb', line 55

def initialize(proc_as_string)
  @block = eval(format('proc { %s }', proc_as_string)) # rubocop:disable Security/Eval
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object (private)



77
78
79
# File 'lib/rvgp/utilities/yaml.rb', line 77

def method_missing(name)
  respond_to_missing?(name) ? @params[name] : super(name)
end

Instance Method Details

#call(params = {}) ⇒ Object

Execute the block, using the provided params as locals NOTE: We expect symbol to value here

Parameters:

  • params (Hash<Symbol, Object>) (defaults to: {})

    local values, available in the proc context. Note that keys are expected to be symbols.

Returns:

  • (Object)

    Whatever the proc returns



64
65
66
67
68
69
# File 'lib/rvgp/utilities/yaml.rb', line 64

def call(params = {})
  # params, here, act as instance variables, since we don't support named
  # params in the provided string, the way you typically would.
  @params = params
  @block.call
end