Class: Noticent::Config::Builder
- Inherits:
-
Object
- Object
- Noticent::Config::Builder
- Defined in:
- lib/noticent/config.rb
Instance Method Summary collapse
- #base_dir=(value) ⇒ Object
- #base_module_name=(value) ⇒ Object
- #build ⇒ Object
- #channel(name, group: :default, klass: nil, &block) ⇒ Object
- #halt_on_error=(value) ⇒ Object
- #hooks ⇒ Object
-
#initialize(options = {}, &block) ⇒ Builder
constructor
A new instance of Builder.
- #logger=(value) ⇒ Object
- #opt_in_provider=(value) ⇒ Object
- #product(name, &block) ⇒ Object
- #scope(name, payload_class: nil, check_constructor: true, &block) ⇒ Object
- #skip_alert_with_no_subscribers=(value) ⇒ Object
- #use_sub_modules=(value) ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Builder
Returns a new instance of Builder.
165 166 167 168 169 170 171 172 173 |
# File 'lib/noticent/config.rb', line 165 def initialize( = {}, &block) @options = @config = Noticent::Config.new() raise BadConfiguration, "no OptInProvider configured" if @config.opt_in_provider.nil? instance_eval(&block) if block_given? @config.instance_variable_set(:@options, @options) end |
Instance Method Details
#base_dir=(value) ⇒ Object
179 180 181 |
# File 'lib/noticent/config.rb', line 179 def base_dir=(value) @options[:base_dir] = value end |
#base_module_name=(value) ⇒ Object
183 184 185 |
# File 'lib/noticent/config.rb', line 183 def base_module_name=(value) @options[:base_module_name] = value end |
#build ⇒ Object
175 176 177 |
# File 'lib/noticent/config.rb', line 175 def build @config end |
#channel(name, group: :default, klass: nil, &block) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/noticent/config.rb', line 232 def channel(name, group: :default, klass: nil, &block) channels = @config.instance_variable_get(:@channels) || {} channel_groups = @config.instance_variable_get(:@channel_groups) || [] raise BadConfiguration, "channel '#{name}' already defined" if channels.include? name raise BadConfiguration, "a channel group named '#{group}' already exists. channels and channel groups cannot have duplicates" if channel_groups.include? name channel_groups << group channel = Noticent::Definitions::Channel.new(@config, name, group: group, klass: klass) hooks.run(:pre_channel_registration, channel) channel.instance_eval(&block) if block_given? hooks.run(:post_channel_registration, channel) channels[name] = channel @config.instance_variable_set(:@channels, channels) @config.instance_variable_set(:@channel_groups, channel_groups.uniq) channel end |
#halt_on_error=(value) ⇒ Object
195 196 197 |
# File 'lib/noticent/config.rb', line 195 def halt_on_error=(value) @options[:halt_on_error] = value end |
#hooks ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/noticent/config.rb', line 207 def hooks if @config.hooks.nil? @config.instance_variable_set(:@hooks, Noticent::Definitions::Hooks.new) else @config.hooks end end |
#logger=(value) ⇒ Object
191 192 193 |
# File 'lib/noticent/config.rb', line 191 def logger=(value) @options[:logger] = value end |
#opt_in_provider=(value) ⇒ Object
187 188 189 |
# File 'lib/noticent/config.rb', line 187 def opt_in_provider=(value) @options[:opt_in_provider] = value end |
#product(name, &block) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/noticent/config.rb', line 215 def product(name, &block) products = @config.instance_variable_get(:@products) || {} raise BadConfiguration, "product #{name} already defined" if products[name] product = Noticent::Definitions::Product.new(@config, name) hooks.run(:pre_product_registration, product) product.instance_eval(&block) if block_given? hooks.run(:post_product_registration, product) products[name] = product @config.instance_variable_set(:@products, products) product end |
#scope(name, payload_class: nil, check_constructor: true, &block) ⇒ Object
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/noticent/config.rb', line 253 def scope(name, payload_class: nil, check_constructor: true, &block) scopes = @config.instance_variable_get(:@scopes) || {} raise BadConfiguration, "scope '#{name}' already defined" if scopes.include? name scope = Noticent::Definitions::Scope.new(@config, name, payload_class: payload_class, check_constructor: check_constructor) scope.instance_eval(&block) scopes[name] = scope @config.instance_variable_set(:@scopes, scopes) scope end |
#skip_alert_with_no_subscribers=(value) ⇒ Object
199 200 201 |
# File 'lib/noticent/config.rb', line 199 def skip_alert_with_no_subscribers=(value) @options[:skip_alert_with_no_subscribers] = value end |
#use_sub_modules=(value) ⇒ Object
203 204 205 |
# File 'lib/noticent/config.rb', line 203 def use_sub_modules=(value) @options[:use_sub_modules] = value end |