class Controll::Event
Attributes
valid_types[W]
name[R]
options[R]
type[R]
Public Class Methods
add_valid_types(*types)
click to toggle source
# File lib/controll/event.rb, line 44 def add_valid_types *types @valid_types += types if types.all? {|type| type.kind_of? Symbol} end
default_valid_types()
click to toggle source
# File lib/controll/event.rb, line 19 def self.default_valid_types [:notice, :error, :warning, :success] end
new(name, *args)
click to toggle source
# File lib/controll/event.rb, line 10 def initialize name, *args raise ArgumentError, "Event must have a name identifier" if name.blank? @name = name.to_sym @options = args.extract_options! @type = (extract_type(args.first) || options[:type] || :notice).to_sym raise ArgumentError, "Invalid type: #{@type} must be one of: #{self.class.valid_types}" unless self.class.valid_type? @type @options.delete(:type) if options[:type] == @type end
reset_types()
click to toggle source
# File lib/controll/event.rb, line 27 def self.reset_types @valid_types = default_valid_types end
valid_type?(type)
click to toggle source
# File lib/controll/event.rb, line 40 def valid_type? type valid_types.map(&:to_sym).include? type.to_sym end
valid_types()
click to toggle source
# File lib/controll/event.rb, line 23 def self.valid_types @valid_types ||= default_valid_types end
Protected Instance Methods
extract_type(arg)
click to toggle source
# File lib/controll/event.rb, line 51 def extract_type arg return arg.type if arg.respond_to? :type arg.to_sym if type? arg end
type?(arg)
click to toggle source
# File lib/controll/event.rb, line 56 def type? arg arg.kind_of?(String) || arg.kind_of?(Symbol) end