Class: Noticent::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/noticent/config.rb

Defined Under Namespace

Classes: Builder

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {})
  @options = options
  @products = {}
end

Instance Attribute Details

#alertsObject (readonly)

Returns the value of attribute alerts.



63
64
65
# File 'lib/noticent/config.rb', line 63

def alerts
  @alerts
end

#channel_groupsObject (readonly)

Returns the value of attribute channel_groups.



65
66
67
# File 'lib/noticent/config.rb', line 65

def channel_groups
  @channel_groups
end

#channelsObject (readonly)

Returns the value of attribute channels.



61
62
63
# File 'lib/noticent/config.rb', line 61

def channels
  @channels
end

#hooksObject (readonly)

Returns the value of attribute hooks.



60
61
62
# File 'lib/noticent/config.rb', line 60

def hooks
  @hooks
end

#productsObject (readonly)

Returns the value of attribute products.



64
65
66
# File 'lib/noticent/config.rb', line 64

def products
  @products
end

#scopesObject (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

Raises:

  • (ArgumentError)


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_dirObject



99
100
101
# File 'lib/noticent/config.rb', line 99

def base_dir
  @options[:base_dir]
end

#base_module_nameObject



103
104
105
# File 'lib/noticent/config.rb', line 103

def base_module_name
  @options[:base_module_name]
end

#channel_dirObject



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_dynamicsObject



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_valueObject



123
124
125
# File 'lib/noticent/config.rb', line 123

def default_value
  @options[:default_value].nil? ? false : @options[:default_value]
end

#halt_on_errorObject



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

#loggerObject



111
112
113
# File 'lib/noticent/config.rb', line 111

def logger
  @options[:logger] || Logger.new(STDOUT)
end

#opt_in_providerObject



107
108
109
# File 'lib/noticent/config.rb', line 107

def opt_in_provider
  @options[:opt_in_provider] || Noticent::ActiveRecordOptInProvider.new
end

#payload_dirObject



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

Raises:

  • (ArgumentError)


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_dirObject



135
136
137
# File 'lib/noticent/config.rb', line 135

def scope_dir
  File.join(base_dir, "scopes")
end

#skip_alert_with_no_subscribersObject



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_modulesObject



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_dirObject



143
144
145
# File 'lib/noticent/config.rb', line 143

def view_dir
  File.join(base_dir, "views")
end