Skip to content

Commit f94e9a6

Browse files
committed
Merge pull request #319 from kbrock/more_cops
More cops
2 parents beab088 + 72ec87e commit f94e9a6

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

lib/floe/container_runner/docker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def docker_event_status_to_event(status)
176176
when "die", "destroy"
177177
:delete
178178
else
179-
:unkonwn
179+
:unknown
180180
end
181181
end
182182

lib/floe/workflow/choice_rule/data.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,27 @@ def parse_compare_key
111111
if (match_values = OPERATION.match(key))
112112
@compare_key = key
113113
@type, operator, @path = match_values.captures
114-
@operation = "op_#{operator.downcase}?".to_sym
114+
@operation = :"op_#{operator.downcase}?"
115115
@compare_predicate = parse_predicate(type)
116116
break
117-
end
118117
# e.g. (Is)(String)
119-
if (match_value = TYPE_CHECK.match(key))
118+
elsif (match_value = TYPE_CHECK.match(key))
120119
@compare_key = key
121120
_operator, type = match_value.captures
122121
# type: nil means no runtime type checking.
123122
@type = @path = nil
124-
@operation = "is_#{type.downcase}?".to_sym
123+
@operation = :"is_#{type.downcase}?"
125124
@compare_predicate = parse_predicate("Boolean")
126125
break
127126
end
128127
end
129128
parser_error!("requires a compare key") if compare_key.nil? || operation.nil?
130129
end
131130

132-
# parse predicate at initilization time
131+
# parse predicate at initialization time
132+
# @param data_type [String] the data type of the variable
133+
# When parsing operations (IntegerGreaterThan), this will be the operation data type (e.g.: Integer)
134+
# When parsing type checks (IsString), this will always be a Boolean
133135
# @return the right predicate attached to the compare key
134136
def parse_predicate(data_type)
135137
path ? parse_path(compare_key) : parse_field(compare_key, data_type)
@@ -140,13 +142,13 @@ def compare_value(context, input)
140142
path ? fetch_path(compare_key, compare_predicate, context, input) : compare_predicate
141143
end
142144

143-
# feth the variable value at runtime
144-
# @return variable value (left hand side )
145+
# fetch the variable value at runtime
146+
# @return variable value (left hand side)
145147
def variable_value(context, input)
146148
fetch_path("Variable", variable, context, input)
147149
end
148150

149-
# parse path at initilization time
151+
# parse path at initialization time
150152
# helper method to parse a path from the payload
151153
def parse_path(field_name)
152154
value = payload[field_name]
@@ -155,6 +157,10 @@ def parse_path(field_name)
155157
end
156158

157159
# parse predicate field at initialization time
160+
# @param field_name [String] the compare key
161+
# @param data_type [String] the data type of the variable
162+
# When parsing operations (IntegerGreaterThan), this will be the operation data type (e.g.: Integer)
163+
# When parsing type checks (IsString), this will always be a Boolean
158164
def parse_field(field_name, data_type)
159165
value = payload[field_name]
160166
return value if correct_type?(value, data_type)
@@ -165,6 +171,7 @@ def parse_field(field_name, data_type)
165171
# fetch a path at runtime
166172
def fetch_path(field_name, field_path, context, input)
167173
value = field_path.value(context, input)
174+
# if this is an operation (GreaterThanPath), ensure the value is the correct type
168175
return value if type.nil? || correct_type?(value, type)
169176

170177
runtime_field_error!(field_name, field_path.to_s, "required to point to a #{type}")
@@ -173,7 +180,7 @@ def fetch_path(field_name, field_path, context, input)
173180
# if we have runtime checking, check against that type
174181
# otherwise assume checking a TYPE_CHECK predicate and check against Boolean
175182
def correct_type?(value, data_type)
176-
send("is_#{data_type.downcase}?".to_sym, value)
183+
send(:"is_#{data_type.downcase}?", value)
177184
end
178185
end
179186
end

lib/floe/workflow/context.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def to_h
148148
end
149149

150150
def ==(other)
151-
other.is_a?(self.class) && other.instance_variable_get("@context") == @context
151+
other.kind_of?(self.class) && other.instance_variable_get(:@context) == @context
152152
end
153153
alias eql? ==
154154

lib/floe/workflow/intrinsic_function/transformer.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,15 @@ def check_types(args, function, signature)
236236

237237
rule(:states_string_split => {:args => subtree(:args)}) do
238238
args = Transformer.process_args(args(), "States.StringSplit", [String, String])
239-
str, delimeter = *args
239+
str, delimiter = *args
240240

241-
case delimeter.size
241+
case delimiter.size
242242
when 0
243243
str.empty? ? [] : [str]
244244
when 1
245-
str.split(delimeter)
245+
str.split(delimiter)
246246
else
247-
str.split(/[#{Regexp.escape(delimeter)}]+/)
247+
str.split(/[#{Regexp.escape(delimiter)}]+/)
248248
end
249249
end
250250

spec/workflow/context_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@
201201
describe "#inspect" do
202202
it "has the same value with or without credentials" do
203203
# removing spaces because Hash#inspect in ruby 3.4 adds spaces that are not present before
204-
expect(ctx.inspect.gsub(" ", "")).to eq("#<Floe::Workflow::Context: {\"Execution\" => {\"Input\" => {\"x\" => \"y\"}}, \"State\" => {}, \"StateHistory\" => [], \"StateMachine\" => {}, \"Task\" => {}}>".gsub(" ", ""))
205-
expect(ctx_creds.inspect.gsub(" ", "")).to eq("#<Floe::Workflow::Context: {\"Execution\" => {\"Input\" => {\"x\" => \"y\"}}, \"State\" => {}, \"StateHistory\" => [], \"StateMachine\" => {}, \"Task\" => {}}>".gsub(" ", ""))
204+
expect(ctx.inspect.delete(" ")).to eq("#<Floe::Workflow::Context: {\"Execution\" => {\"Input\" => {\"x\" => \"y\"}}, \"State\" => {}, \"StateHistory\" => [], \"StateMachine\" => {}, \"Task\" => {}}>".delete(" "))
205+
expect(ctx_creds.inspect.delete(" ")).to eq("#<Floe::Workflow::Context: {\"Execution\" => {\"Input\" => {\"x\" => \"y\"}}, \"State\" => {}, \"StateHistory\" => [], \"StateMachine\" => {}, \"Task\" => {}}>".delete(" "))
206206
end
207207

208208
it "doesn't expose credentials" do
@@ -238,7 +238,7 @@
238238
end
239239
end
240240

241-
describe "#eql?" do
241+
describe "#eql?" do
242242
it "compares with values" do
243243
ctx1 = described_class.new(:input => input.to_json)
244244
ctx2 = described_class.new(:input => input.to_json)

0 commit comments

Comments
 (0)