parameter_substitution 0.3.0.pre.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 832702dbcfb569f36a9f85bc96cefd0d5d7fdf40
4
- data.tar.gz: d43a6209498df3ceac71169c3e2b3bd629b9c46f
2
+ SHA256:
3
+ metadata.gz: 28e66926e2dc18a7902f3670410a6290b34d44da4f490045d15787085eacf800
4
+ data.tar.gz: b3618e294a0c4f07573382bacc574f8684abebf1dd8da4e1eb5752027c9e2470
5
5
  SHA512:
6
- metadata.gz: 259266dfafe0c96e80d1300a6da01d84ded237e0cb169b66df5d2dac11b17698e44bf57b6b332f504507ab40bc31048af1d63997c382f3048234f866b09121df
7
- data.tar.gz: c434aeff54ada28bd8bb2fa1e61acff527cdc84eba240fb49afb32ad393f2e740e787ef9c0d61a188081e03f6758fdb5cb9aa58638984d48f7873bcda3624c74
6
+ metadata.gz: 2b383ce1da83355a4c5db67561491cfc83636bb4b7ab97d1fe72e1ecc622b44451c8ff1be54083be0b69648a16e925eb1253552b35feadacdfb13a91e86afe67
7
+ data.tar.gz: 3fb0bd0c28df9e4b6b8b4155894717aa31e1d5f0773b5060769956b55c58ceec835537cd9574506e568191375673205823b9edf7bc7be57ae64b6f2f9c75e65f
@@ -2,6 +2,7 @@
2
2
 
3
3
  # See lib/parameter_substitution/readme.md
4
4
 
5
+ require 'active_support/all'
5
6
  require "parameter_substitution/context"
6
7
  require "parameter_substitution/parse_error"
7
8
  require "parameter_substitution/parser"
@@ -18,8 +19,6 @@ Dir[File.dirname(__FILE__) + '/parameter_substitution/formatters/*.rb'].each do
18
19
  require file
19
20
  end
20
21
 
21
- require 'active_support/all'
22
-
23
22
  class ParameterSubstitution
24
23
  class SubstitutionError < StandardError; end
25
24
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'hobo_support/enumerable'
3
+ require 'invoca/utils/enumerable'
4
4
 
5
5
  class ParameterSubstitution
6
6
  class Context
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
-
3
- require 'hobo_support'
2
+ require "parameter_substitution/formatters/date_time_format"
4
3
 
5
4
  class ParameterSubstitution::Formatters::DateTimeCustom < ParameterSubstitution::Formatters::DateTimeFormat
6
5
  def self.has_parameters?
@@ -18,8 +17,6 @@ class ParameterSubstitution::Formatters::DateTimeCustom < ParameterSubstitution:
18
17
  end
19
18
 
20
19
  def format(value)
21
- self.class.parse_to_time(value, @parse_options)._?
22
- .in_time_zone(@to_time_zone)._?
23
- .strftime(@to_formatting).to_s
20
+ self.class.parse_to_time(value, @parse_options)&.in_time_zone(@to_time_zone)&.strftime(@to_formatting).to_s # rubocop:disable Lint/SafeNavigationChain
24
21
  end
25
22
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ParameterSubstitution::Formatters::IfTruthy < ParameterSubstitution::Formatters::Base
4
+ TRUTHY_VALUES = [true, "true", "t", 1, "1", "on", "yes"].freeze
5
+
6
+ def self.description
7
+ "If the input is truthy (i.e. #{TRUTHY_VALUES.inspect}) then the input is replaced with the first argument. Otherwise, the input is replaced with the second argument."
8
+ end
9
+
10
+ def self.has_parameters?
11
+ true
12
+ end
13
+
14
+ def initialize(value_if_true, value_if_false)
15
+ @value_if_true = value_if_true
16
+ @value_if_false = value_if_false
17
+ end
18
+
19
+ def format(value)
20
+ if TRUTHY_VALUES.include?(downcase_if_string(value))
21
+ @value_if_true
22
+ else
23
+ @value_if_false
24
+ end
25
+ end
26
+
27
+ :private
28
+
29
+ def downcase_if_string(value)
30
+ if value.is_a?(String)
31
+ value.downcase
32
+ else
33
+ value
34
+ end
35
+ end
36
+ end
@@ -17,7 +17,7 @@ class ParameterSubstitution::Formatters::ParseTime < ParameterSubstitution::Form
17
17
  value && Time.strptime(value.to_s, @format_string).strftime('%Y-%m-%d %H:%M:%S')
18
18
  rescue ArgumentError => ex
19
19
  # strptime raises argument error if either argument is wrong.
20
- ex.message =~ /invalid strptime format/ or raise
20
+ ex.message =~ /invalid .*strptime format/ or raise
21
21
  value
22
22
  end
23
23
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'hobo_support/array'
3
+ require 'invoca/utils/array'
4
4
 
5
5
  class ParameterSubstitution
6
6
  class SubstitutionExpression
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ParameterSubstitution
4
- VERSION = "0.3.0.pre.3"
4
+ VERSION = "1.2.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameter_substitution
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.pre.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca Development
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
33
+ - !ruby/object:Gem::Dependency
34
+ name: builder
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: invoca-utils
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.3'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.3'
61
+ - !ruby/object:Gem::Dependency
62
+ name: parslet
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.8'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.8'
13
75
  description: The substitution can be formatted using a syntax that looks like method
14
76
  calls
15
77
  email:
@@ -49,6 +111,7 @@ files:
49
111
  - lib/parameter_substitution/formatters/duration_grouped_by_description.rb
50
112
  - lib/parameter_substitution/formatters/greater_than_value.rb
51
113
  - lib/parameter_substitution/formatters/if_nil.rb
114
+ - lib/parameter_substitution/formatters/if_truthy.rb
52
115
  - lib/parameter_substitution/formatters/in_timezone.rb
53
116
  - lib/parameter_substitution/formatters/json_parse.rb
54
117
  - lib/parameter_substitution/formatters/left.rb
@@ -88,12 +151,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
151
  version: '0'
89
152
  required_rubygems_version: !ruby/object:Gem::Requirement
90
153
  requirements:
91
- - - ">"
154
+ - - ">="
92
155
  - !ruby/object:Gem::Version
93
- version: 1.3.1
156
+ version: '0'
94
157
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.6.13
158
+ rubygems_version: 3.0.3
97
159
  signing_key:
98
160
  specification_version: 4
99
161
  summary: Handles parsing an input strings with embedded substitution parameters and