Class: Bible270::Configuration
- Inherits:
-
Object
- Object
- Bible270::Configuration
- Defined in:
- lib/bible270/configuration.rb
Constant Summary collapse
- PROVIDER_LABELS =
Human labels for providers we know; anything else is titleised.
{ github: "GitHub", gitlab: "GitLab", google_oauth2: "Google", google: "Google", facebook: "Facebook", twitter: "Twitter", apple: "Apple", discord: "Discord", microsoft_graph: "Microsoft", azure_activedirectory_v2: "Microsoft", openid_connect: "OpenID Connect", saml: "SSO" }.freeze
Instance Attribute Summary collapse
-
#after_sign_in_path ⇒ Object
Where to send the reader after a successful sign-in / sign-out.
-
#after_sign_out_path ⇒ Object
Returns the value of attribute after_sign_out_path.
-
#allow_reader_start_date ⇒ Object
Whether an individual reader may set or change their own start date.
-
#app_name ⇒ Object
Public labels.
-
#bible_version ⇒ Object
Default Bible translation and a builder for external passage links.
-
#current_reader_resolver ⇒ Object
A callable (lambda) that receives the current controller and returns a Bible270::Reader (or nil).
-
#email_sign_in ⇒ Object
Offer sign-in by email link, so readers who don't have (or don't want to use) a GitHub/Google/etc.
-
#email_sign_in_ask_name ⇒ Object
Whether a reader may type the display name shown beside their reflections when signing in by email (otherwise it's derived from the address).
-
#email_sign_in_deliver_later ⇒ Object
Send the sign-in email via Active Job (deliver_later) instead of inline.
-
#email_sign_in_max_per_window ⇒ Object
Returns the value of attribute email_sign_in_max_per_window.
-
#email_sign_in_ttl ⇒ Object
How long a magic link stays valid (seconds).
-
#email_sign_in_window ⇒ Object
Simple abuse guard: at most N links per address per window (seconds).
-
#layout ⇒ Object
Layout used to render engine pages.
-
#mailer_from ⇒ Object
From: address for the sign-in email.
-
#mount_at ⇒ Object
Where the engine is mounted in the host application.
-
#omniauth_path_prefix ⇒ Object
OmniAuth's path_prefix, if you need to override it.
-
#omniauth_providers ⇒ Object
Providers to offer on the sign-in screen.
-
#parent_controller ⇒ Object
Controller the engine's controllers inherit from.
-
#passage_url_builder ⇒ Object
Returns the value of attribute passage_url_builder.
-
#require_sign_in_to_participate ⇒ Object
Only signed-in readers may check off and comment (viewing is always open).
-
#start_date ⇒ Object
Optional community-wide start date for the plan.
-
#tagline ⇒ Object
Returns the value of attribute tagline.
Instance Method Summary collapse
-
#any_sign_in_method? ⇒ Boolean
Any way at all for a new person to sign in?.
-
#auth_path_prefix ⇒ Object
The prefix OmniAuth's middleware should serve its routes under.
- #email_sign_in? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #label_for_provider(key) ⇒ Object
- #omniauth_provider_keys ⇒ Object
- #single_provider? ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/bible270/configuration.rb', line 162 def initialize @parent_controller = "ActionController::Base" @layout = "bible270/application" @current_reader_resolver = nil @after_sign_in_path = nil @after_sign_out_path = nil @bible_version = "ESV" @passage_url_builder = lambda do |reference, version| search = URI.encode_www_form_component(reference) version = URI.encode_www_form_component(version) "https://www.biblegateway.com/passage/?search=#{search}&version=#{version}" end @app_name = "Daily Bread" @tagline = "A 270-day journey through Scripture" @require_sign_in_to_participate = true self.mount_at = "/daily-bread" @start_date = nil @allow_reader_start_date = true self.omniauth_providers = [:github] @omniauth_path_prefix = nil @email_sign_in = true @mailer_from = "no-reply@example.com" @email_sign_in_ttl = 20 * 60 # 20 minutes @email_sign_in_window = 15 * 60 # 15 minutes @email_sign_in_max_per_window = 5 @email_sign_in_ask_name = true @email_sign_in_deliver_later = false end |
Instance Attribute Details
#after_sign_in_path ⇒ Object
Where to send the reader after a successful sign-in / sign-out.
59 60 61 |
# File 'lib/bible270/configuration.rb', line 59 def after_sign_in_path @after_sign_in_path end |
#after_sign_out_path ⇒ Object
Returns the value of attribute after_sign_out_path.
60 61 62 |
# File 'lib/bible270/configuration.rb', line 60 def after_sign_out_path @after_sign_out_path end |
#allow_reader_start_date ⇒ Object
Whether an individual reader may set or change their own start date. When false, everyone is pinned to config.start_date.
157 158 159 |
# File 'lib/bible270/configuration.rb', line 157 def allow_reader_start_date @allow_reader_start_date end |
#app_name ⇒ Object
Public labels.
143 144 145 |
# File 'lib/bible270/configuration.rb', line 143 def app_name @app_name end |
#bible_version ⇒ Object
Default Bible translation and a builder for external passage links.
139 140 141 |
# File 'lib/bible270/configuration.rb', line 139 def bible_version @bible_version end |
#current_reader_resolver ⇒ Object
A callable (lambda) that receives the current controller and returns a Bible270::Reader (or nil). Use this to bridge your host's users:
config.current_reader_resolver = ->(c) {
u = c.send(:current_user)
u && Bible270::Reader.for_owner(u, display_name: u.name, email: u.email)
}
Leave nil to use the built-in session-based sign-in (OmniAuth).
28 29 30 |
# File 'lib/bible270/configuration.rb', line 28 def current_reader_resolver @current_reader_resolver end |
#email_sign_in ⇒ Object
Offer sign-in by email link, so readers who don't have (or don't want to use) a GitHub/Google/etc. account can still take part. Requires the host app to have Action Mailer delivery configured.
102 103 104 |
# File 'lib/bible270/configuration.rb', line 102 def email_sign_in @email_sign_in end |
#email_sign_in_ask_name ⇒ Object
Whether a reader may type the display name shown beside their reflections when signing in by email (otherwise it's derived from the address).
116 117 118 |
# File 'lib/bible270/configuration.rb', line 116 def email_sign_in_ask_name @email_sign_in_ask_name end |
#email_sign_in_deliver_later ⇒ Object
Send the sign-in email via Active Job (deliver_later) instead of inline. Leave false unless you have a queue backend configured.
120 121 122 |
# File 'lib/bible270/configuration.rb', line 120 def email_sign_in_deliver_later @email_sign_in_deliver_later end |
#email_sign_in_max_per_window ⇒ Object
Returns the value of attribute email_sign_in_max_per_window.
112 113 114 |
# File 'lib/bible270/configuration.rb', line 112 def email_sign_in_max_per_window @email_sign_in_max_per_window end |
#email_sign_in_ttl ⇒ Object
How long a magic link stays valid (seconds).
108 109 110 |
# File 'lib/bible270/configuration.rb', line 108 def email_sign_in_ttl @email_sign_in_ttl end |
#email_sign_in_window ⇒ Object
Simple abuse guard: at most N links per address per window (seconds).
111 112 113 |
# File 'lib/bible270/configuration.rb', line 111 def email_sign_in_window @email_sign_in_window end |
#layout ⇒ Object
Layout used to render engine pages.
17 18 19 |
# File 'lib/bible270/configuration.rb', line 17 def layout @layout end |
#mailer_from ⇒ Object
From: address for the sign-in email.
105 106 107 |
# File 'lib/bible270/configuration.rb', line 105 def mailer_from @mailer_from end |
#mount_at ⇒ Object
Where the engine is mounted in the host application. Set this once, in config/initializers/bible270.rb, and use it everywhere the path is needed:
# config/routes.rb
mount Bible270::Engine, at: Bible270.config.mount_at
# config/initializers/omniauth.rb
path_prefix Bible270.config.auth_path_prefix
Accepts "daily-bread" or "/daily-bread"; stored with a leading slash and no trailing one.
41 42 43 |
# File 'lib/bible270/configuration.rb', line 41 def mount_at @mount_at end |
#omniauth_path_prefix ⇒ Object
OmniAuth's path_prefix, if you need to override it. Normally leave this
nil: the engine derives "
77 78 79 |
# File 'lib/bible270/configuration.rb', line 77 def omniauth_path_prefix @omniauth_path_prefix end |
#omniauth_providers ⇒ Object
Providers to offer on the sign-in screen. Accepts symbols, or pairs of [provider, label] when you want to override the displayed name:
config.omniauth_providers = [:github]
config.omniauth_providers = [:github, [:google_oauth2, "Google"]]
The host application supplies the matching strategy gems and registers them in the OmniAuth builder (see the README, or run the install generator).
72 73 74 |
# File 'lib/bible270/configuration.rb', line 72 def omniauth_providers @omniauth_providers end |
#parent_controller ⇒ Object
Controller the engine's controllers inherit from. Set this to your host's "::ApplicationController" if you want to share layout, auth and helpers.
14 15 16 |
# File 'lib/bible270/configuration.rb', line 14 def parent_controller @parent_controller end |
#passage_url_builder ⇒ Object
Returns the value of attribute passage_url_builder.
140 141 142 |
# File 'lib/bible270/configuration.rb', line 140 def passage_url_builder @passage_url_builder end |
#require_sign_in_to_participate ⇒ Object
Only signed-in readers may check off and comment (viewing is always open).
160 161 162 |
# File 'lib/bible270/configuration.rb', line 160 def require_sign_in_to_participate @require_sign_in_to_participate end |
#start_date ⇒ Object
Optional community-wide start date for the plan. Set this when everyone reads together as a cohort (e.g. a church starting on a set Sunday):
config.start_date = Date.new(2026, 9, 6) # or the string "2026-09-06"
Leave nil for an undated plan, where each reader's own start date applies (defaulting to the day they first check something off).
153 154 155 |
# File 'lib/bible270/configuration.rb', line 153 def start_date @start_date end |
#tagline ⇒ Object
Returns the value of attribute tagline.
144 145 146 |
# File 'lib/bible270/configuration.rb', line 144 def tagline @tagline end |
Instance Method Details
#any_sign_in_method? ⇒ Boolean
Any way at all for a new person to sign in?
125 126 127 |
# File 'lib/bible270/configuration.rb', line 125 def any_sign_in_method? email_sign_in? || omniauth_providers.any? end |
#auth_path_prefix ⇒ Object
The prefix OmniAuth's middleware should serve its routes under. Derived from mount_at unless omniauth_path_prefix is set explicitly.
52 53 54 55 56 |
# File 'lib/bible270/configuration.rb', line 52 def auth_path_prefix return omniauth_path_prefix if omniauth_path_prefix mount_at == "/" ? "/auth" : "#{mount_at}/auth" end |
#email_sign_in? ⇒ Boolean
122 |
# File 'lib/bible270/configuration.rb', line 122 def email_sign_in? = !!@email_sign_in |
#label_for_provider(key) ⇒ Object
131 132 133 134 135 136 |
# File 'lib/bible270/configuration.rb', line 131 def label_for_provider(key) found = omniauth_providers.find { |k, _| k.to_s == key.to_s } return found.last if found PROVIDER_LABELS[key.to_sym] || key.to_s.tr("_", " ").split.map(&:capitalize).join(" ") end |
#omniauth_provider_keys ⇒ Object
95 |
# File 'lib/bible270/configuration.rb', line 95 def omniauth_provider_keys = omniauth_providers.map(&:first) |
#single_provider? ⇒ Boolean
129 |
# File 'lib/bible270/configuration.rb', line 129 def single_provider? = omniauth_providers.size == 1 |