class Wrapture::ActionSpec
An action to take within a generated program.
Public Class Methods
new(spec)
click to toggle source
Creates an action spec based on the provided spec hash.
The hash must have the following keys:
- name
-
the type of action to take (currently only throw-exception is
supported)
- constructor
-
the function to use to create the exception, described as a
wrapped function call
# File lib/wrapture/action_spec.rb, line 56 def initialize(spec) @spec = ActionSpec.normalize_spec_hash(spec) end
normalize_spec_hash(spec)
click to toggle source
Normalizes a hash specification of a rule. Normalization checks for invalid keys and unrecognized conditions.
# File lib/wrapture/action_spec.rb, line 26 def self.normalize_spec_hash(spec) normalized = spec.dup required_keys = %w[name constructor] missing_keys = required_keys - spec.keys unless missing_keys.empty? missing_msg = "required keys are missing: #{missing_keys.join(', ')}" raise(MissingSpecKey, missing_msg) end extra_keys = spec.keys - required_keys unless extra_keys.empty? extra_msg = "these keys are unrecognized: #{extra_keys.join(', ')}" raise(InvalidSpecKey, extra_msg) end func_spec = WrappedFunctionSpec.normalize_spec_hash(spec['constructor']) normalized['constructor'] = func_spec normalized end
Public Instance Methods
includes()
click to toggle source
A list of includes needed for the action.
# File lib/wrapture/action_spec.rb, line 61 def includes @spec['constructor']['includes'].dup end
take()
click to toggle source
A string containing the invocation of this action.
# File lib/wrapture/action_spec.rb, line 66 def take call_spec = @spec['constructor'] params = call_spec['params'].map do |param_spec| if param_spec['value'] == RETURN_VALUE_KEYWORD 'return_val' else param_spec['value'] end end "throw #{call_spec['name']}( #{params.join(', ')} )" end