Skip to content

Commit d6dfd38

Browse files
committed
style: fix Ruby Standard Style violations
- Use double-quoted strings consistently - Fix indentation and alignment issues - Use alias_method instead of alias - Fix empty method definition style
1 parent c999038 commit d6dfd38

File tree

2 files changed

+59
-58
lines changed

2 files changed

+59
-58
lines changed

templatescompiler/erbrenderer/erb_renderer.rb

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Based on common/properties/template_evaluation_context.rb
2-
require 'rubygems'
3-
require 'json'
4-
require 'erb'
5-
require 'yaml'
2+
require "rubygems"
3+
require "json"
4+
require "erb"
5+
require "yaml"
66

77
# Simple struct-like class to replace OpenStruct dependency
88
# OpenStruct is being removed from Ruby standard library in Ruby 3.5+
@@ -15,15 +15,15 @@ def initialize(hash = {})
1515
end
1616

1717
def method_missing(method_name, *args)
18-
if method_name.to_s.end_with?('=')
19-
@table[method_name.to_s.chomp('=').to_sym] = wrap_value(args.first)
18+
if method_name.to_s.end_with?("=")
19+
@table[method_name.to_s.chomp("=").to_sym] = wrap_value(args.first)
2020
else
2121
@table[method_name.to_sym]
2222
end
2323
end
2424

2525
def respond_to_missing?(method_name, _include_private = false)
26-
@table.key?(method_name.to_sym) || method_name.to_s.end_with?('=')
26+
@table.key?(method_name.to_sym) || method_name.to_s.end_with?("=")
2727
end
2828

2929
private
@@ -57,17 +57,17 @@ class TemplateEvaluationContext
5757
attr_reader :name, :index, :properties, :raw_properties, :spec
5858

5959
def initialize(spec)
60-
@name = spec['job']['name'] if spec['job'].is_a?(Hash)
61-
@index = spec['index']
60+
@name = spec["job"]["name"] if spec["job"].is_a?(Hash)
61+
@index = spec["index"]
6262

63-
properties1 = if !spec['job_properties'].nil?
64-
spec['job_properties']
65-
else
66-
spec['global_properties'].recursive_merge!(spec['cluster_properties'])
67-
end
63+
properties1 = if !spec["job_properties"].nil?
64+
spec["job_properties"]
65+
else
66+
spec["global_properties"].recursive_merge!(spec["cluster_properties"])
67+
end
6868

6969
properties = {}
70-
spec['default_properties'].each do |name, value|
70+
spec["default_properties"].each do |name, value|
7171
copy_property(properties, properties1, name, value)
7272
end
7373

@@ -112,7 +112,7 @@ def if_link(_name)
112112
private
113113

114114
def copy_property(dst, src, name, default = nil)
115-
keys = name.split('.')
115+
keys = name.split(".")
116116
src_ref = src
117117
dst_ref = dst
118118

@@ -145,7 +145,7 @@ def openstruct(object)
145145
end
146146

147147
def lookup_property(collection, name)
148-
keys = name.split('.')
148+
keys = name.split(".")
149149
ref = collection
150150

151151
keys.each do |key|
@@ -180,7 +180,8 @@ def else_if_p(*names, &block)
180180
end
181181

182182
class InactiveElseBlock
183-
def else; end
183+
def else
184+
end
184185

185186
def else_if_p(*_names)
186187
InactiveElseBlock.new
@@ -190,7 +191,7 @@ def else_if_p(*_names)
190191

191192
# TODO: do not use JSON in releases
192193
class << JSON
193-
alias dump_array_or_hash dump
194+
alias_method :dump_array_or_hash, :dump
194195

195196
def dump(*args)
196197
arg = args[0]
@@ -208,7 +209,7 @@ def initialize(json_context_path)
208209
end
209210

210211
def render(src_path, dst_path)
211-
erb = ERB.new(File.read(src_path), trim_mode: '-')
212+
erb = ERB.new(File.read(src_path), trim_mode: "-")
212213
erb.filename = src_path
213214

214215
# NOTE: JSON.load_file was added in v2.3.1: https://github.com/ruby/json/blob/v2.3.1/lib/json/common.rb#L286
@@ -220,7 +221,7 @@ def render(src_path, dst_path)
220221
name = "#{template_evaluation_context&.name}/#{template_evaluation_context&.index}"
221222

222223
line_i = e.backtrace.index { |l| l.include?(erb&.filename.to_s) }
223-
line_num = line_i ? e.backtrace[line_i].split(':')[1] : 'unknown'
224+
line_num = line_i ? e.backtrace[line_i].split(":")[1] : "unknown"
224225
location = "(line #{line_num}: #{e.inspect})"
225226

226227
raise("Error filling in template '#{src_path}' for #{name} #{location}")
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
require 'spec_helper'
2-
require 'erb_renderer'
1+
require "spec_helper"
2+
require "erb_renderer"
33

4-
RSpec.describe 'PropertyStruct' do
5-
describe 'initialization and attribute access' do
6-
it 'provides dynamic attribute access for hash keys' do
7-
ps = PropertyStruct.new(name: 'test', value: 42)
8-
expect(ps.name).to eq('test')
4+
RSpec.describe "PropertyStruct" do
5+
describe "initialization and attribute access" do
6+
it "provides dynamic attribute access for hash keys" do
7+
ps = PropertyStruct.new(name: "test", value: 42)
8+
expect(ps.name).to eq("test")
99
expect(ps.value).to eq(42)
1010
end
1111

12-
it 'converts string keys to symbols' do
13-
ps = PropertyStruct.new('name' => 'test', 'value' => 42)
14-
expect(ps.name).to eq('test')
12+
it "converts string keys to symbols" do
13+
ps = PropertyStruct.new("name" => "test", "value" => 42)
14+
expect(ps.name).to eq("test")
1515
expect(ps.value).to eq(42)
1616
end
1717

18-
it 'supports nested attribute access' do
19-
ps = PropertyStruct.new(config: { database: { host: 'localhost', port: 5432 } })
18+
it "supports nested attribute access" do
19+
ps = PropertyStruct.new(config: {database: {host: "localhost", port: 5432}})
2020
nested = ps.config
2121
expect(nested).to be_a(PropertyStruct)
2222
expect(nested.database).to be_a(PropertyStruct)
23-
expect(nested.database.host).to eq('localhost')
23+
expect(nested.database.host).to eq("localhost")
2424
expect(nested.database.port).to eq(5432)
2525
end
2626

27-
it 'handles arrays of hashes' do
28-
ps = PropertyStruct.new(servers: [{ name: 'web1', ip: '10.0.0.1' }, { name: 'web2', ip: '10.0.0.2' }])
27+
it "handles arrays of hashes" do
28+
ps = PropertyStruct.new(servers: [{name: "web1", ip: "10.0.0.1"}, {name: "web2", ip: "10.0.0.2"}])
2929
servers = ps.servers
3030
expect(servers).to be_an(Array)
3131
expect(servers.length).to eq(2)
32-
expect(servers.first.name).to eq('web1')
33-
expect(servers.last.ip).to eq('10.0.0.2')
32+
expect(servers.first.name).to eq("web1")
33+
expect(servers.last.ip).to eq("10.0.0.2")
3434
end
3535

36-
it 'responds to method queries correctly' do
37-
ps = PropertyStruct.new(existing_key: 'value')
36+
it "responds to method queries correctly" do
37+
ps = PropertyStruct.new(existing_key: "value")
3838
expect(ps.respond_to?(:existing_key)).to be true
3939
expect(ps.respond_to?(:nonexistent_key)).to be false
4040
end
4141
end
4242

43-
describe 'Ruby standard library method pass-through' do
44-
it 'supports array operations like map' do
43+
describe "Ruby standard library method pass-through" do
44+
it "supports array operations like map" do
4545
ps = PropertyStruct.new(ports: [8080, 8081, 8082])
4646
expect(ps.ports.map(&:to_s)).to eq(%w[8080 8081 8082])
4747
end
4848

49-
it 'supports string operations' do
50-
ps = PropertyStruct.new(url: 'https://example.com')
51-
expect(ps.url.start_with?('https')).to be true
52-
expect(ps.url.split('://')).to eq(['https', 'example.com'])
49+
it "supports string operations" do
50+
ps = PropertyStruct.new(url: "https://example.com")
51+
expect(ps.url.start_with?("https")).to be true
52+
expect(ps.url.split("://")).to eq(["https", "example.com"])
5353
end
5454

55-
it 'supports hash operations via direct access' do
56-
ps = PropertyStruct.new(config: { a: 1, b: 2, c: 3 })
55+
it "supports hash operations via direct access" do
56+
ps = PropertyStruct.new(config: {a: 1, b: 2, c: 3})
5757
expect(ps.config.a).to eq(1)
5858
expect(ps.config.b).to eq(2)
5959
expect(ps.config.c).to eq(3)
6060
end
6161

62-
it 'supports nil and empty checks' do
63-
ps = PropertyStruct.new(empty_string: '', nil_value: nil, filled: 'data')
62+
it "supports nil and empty checks" do
63+
ps = PropertyStruct.new(empty_string: "", nil_value: nil, filled: "data")
6464
expect(ps.empty_string.empty?).to be true
6565
expect(ps.nil_value.nil?).to be true
6666
expect(ps.filled.nil?).to be false
6767
end
6868
end
6969

70-
describe 'compatibility across Ruby versions' do
71-
it 'works with ERB rendering' do
70+
describe "compatibility across Ruby versions" do
71+
it "works with ERB rendering" do
7272
template = ERB.new("<%= ps.name.upcase %>: <%= ps.ports.join(',') %>")
73-
ps = PropertyStruct.new(name: 'service', ports: [80, 443, 8080])
73+
ps = PropertyStruct.new(name: "service", ports: [80, 443, 8080])
7474
result = template.result(binding)
75-
expect(result).to eq('SERVICE: 80,443,8080')
75+
expect(result).to eq("SERVICE: 80,443,8080")
7676
end
7777

78-
it 'maintains OpenStruct API compatibility' do
78+
it "maintains OpenStruct API compatibility" do
7979
# Test that PropertyStruct can be used as a drop-in replacement for OpenStruct
80-
ps = PropertyStruct.new(field1: 'value1', field2: 'value2')
80+
ps = PropertyStruct.new(field1: "value1", field2: "value2")
8181
expect(ps).to respond_to(:field1)
8282
expect(ps).to respond_to(:field2)
83-
expect(ps.field1).to eq('value1')
84-
expect(ps.field2).to eq('value2')
83+
expect(ps.field1).to eq("value1")
84+
expect(ps.field2).to eq("value2")
8585
end
8686
end
8787
end

0 commit comments

Comments
 (0)