Class: Noticent::Config
- Inherits:
-
Object
- Object
- Noticent::Config
- Defined in:
- lib/noticent/config.rb
Defined Under Namespace
Classes: Builder
Instance Attribute Summary collapse
-
#alerts ⇒ Object
readonly
Returns the value of attribute alerts.
-
#channel_groups ⇒ Object
readonly
Returns the value of attribute channel_groups.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#products ⇒ Object
readonly
Returns the value of attribute products.
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Instance Method Summary collapse
- #alert_channels(alert_name) ⇒ Object
- #alerts_by_scope(scope) ⇒ Object
- #base_dir ⇒ Object
- #base_module_name ⇒ Object
- #channel_dir ⇒ Object
- #channels_by_group(group) ⇒ Object
- #create_dynamics ⇒ Object
- #default_value ⇒ Object
- #halt_on_error ⇒ Object
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #logger ⇒ Object
- #opt_in_provider ⇒ Object
- #payload_dir ⇒ Object
- #products_by_alert(alert_name) ⇒ Object
- #scope_dir ⇒ Object
- #skip_alert_with_no_subscribers ⇒ Object
- #use_sub_modules ⇒ Object
- #validate! ⇒ Object
- #view_dir ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
67 68 69 70 |
# File 'lib/noticent/config.rb', line 67 def initialize( = {}) @options = @products = {} end |
Instance Attribute Details
#alerts ⇒ Object (readonly)
Returns the value of attribute alerts.
63 64 65 |
# File 'lib/noticent/config.rb', line 63 def alerts @alerts end |
#channel_groups ⇒ Object (readonly)
Returns the value of attribute channel_groups.
65 66 67 |
# File 'lib/noticent/config.rb', line 65 def channel_groups @channel_groups end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
61 62 63 |
# File 'lib/noticent/config.rb', line 61 def channels @channels end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
60 61 62 |
# File 'lib/noticent/config.rb', line 60 def hooks @hooks end |
#products ⇒ Object (readonly)
Returns the value of attribute products.
64 65 66 |
# File 'lib/noticent/config.rb', line 64 def products @products end |
#scopes ⇒ Object (readonly)
Returns the value of attribute scopes.
62 63 64 |
# File 'lib/noticent/config.rb', line 62 def scopes @scopes end |
Instance Method Details
#alert_channels(alert_name) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/noticent/config.rb', line 78 def alert_channels(alert_name) alert = @alerts[alert_name] raise ArgumentError, "no alert #{alert_name} found" if alert.nil? return [] if alert.notifiers.nil? alert.notifiers.values.collect { |notifier| channels_by_group(notifier.channel_group).uniq }.uniq.flatten end |
#alerts_by_scope(scope) ⇒ Object
93 94 95 96 97 |
# File 'lib/noticent/config.rb', line 93 def alerts_by_scope(scope) return [] if @alerts.nil? @alerts.values.select { |x| x.scope.name == scope } end |
#base_dir ⇒ Object
99 100 101 |
# File 'lib/noticent/config.rb', line 99 def base_dir @options[:base_dir] end |
#base_module_name ⇒ Object
103 104 105 |
# File 'lib/noticent/config.rb', line 103 def base_module_name @options[:base_module_name] end |
#channel_dir ⇒ Object
139 140 141 |
# File 'lib/noticent/config.rb', line 139 def channel_dir File.join(base_dir, "channels") end |
#channels_by_group(group) ⇒ Object
72 73 74 75 76 |
# File 'lib/noticent/config.rb', line 72 def channels_by_group(group) return [] if @channels.nil? @channels.values.select { |x| x.group == group } end |
#create_dynamics ⇒ Object
147 148 149 150 151 152 153 154 155 156 |
# File 'lib/noticent/config.rb', line 147 def create_dynamics return if alerts.nil? alerts.keys.each do |alert| const_name = "ALERT_#{alert.to_s.upcase}" next if Noticent.const_defined?(const_name) Noticent.const_set(const_name, alert) end end |
#default_value ⇒ Object
123 124 125 |
# File 'lib/noticent/config.rb', line 123 def default_value @options[:default_value].nil? ? false : @options[:default_value] end |
#halt_on_error ⇒ Object
115 116 117 |
# File 'lib/noticent/config.rb', line 115 def halt_on_error @options[:halt_on_error].nil? ? false : @options[:halt_on_error] end |
#logger ⇒ Object
111 112 113 |
# File 'lib/noticent/config.rb', line 111 def logger @options[:logger] || Logger.new(STDOUT) end |
#opt_in_provider ⇒ Object
107 108 109 |
# File 'lib/noticent/config.rb', line 107 def opt_in_provider @options[:opt_in_provider] || Noticent::ActiveRecordOptInProvider.new end |
#payload_dir ⇒ Object
131 132 133 |
# File 'lib/noticent/config.rb', line 131 def payload_dir File.join(base_dir, "payloads") end |
#products_by_alert(alert_name) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/noticent/config.rb', line 86 def products_by_alert(alert_name) alert = @alerts[alert_name] raise ArgumentError, "no alert #{alert_name} found" if alert.nil? alert.products end |
#scope_dir ⇒ Object
135 136 137 |
# File 'lib/noticent/config.rb', line 135 def scope_dir File.join(base_dir, "scopes") end |
#skip_alert_with_no_subscribers ⇒ Object
119 120 121 |
# File 'lib/noticent/config.rb', line 119 def skip_alert_with_no_subscribers @options[:skip_alert_with_no_subscribers].nil? ? false : @options[:skip_alert_with_no_subscribers] end |
#use_sub_modules ⇒ Object
127 128 129 |
# File 'lib/noticent/config.rb', line 127 def use_sub_modules @options[:use_sub_modules].nil? ? false : @options[:use_sub_modules] end |
#validate! ⇒ Object
158 159 160 161 162 |
# File 'lib/noticent/config.rb', line 158 def validate! # check all scopes scopes&.values&.each(&:validate!) alerts&.values&.each(&:validate!) end |
#view_dir ⇒ Object
143 144 145 |
# File 'lib/noticent/config.rb', line 143 def view_dir File.join(base_dir, "views") end |