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.
-
#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?.
- #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.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/bible270/configuration.rb', line 134 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 @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.
31 32 33 |
# File 'lib/bible270/configuration.rb', line 31 def after_sign_in_path @after_sign_in_path end |
#after_sign_out_path ⇒ Object
Returns the value of attribute after_sign_out_path.
32 33 34 |
# File 'lib/bible270/configuration.rb', line 32 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.
129 130 131 |
# File 'lib/bible270/configuration.rb', line 129 def allow_reader_start_date @allow_reader_start_date end |
#app_name ⇒ Object
Public labels.
115 116 117 |
# File 'lib/bible270/configuration.rb', line 115 def app_name @app_name end |
#bible_version ⇒ Object
Default Bible translation and a builder for external passage links.
111 112 113 |
# File 'lib/bible270/configuration.rb', line 111 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.
74 75 76 |
# File 'lib/bible270/configuration.rb', line 74 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).
88 89 90 |
# File 'lib/bible270/configuration.rb', line 88 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.
92 93 94 |
# File 'lib/bible270/configuration.rb', line 92 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.
84 85 86 |
# File 'lib/bible270/configuration.rb', line 84 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).
80 81 82 |
# File 'lib/bible270/configuration.rb', line 80 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).
83 84 85 |
# File 'lib/bible270/configuration.rb', line 83 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.
77 78 79 |
# File 'lib/bible270/configuration.rb', line 77 def mailer_from @mailer_from end |
#omniauth_path_prefix ⇒ Object
OmniAuth's path_prefix, if you need to override it. Normally leave this
nil: the engine derives "
49 50 51 |
# File 'lib/bible270/configuration.rb', line 49 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).
44 45 46 |
# File 'lib/bible270/configuration.rb', line 44 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.
112 113 114 |
# File 'lib/bible270/configuration.rb', line 112 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).
132 133 134 |
# File 'lib/bible270/configuration.rb', line 132 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).
125 126 127 |
# File 'lib/bible270/configuration.rb', line 125 def start_date @start_date end |
#tagline ⇒ Object
Returns the value of attribute tagline.
116 117 118 |
# File 'lib/bible270/configuration.rb', line 116 def tagline @tagline end |
Instance Method Details
#any_sign_in_method? ⇒ Boolean
Any way at all for a new person to sign in?
97 98 99 |
# File 'lib/bible270/configuration.rb', line 97 def any_sign_in_method? email_sign_in? || omniauth_providers.any? end |
#email_sign_in? ⇒ Boolean
94 |
# File 'lib/bible270/configuration.rb', line 94 def email_sign_in? = !!@email_sign_in |
#label_for_provider(key) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/bible270/configuration.rb', line 103 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
67 |
# File 'lib/bible270/configuration.rb', line 67 def omniauth_provider_keys = omniauth_providers.map(&:first) |
#single_provider? ⇒ Boolean
101 |
# File 'lib/bible270/configuration.rb', line 101 def single_provider? = omniauth_providers.size == 1 |