Skip to content

Commit aabe849

Browse files
committed
maybe works
1 parent e18032f commit aabe849

File tree

8 files changed

+294
-9
lines changed

8 files changed

+294
-9
lines changed

Gemfile.lock

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
PATH
2+
remote: .
3+
specs:
4+
rails_erb_credentials (0.1.0)
5+
rails (> 7.1)
6+
7+
GEM
8+
remote: https://rubygems.org/
9+
specs:
10+
actioncable (7.2.1)
11+
actionpack (= 7.2.1)
12+
activesupport (= 7.2.1)
13+
nio4r (~> 2.0)
14+
websocket-driver (>= 0.6.1)
15+
zeitwerk (~> 2.6)
16+
actionmailbox (7.2.1)
17+
actionpack (= 7.2.1)
18+
activejob (= 7.2.1)
19+
activerecord (= 7.2.1)
20+
activestorage (= 7.2.1)
21+
activesupport (= 7.2.1)
22+
mail (>= 2.8.0)
23+
actionmailer (7.2.1)
24+
actionpack (= 7.2.1)
25+
actionview (= 7.2.1)
26+
activejob (= 7.2.1)
27+
activesupport (= 7.2.1)
28+
mail (>= 2.8.0)
29+
rails-dom-testing (~> 2.2)
30+
actionpack (7.2.1)
31+
actionview (= 7.2.1)
32+
activesupport (= 7.2.1)
33+
nokogiri (>= 1.8.5)
34+
racc
35+
rack (>= 2.2.4, < 3.2)
36+
rack-session (>= 1.0.1)
37+
rack-test (>= 0.6.3)
38+
rails-dom-testing (~> 2.2)
39+
rails-html-sanitizer (~> 1.6)
40+
useragent (~> 0.16)
41+
actiontext (7.2.1)
42+
actionpack (= 7.2.1)
43+
activerecord (= 7.2.1)
44+
activestorage (= 7.2.1)
45+
activesupport (= 7.2.1)
46+
globalid (>= 0.6.0)
47+
nokogiri (>= 1.8.5)
48+
actionview (7.2.1)
49+
activesupport (= 7.2.1)
50+
builder (~> 3.1)
51+
erubi (~> 1.11)
52+
rails-dom-testing (~> 2.2)
53+
rails-html-sanitizer (~> 1.6)
54+
activejob (7.2.1)
55+
activesupport (= 7.2.1)
56+
globalid (>= 0.3.6)
57+
activemodel (7.2.1)
58+
activesupport (= 7.2.1)
59+
activerecord (7.2.1)
60+
activemodel (= 7.2.1)
61+
activesupport (= 7.2.1)
62+
timeout (>= 0.4.0)
63+
activestorage (7.2.1)
64+
actionpack (= 7.2.1)
65+
activejob (= 7.2.1)
66+
activerecord (= 7.2.1)
67+
activesupport (= 7.2.1)
68+
marcel (~> 1.0)
69+
activesupport (7.2.1)
70+
base64
71+
bigdecimal
72+
concurrent-ruby (~> 1.0, >= 1.3.1)
73+
connection_pool (>= 2.2.5)
74+
drb
75+
i18n (>= 1.6, < 2)
76+
logger (>= 1.4.2)
77+
minitest (>= 5.1)
78+
securerandom (>= 0.3)
79+
tzinfo (~> 2.0, >= 2.0.5)
80+
ast (2.4.2)
81+
base64 (0.2.0)
82+
bigdecimal (3.1.8)
83+
builder (3.3.0)
84+
concurrent-ruby (1.3.4)
85+
connection_pool (2.4.1)
86+
crass (1.0.6)
87+
date (3.3.4)
88+
drb (2.2.1)
89+
erubi (1.13.0)
90+
globalid (1.2.1)
91+
activesupport (>= 6.1)
92+
i18n (1.14.6)
93+
concurrent-ruby (~> 1.0)
94+
io-console (0.7.2)
95+
irb (1.14.1)
96+
rdoc (>= 4.0.0)
97+
reline (>= 0.4.2)
98+
json (2.7.2)
99+
language_server-protocol (3.17.0.3)
100+
logger (1.6.1)
101+
loofah (2.22.0)
102+
crass (~> 1.0.2)
103+
nokogiri (>= 1.12.0)
104+
mail (2.8.1)
105+
mini_mime (>= 0.1.1)
106+
net-imap
107+
net-pop
108+
net-smtp
109+
marcel (1.0.4)
110+
mini_mime (1.1.5)
111+
minitest (5.25.1)
112+
net-imap (0.4.16)
113+
date
114+
net-protocol
115+
net-pop (0.1.2)
116+
net-protocol (0.2.2)
117+
timeout
118+
net-smtp (0.5.0)
119+
net-protocol
120+
nio4r (2.7.3)
121+
nokogiri (1.16.7-aarch64-linux)
122+
racc (~> 1.4)
123+
nokogiri (1.16.7-arm-linux)
124+
racc (~> 1.4)
125+
nokogiri (1.16.7-arm64-darwin)
126+
racc (~> 1.4)
127+
nokogiri (1.16.7-x86-linux)
128+
racc (~> 1.4)
129+
nokogiri (1.16.7-x86_64-darwin)
130+
racc (~> 1.4)
131+
nokogiri (1.16.7-x86_64-linux)
132+
racc (~> 1.4)
133+
parallel (1.26.3)
134+
parser (3.3.5.0)
135+
ast (~> 2.4.1)
136+
racc
137+
psych (5.1.2)
138+
stringio
139+
racc (1.8.1)
140+
rack (2.2.9)
141+
rack-session (1.0.2)
142+
rack (< 3)
143+
rack-test (2.1.0)
144+
rack (>= 1.3)
145+
rackup (1.0.0)
146+
rack (< 3)
147+
webrick
148+
rails (7.2.1)
149+
actioncable (= 7.2.1)
150+
actionmailbox (= 7.2.1)
151+
actionmailer (= 7.2.1)
152+
actionpack (= 7.2.1)
153+
actiontext (= 7.2.1)
154+
actionview (= 7.2.1)
155+
activejob (= 7.2.1)
156+
activemodel (= 7.2.1)
157+
activerecord (= 7.2.1)
158+
activestorage (= 7.2.1)
159+
activesupport (= 7.2.1)
160+
bundler (>= 1.15.0)
161+
railties (= 7.2.1)
162+
rails-dom-testing (2.2.0)
163+
activesupport (>= 5.0.0)
164+
minitest
165+
nokogiri (>= 1.6)
166+
rails-html-sanitizer (1.6.0)
167+
loofah (~> 2.21)
168+
nokogiri (~> 1.14)
169+
railties (7.2.1)
170+
actionpack (= 7.2.1)
171+
activesupport (= 7.2.1)
172+
irb (~> 1.13)
173+
rackup (>= 1.0.0)
174+
rake (>= 12.2)
175+
thor (~> 1.0, >= 1.2.2)
176+
zeitwerk (~> 2.6)
177+
rainbow (3.1.1)
178+
rake (13.2.1)
179+
rdoc (6.7.0)
180+
psych (>= 4.0.0)
181+
regexp_parser (2.9.2)
182+
reline (0.5.10)
183+
io-console (~> 0.5)
184+
rubocop (1.66.1)
185+
json (~> 2.3)
186+
language_server-protocol (>= 3.17.0)
187+
parallel (~> 1.10)
188+
parser (>= 3.3.0.2)
189+
rainbow (>= 2.2.2, < 4.0)
190+
regexp_parser (>= 2.4, < 3.0)
191+
rubocop-ast (>= 1.32.2, < 2.0)
192+
ruby-progressbar (~> 1.7)
193+
unicode-display_width (>= 2.4.0, < 3.0)
194+
rubocop-ast (1.32.3)
195+
parser (>= 3.3.1.0)
196+
ruby-progressbar (1.13.0)
197+
securerandom (0.3.1)
198+
stringio (3.1.1)
199+
thor (1.3.2)
200+
timeout (0.4.1)
201+
tzinfo (2.0.6)
202+
concurrent-ruby (~> 1.0)
203+
unicode-display_width (2.6.0)
204+
useragent (0.16.10)
205+
webrick (1.8.2)
206+
websocket-driver (0.7.6)
207+
websocket-extensions (>= 0.1.0)
208+
websocket-extensions (0.1.5)
209+
zeitwerk (2.6.18)
210+
211+
PLATFORMS
212+
aarch64-linux
213+
arm-linux
214+
arm64-darwin
215+
x86-linux
216+
x86_64-darwin
217+
x86_64-linux
218+
219+
DEPENDENCIES
220+
minitest (~> 5.16)
221+
rails_erb_credentials!
222+
rake (~> 13.0)
223+
rubocop (~> 1.21)
224+
225+
BUNDLED WITH
226+
2.5.13

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ require "rubocop/rake_task"
1010
RuboCop::RakeTask.new
1111

1212
task default: %i[test rubocop]
13+
14+
namespace :dummy do
15+
desc "Regenerate the dummy app"
16+
task :create do
17+
system "rails new test/dummy --skip-active-record --skip-test --skip-bundle --skip-spring --skip-bootsnap --skip-git"
18+
system "cd test/dummy && bundle install"
19+
end
20+
end

lib/rails_erb_credentials.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
# frozen_string_literal: true
22

3-
require_relative "rails_erb_credentials/version"
4-
5-
module RailsErbCredentials
6-
class Error < StandardError; end
7-
# Your code goes here...
8-
end
3+
require "rails_erb_credentials/version"
4+
require "rails_erb_credentials/initializer"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require "erb"
4+
5+
module RailsErbCredentials
6+
class EvaluatedCredentials
7+
def initialize(original_credentials)
8+
@original_credentials = original_credentials
9+
end
10+
11+
def method_missing(method_name, *args, &block)
12+
value = @original_credentials.public_send(method_name)
13+
if value.is_a?(String) && value.include?("<%=")
14+
ERB.new(value).result(binding)
15+
else
16+
value
17+
end
18+
end
19+
20+
def respond_to_missing?(method_name, include_private = false)
21+
@original_credentials.respond_to?(method_name) || super
22+
end
23+
end
24+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_erb_credentials/evaluated_credentials"
4+
module RailsErbCredentials
5+
# class Railtie < ::Rails::Railtie
6+
# initializer "rails_erb_credentials" do
7+
# Rails.application.config.before_initialize do
8+
# original_credentials = Rails.application.credentials
9+
# puts "original_credentials: #{original_credentials}"
10+
# Rails.application.credentials = EvaluatedCredentials.new(original_credentials)
11+
# puts "Rails.application.credentials: #{Rails.application.credentials.test}"
12+
# end
13+
# end
14+
# end
15+
end

rails_erb_credentials.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
3434
spec.require_paths = ["lib"]
3535

3636
# Uncomment to register a new dependency of your gem
37-
# spec.add_dependency "example-gem", "~> 1.0"
37+
spec.add_dependency "rails", "> 7.1"
3838

3939
# For more information and examples about making a new gem, check out our
4040
# guide at: https://bundler.io/guides/creating_gem.html

test/test_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# frozen_string_literal: true
22

3+
require "rails"
4+
require "rails/test_help"
5+
36
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
47
require "rails_erb_credentials"
58

69
require "minitest/autorun"
10+
11+
Minitest::Test.class_eval do
12+
def before_setup
13+
super
14+
ENV['TEST'] = 'test_secret'
15+
end
16+
end

test/test_rails_erb_credentials.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
# frozen_string_literal: true
22

33
require "test_helper"
4+
require "dummy/config/environment"
45

56
class TestRailsErbCredentials < Minitest::Test
7+
def setup
8+
9+
end
10+
611
def test_that_it_has_a_version_number
712
refute_nil ::RailsErbCredentials::VERSION
813
end
914

10-
def test_it_does_something_useful
11-
assert false
15+
def test_evaluates_erb_in_credentials
16+
ENV['TEST'] = "my_actual_secret"
17+
assert_equal "my_actual_secret", Rails.application.credentials.test
1218
end
1319
end

0 commit comments

Comments
 (0)