Class: ParameterSubstitution::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/parameter_substitution/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input:, mapping:, required_parameters: [], parameter_start: "<", parameter_end: ">", destination_encoding: :text, allow_unknown_replacement_parameters: false, allow_nil: false, allow_unmatched_parameter_end: false) ⇒ Context

Returns a new instance of Context.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/parameter_substitution/context.rb', line 11

def initialize(
  input:,
  mapping:,
  required_parameters: [],
  parameter_start: "<",
  parameter_end: ">",
  destination_encoding: :text,
  allow_unknown_replacement_parameters: false,
  allow_nil: false,
  allow_unmatched_parameter_end: false
)

  @input = input
  @mapping = mapping
  @required_parameters = required_parameters
  @parameter_start = parameter_start
  @parameter_end = parameter_end
  @destination_encoding = destination_encoding
  @allow_unknown_replacement_parameters = allow_unknown_replacement_parameters
  @allow_nil = allow_nil
  @allow_unmatched_parameter_end = allow_unmatched_parameter_end
end

Instance Attribute Details

#allow_nilObject (readonly)

Returns the value of attribute allow_nil.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def allow_nil
  @allow_nil
end

#allow_unknown_replacement_parametersObject (readonly)

Returns the value of attribute allow_unknown_replacement_parameters.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def allow_unknown_replacement_parameters
  @allow_unknown_replacement_parameters
end

#allow_unmatched_parameter_endObject (readonly)

Returns the value of attribute allow_unmatched_parameter_end.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def allow_unmatched_parameter_end
  @allow_unmatched_parameter_end
end

#destination_encodingObject (readonly)

Returns the value of attribute destination_encoding.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def destination_encoding
  @destination_encoding
end

#inputObject (readonly)

Returns the value of attribute input.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def input
  @input
end

#mappingObject (readonly)

Returns the value of attribute mapping.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def mapping
  @mapping
end

#parameter_endObject (readonly)

Returns the value of attribute parameter_end.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def parameter_end
  @parameter_end
end

#parameter_startObject (readonly)

Returns the value of attribute parameter_start.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def parameter_start
  @parameter_start
end

#required_parametersObject (readonly)

Returns the value of attribute required_parameters.



7
8
9
# File 'lib/parameter_substitution/context.rb', line 7

def required_parameters
  @required_parameters
end

Instance Method Details

#allow_unknown_params?(inside_quotes) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/parameter_substitution/context.rb', line 34

def allow_unknown_params?(inside_quotes)
  allow_unknown_replacement_parameters || (destination_encoding == :json && inside_quotes)
end

#duplicate_rawObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/parameter_substitution/context.rb', line 54

def duplicate_raw
  ParameterSubstitution::Context.new(
    input: @input,
    mapping: @mapping,
    required_parameters: @required_parameters,
    parameter_start: @parameter_start,
    parameter_end: @parameter_end,
    destination_encoding: :raw,
    allow_unknown_replacement_parameters: @allow_unknown_replacement_parameters,
    allow_nil: @allow_nil,
    allow_unmatched_parameter_end: @allow_unmatched_parameter_end
  )
end

#formatted_arg_list(arg_list) ⇒ Object



50
51
52
# File 'lib/parameter_substitution/context.rb', line 50

def formatted_arg_list(arg_list)
  arg_list.sort.map { |arg| "'#{arg}'" }.join(", ")
end

#mapped_value(key) ⇒ Object



42
43
44
# File 'lib/parameter_substitution/context.rb', line 42

def mapped_value(key)
  downcased_mapping[key.downcase]
end

#mapping_has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/parameter_substitution/context.rb', line 38

def mapping_has_key?(key)
  downcased_mapping.key?(key.downcase)
end

#mapping_keysObject



46
47
48
# File 'lib/parameter_substitution/context.rb', line 46

def mapping_keys
  mapping.keys
end