Class: ParameterSubstitution::Context
- Inherits:
-
Object
- Object
- ParameterSubstitution::Context
- Defined in:
- lib/parameter_substitution/context.rb
Instance Attribute Summary collapse
-
#allow_nil ⇒ Object
readonly
Returns the value of attribute allow_nil.
-
#allow_unknown_replacement_parameters ⇒ Object
readonly
Returns the value of attribute allow_unknown_replacement_parameters.
-
#allow_unmatched_parameter_end ⇒ Object
readonly
Returns the value of attribute allow_unmatched_parameter_end.
-
#destination_encoding ⇒ Object
readonly
Returns the value of attribute destination_encoding.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#mapping ⇒ Object
readonly
Returns the value of attribute mapping.
-
#parameter_end ⇒ Object
readonly
Returns the value of attribute parameter_end.
-
#parameter_start ⇒ Object
readonly
Returns the value of attribute parameter_start.
-
#required_parameters ⇒ Object
readonly
Returns the value of attribute required_parameters.
Instance Method Summary collapse
- #allow_unknown_params?(inside_quotes) ⇒ Boolean
- #duplicate_raw ⇒ Object
- #formatted_arg_list(arg_list) ⇒ Object
-
#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
constructor
A new instance of Context.
- #mapped_value(key) ⇒ Object
- #mapping_has_key?(key) ⇒ Boolean
- #mapping_keys ⇒ Object
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_nil ⇒ Object (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_parameters ⇒ Object (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_end ⇒ Object (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_encoding ⇒ Object (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 |
#input ⇒ Object (readonly)
Returns the value of attribute input.
7 8 9 |
# File 'lib/parameter_substitution/context.rb', line 7 def input @input end |
#mapping ⇒ Object (readonly)
Returns the value of attribute mapping.
7 8 9 |
# File 'lib/parameter_substitution/context.rb', line 7 def mapping @mapping end |
#parameter_end ⇒ Object (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_start ⇒ Object (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_parameters ⇒ Object (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
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_raw ⇒ Object
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
38 39 40 |
# File 'lib/parameter_substitution/context.rb', line 38 def mapping_has_key?(key) downcased_mapping.key?(key.downcase) end |
#mapping_keys ⇒ Object
46 47 48 |
# File 'lib/parameter_substitution/context.rb', line 46 def mapping_keys mapping.keys end |