Class: Contentful::Moderator::Config
- Inherits:
-
Object
- Object
- Contentful::Moderator::Config
- Defined in:
- lib/contentful/moderator/config.rb
Constant Summary collapse
- DEFAULT_PORT =
33123- DEFAULT_ENDPOINT =
'/moderator'
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #authors ⇒ Object
- #configure_mailer ⇒ Object
- #content_types ⇒ Object
- #editors ⇒ Object
- #endpoint ⇒ Object
-
#initialize(config = {}) ⇒ Config
constructor
A new instance of Config.
- #mail_origin ⇒ Object
- #mailer_configured? ⇒ Boolean
- #mailer_password ⇒ Object
- #mailer_settings ⇒ Object
- #mailer_username ⇒ Object
- #port ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ Config
Returns a new instance of Config.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/contentful/moderator/config.rb', line 16 def initialize(config = {}) @config = Hashie::Mash.new(config) @config.port = (ENV.key?('PORT') ? ENV['PORT'].to_i : DEFAULT_PORT) unless @config.port? @config.endpoint = DEFAULT_ENDPOINT unless @config.endpoint? fail ':content_types not set' unless @config.content_types? && !@config.content_types.empty? fail ':authors not set' unless @config. && !@config..empty? fail ':editors not set' unless @config.editors? && !@config.editors.empty? fail ':mail_origin not set' unless @config.mail_origin? fail ':mailer_settings not properly configured' unless mailer_configured? configure_mailer end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/contentful/moderator/config.rb', line 10 def config @config end |
Class Method Details
.load(path) ⇒ Object
12 13 14 |
# File 'lib/contentful/moderator/config.rb', line 12 def self.load(path) new(Hashie::Mash.load(path)) end |
Instance Method Details
#authors ⇒ Object
39 40 41 |
# File 'lib/contentful/moderator/config.rb', line 39 def @config. end |
#configure_mailer ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/contentful/moderator/config.rb', line 89 def configure_mailer this = self Mail.defaults do delivery_method this.config.mailer_settings.connection_type.to_sym, { address: this.config.mailer_settings.address, port: this.config.mailer_settings.port, domain: this.config.mailer_settings.domain, user_name: this.mailer_username, password: this.mailer_password, authentication: this.config.mailer_settings.authentication, enable_starttls_auto: this.config.mailer_settings.enable_starttls_auto, openssl_verify_mode: this.config.mailer_settings.openssl_verify_mode, ssl: this.config.mailer_settings.ssl, tls: this.config.mailer_settings.tls } end end |
#content_types ⇒ Object
47 48 49 |
# File 'lib/contentful/moderator/config.rb', line 47 def content_types @config.content_types end |
#editors ⇒ Object
43 44 45 |
# File 'lib/contentful/moderator/config.rb', line 43 def editors @config.editors end |
#endpoint ⇒ Object
35 36 37 |
# File 'lib/contentful/moderator/config.rb', line 35 def endpoint @config.endpoint end |
#mail_origin ⇒ Object
51 52 53 |
# File 'lib/contentful/moderator/config.rb', line 51 def mail_origin @config.mail_origin end |
#mailer_configured? ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/contentful/moderator/config.rb', line 69 def mailer_configured? return false unless @config.mailer_settings? return false unless @config.mailer_settings.connection_type return false unless @config.mailer_settings.address return false unless @config.mailer_settings.port return false unless @config.mailer_settings.domain # Optionals - Explicitly left here as reminder # # return false unless @config.mailer_settings.user_name # return false unless @config.mailer_settings.password # return false unless @config.mailer_settings.authentication # return false unless @config.mailer_settings.enable_starttls_auto # return false unless @config.mailer_settings.openssl_verify_mode # return false unless @config.mailer_settings.ssl # return false unless @config.mailer_settings.tls true end |
#mailer_password ⇒ Object
64 65 66 67 |
# File 'lib/contentful/moderator/config.rb', line 64 def mailer_password return ENV['ENV_MAILER_PASSWORD'] if config.mailer_settings.password == "'env_mailer_password'" config.mailer_settings.password end |
#mailer_settings ⇒ Object
55 56 57 |
# File 'lib/contentful/moderator/config.rb', line 55 def mailer_settings @config.mailer_settings end |
#mailer_username ⇒ Object
59 60 61 62 |
# File 'lib/contentful/moderator/config.rb', line 59 def mailer_username return ENV['ENV_MAILER_USERNAME'] if config.mailer_settings.user_name == "'env_mailer_username'" config.mailer_settings.user_name end |
#port ⇒ Object
31 32 33 |
# File 'lib/contentful/moderator/config.rb', line 31 def port @config.port end |