Class: RailsErbCredentials::EvaluatedCredentials
- Inherits:
-
Object
- Object
- RailsErbCredentials::EvaluatedCredentials
show all
- Defined in:
- lib/rails_erb_credentials/evaluated_credentials.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of EvaluatedCredentials.
7
8
9
|
# File 'lib/rails_erb_credentials/evaluated_credentials.rb', line 7
def initialize(original_credentials)
@original_credentials = original_credentials
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/rails_erb_credentials/evaluated_credentials.rb', line 11
def method_missing(method_name, *args, &block)
if @original_credentials.respond_to?(method_name)
value = @original_credentials.public_send(method_name, *args, &block)
evaluate_value(value)
else
super
end
end
|
Instance Method Details
#evaluate_value(value) ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/rails_erb_credentials/evaluated_credentials.rb', line 20
def evaluate_value(value)
if value.is_a?(Hash)
value.transform_values { |v| evaluate_value(v) }
elsif value.is_a?(String) && value.include?("<%=")
ERB.new(value).result(binding)
else
value
end
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/rails_erb_credentials/evaluated_credentials.rb', line 30
def respond_to_missing?(method_name, include_private = false)
@original_credentials.respond_to?(method_name, include_private) || super
end
|