Class: Controll::Event
- Inherits:
-
Object
- Object
- Controll::Event
- Defined in:
- lib/controll/event.rb
Defined Under Namespace
Modules: Helper Classes: InvalidError, Matcher
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .add_valid_types(*types) ⇒ Object
- .default_valid_types ⇒ Object
- .reset_types ⇒ Object
- .valid_type?(type) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(name, *args) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(name, *args) ⇒ Event
Returns a new instance of Event.
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. @type = (extract_type(args.first) || [: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 [:type] == @type end |
Class Attribute Details
.valid_types ⇒ Object
23 24 25 |
# File 'lib/controll/event.rb', line 23 def self.valid_types @valid_types ||= default_valid_types end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/controll/event.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/controll/event.rb', line 8 def @options end |
#type ⇒ Object (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_types ⇒ Object
19 20 21 |
# File 'lib/controll/event.rb', line 19 def self.default_valid_types [:notice, :error, :warning, :success] end |
.reset_types ⇒ Object
27 28 29 |
# File 'lib/controll/event.rb', line 27 def self.reset_types @valid_types = default_valid_types end |
.valid_type?(type) ⇒ 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 |