Class: Controll::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/controll/event.rb

Defined Under Namespace

Modules: Helper Classes: InvalidError, Matcher

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args) ⇒ Event

Returns a new instance of Event.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
# 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

Class Attribute Details

.valid_typesObject



23
24
25
# File 'lib/controll/event.rb', line 23

def self.valid_types
  @valid_types ||= default_valid_types
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/controll/event.rb', line 8

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/controll/event.rb', line 8

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/controll/event.rb', line 8

def type
  @type
end

Class Method Details

.add_valid_types(*types) ⇒ Object



44
45
46
# 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_typesObject



19
20
21
# File 'lib/controll/event.rb', line 19

def self.default_valid_types
  [:notice, :error, :warning, :success]
end

.reset_typesObject



27
28
29
# File 'lib/controll/event.rb', line 27

def self.reset_types
  @valid_types = default_valid_types
end

.valid_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/controll/event.rb', line 40

def valid_type? type
  valid_types.map(&:to_sym).include? type.to_sym
end