Skip to content

Commit

Permalink
add code comments and bring back the singleton
Browse files Browse the repository at this point in the history
Using singleton avoids initialisation of the Settings class (which is mostly global)
  • Loading branch information
madhums committed Mar 12, 2024
1 parent 7270e97 commit d019de9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/views/includes/_footer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<%= link_to t('.home'), root_path %>
</li>
<li class="mt-3 mt-sm-2">
<%= link_to t('.contact'), "mailto:#{Settings.contact_email}" %>
<%= link_to t('.contact'), "mailto:#{Settings.instance.contact_email}" %>
</li>
<li class="mt-3 mt-sm-2">
<%= link_to t('.stories'), stories_path %>
Expand Down
18 changes: 14 additions & 4 deletions config/initializers/settings.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# The Settings class is a singleton class which holds all configuration
# which is accessed throughout the application outside of `config` files.
# These settings mostly include environemt variables and other global settings.
#
# Similar pattern and inspiration from:
# https://garrettdimon.com/journal/posts/unified-configuration-in-rails
#
# Usage: Settings.instance.contact_email
#

class Settings
class << self
def contact_email
ENV["DOMAIN_EMAIL_ADDRESS"]
end
include Singleton

def contact_email
ENV["DOMAIN_EMAIL_ADDRESS"]
end
end

0 comments on commit d019de9

Please sign in to comment.