class Obscenity::Config

Constants

DEFAULT_BLACKLIST
DEFAULT_WHITELIST

Attributes

replacement[RW]

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/obscenity/config.rb, line 9
def initialize
  yield(self) if block_given?
  validate_config_options
end

Public Instance Methods

blacklist() click to toggle source
# File lib/obscenity/config.rb, line 18
def blacklist
  @blacklist ||= DEFAULT_BLACKLIST
end
blacklist=(value) click to toggle source
# File lib/obscenity/config.rb, line 22
def blacklist=(value)
  @blacklist = value == :default ? DEFAULT_BLACKLIST : value
end
whitelist() click to toggle source
# File lib/obscenity/config.rb, line 26
def whitelist
  @whitelist ||= DEFAULT_WHITELIST
end
whitelist=(value) click to toggle source
# File lib/obscenity/config.rb, line 30
def whitelist=(value)
  @whitelist = value == :default ? DEFAULT_WHITELIST : value
end

Private Instance Methods

validate_config_options() click to toggle source
# File lib/obscenity/config.rb, line 35
def validate_config_options
  [@blacklist, @whitelist].each{ |content| validate_list_content(content) if content }
end
validate_list_content(content) click to toggle source
# File lib/obscenity/config.rb, line 39
def validate_list_content(content)
  case content
  when Array    then !content.empty?       || raise(Obscenity::EmptyContentList.new('Content array is empty.'))
  when String   then File.exists?(content) || raise(Obscenity::UnkownContentFile.new("Content file can't be found."))
  when Pathname then content.exist?        || raise(Obscenity::UnkownContentFile.new("Content file can't be found."))
  when Symbol   then content == :default   || raise(Obscenity::UnkownContent.new("The only accepted symbol is :default."))
  else
    raise Obscenity::UnkownContent.new("The content can be either an Array, Pathname, or String path to a .yml file.")
  end
end