class Noticent::Config::Builder

Public Class Methods

new(options = {}, &block) click to toggle source
# File lib/noticent/config.rb, line 165
def initialize(options = {}, &block)
  @options = options
  @config = Noticent::Config.new(options)
  raise BadConfiguration, "no OptInProvider configured" if @config.opt_in_provider.nil?

  instance_eval(&block) if block_given?

  @config.instance_variable_set(:@options, @options)
end

Public Instance Methods

base_dir=(value) click to toggle source
# File lib/noticent/config.rb, line 179
def base_dir=(value)
  @options[:base_dir] = value
end
base_module_name=(value) click to toggle source
# File lib/noticent/config.rb, line 183
def base_module_name=(value)
  @options[:base_module_name] = value
end
build() click to toggle source
# File lib/noticent/config.rb, line 175
def build
  @config
end
channel(name, group: :default, klass: nil, &block) click to toggle source
# 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) click to toggle source
# File lib/noticent/config.rb, line 195
def halt_on_error=(value)
  @options[:halt_on_error] = value
end
hooks() click to toggle source
# 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) click to toggle source
# File lib/noticent/config.rb, line 191
def logger=(value)
  @options[:logger] = value
end
opt_in_provider=(value) click to toggle source
# File lib/noticent/config.rb, line 187
def opt_in_provider=(value)
  @options[:opt_in_provider] = value
end
product(name, &block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/noticent/config.rb, line 203
def use_sub_modules=(value)
  @options[:use_sub_modules] = value
end