Class: Dokno::Config
- Inherits:
-
Object
- Object
- Dokno::Config
- Defined in:
- lib/dokno/config/config.rb
Constant Summary collapse
- TAG_WHITELIST =
Defaults
%w[code img h1 h2 h3 h4 h5 h6 a em u i b strong ol ul li table thead tbody tfoot tr th td blockquote hr br p]
- ATTR_WHITELIST =
%w[src alt title href target]
- APP_USER_OBJECT =
'current_user'
- APP_USER_AUTH_METHOD =
:admin?
- APP_USER_NAME_METHOD =
:name
- ARTICLE_REVIEW_PERIOD =
1.year
- ARTICLE_REVIEW_PROMPT_DAYS =
30
Instance Attribute Summary collapse
-
#app_name ⇒ Object
Dokno configuration options.
-
#app_user_auth_method ⇒ Object
Returns the value of attribute app_user_auth_method.
-
#app_user_name_method ⇒ Object
Returns the value of attribute app_user_name_method.
-
#app_user_object ⇒ Object
Returns the value of attribute app_user_object.
-
#article_review_period ⇒ Object
Returns the value of attribute article_review_period.
-
#article_review_prompt_days ⇒ Object
Returns the value of attribute article_review_prompt_days.
-
#attr_whitelist ⇒ Object
Returns the value of attribute attr_whitelist.
-
#tag_whitelist ⇒ Object
Returns the value of attribute tag_whitelist.
Instance Method Summary collapse
- #config_error_prefix ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #validate ⇒ Object
- #validate_config_option(option:, expected_class:, example:) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dokno/config/config.rb', line 58 def initialize self.app_name = Rails.application.class.module_parent.name.underscore.humanize.upcase self.tag_whitelist = TAG_WHITELIST self.attr_whitelist = ATTR_WHITELIST self.app_user_object = APP_USER_OBJECT self.app_user_auth_method = APP_USER_AUTH_METHOD self.app_user_name_method = APP_USER_NAME_METHOD self.article_review_period = ARTICLE_REVIEW_PERIOD self.article_review_prompt_days = ARTICLE_REVIEW_PROMPT_DAYS end |
Instance Attribute Details
#app_name ⇒ Object
Dokno configuration options
app_name (String)
Host app name for display within the mounted dashboard
tag_whitelist (Enumerable)
Determines which HTML tags are allowed in Article markdown
attr_whitelist (Enumerable)
Determines which HTML attributes are allowed in Article markdown
app_user_object (String)
Host app's user object
app_user_auth_method (Symbol)
Host app's user object method to be used for edit authorization.
Should return boolean
app_user_name_method (Symbol)
Host app's user object method that returns the authenticated user's name or other
identifier that will be included in change log events.
Should return a string
article_review_period (ActiveSupport::Duration)
The amount of time before articles should be reviewed for accuracy/relevance
article_review_prompt_days (Integer)
The number of days prior to an article being up for review that users should be prompted
40 41 42 |
# File 'lib/dokno/config/config.rb', line 40 def app_name @app_name end |
#app_user_auth_method ⇒ Object
Returns the value of attribute app_user_auth_method.
44 45 46 |
# File 'lib/dokno/config/config.rb', line 44 def app_user_auth_method @app_user_auth_method end |
#app_user_name_method ⇒ Object
Returns the value of attribute app_user_name_method.
45 46 47 |
# File 'lib/dokno/config/config.rb', line 45 def app_user_name_method @app_user_name_method end |
#app_user_object ⇒ Object
Returns the value of attribute app_user_object.
43 44 45 |
# File 'lib/dokno/config/config.rb', line 43 def app_user_object @app_user_object end |
#article_review_period ⇒ Object
Returns the value of attribute article_review_period.
46 47 48 |
# File 'lib/dokno/config/config.rb', line 46 def article_review_period @article_review_period end |
#article_review_prompt_days ⇒ Object
Returns the value of attribute article_review_prompt_days.
47 48 49 |
# File 'lib/dokno/config/config.rb', line 47 def article_review_prompt_days @article_review_prompt_days end |
#attr_whitelist ⇒ Object
Returns the value of attribute attr_whitelist.
42 43 44 |
# File 'lib/dokno/config/config.rb', line 42 def attr_whitelist @attr_whitelist end |
#tag_whitelist ⇒ Object
Returns the value of attribute tag_whitelist.
41 42 43 |
# File 'lib/dokno/config/config.rb', line 41 def tag_whitelist @tag_whitelist end |
Instance Method Details
#config_error_prefix ⇒ Object
84 85 86 |
# File 'lib/dokno/config/config.rb', line 84 def config_error_prefix "Dokno configuration error (check config/initializers/dokno.rb):" end |
#validate ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/dokno/config/config.rb', line 69 def validate validate_config_option(option: 'tag_whitelist', expected_class: Enumerable, example: '%w[a p strong]') validate_config_option(option: 'attr_whitelist', expected_class: Enumerable, example: '%w[class href]') validate_config_option(option: 'app_user_object', expected_class: String, example: 'current_user') validate_config_option(option: 'app_user_auth_method', expected_class: Symbol, example: ':admin?') validate_config_option(option: 'app_user_name_method', expected_class: Symbol, example: ':name') validate_config_option(option: 'article_review_period', expected_class: ActiveSupport::Duration, example: '1.year') validate_config_option(option: 'article_review_prompt_days', expected_class: Integer, example: '30') end |
#validate_config_option(option:, expected_class:, example:) ⇒ Object
79 80 81 82 |
# File 'lib/dokno/config/config.rb', line 79 def validate_config_option(option:, expected_class:, example:) return unless !send(option.to_sym).is_a? expected_class raise Error::Config, "#{config_error_prefix} #{option} must be #{expected_class}, e.g. #{example}" end |