Class: Blur::SuperScript

Inherits:
Object
  • Object
show all
Defined in:
library/blur/script.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.authorsObject Also known as: author

Returns the value of attribute authors.



56
57
58
# File 'library/blur/script.rb', line 56

def authors
  @authors
end

.descriptionObject

Returns the value of attribute description.



56
57
58
# File 'library/blur/script.rb', line 56

def description
  @description
end

.eventsObject

Returns the value of attribute events.



56
57
58
# File 'library/blur/script.rb', line 56

def events
  @events
end

.nameObject

Returns the value of attribute name.



56
57
58
# File 'library/blur/script.rb', line 56

def name
  @name
end

.versionObject

Returns the value of attribute version.



56
57
58
# File 'library/blur/script.rb', line 56

def version
  @version
end

Instance Attribute Details

#_client_refObject

Reference to the main client that holds the script.



128
129
130
# File 'library/blur/script.rb', line 128

def _client_ref
  @_client_ref
end

#cacheObject

Returns the value of attribute cache.



134
135
136
# File 'library/blur/script.rb', line 134

def cache
  @cache
end

#configObject

Script-specific configuration that is read from the main configuration file.



132
133
134
# File 'library/blur/script.rb', line 132

def config
  @config
end

Class Method Details

.Author(*authors) ⇒ Object Also known as: Authors

Sets the author.

Examples:

Author 'John Doe <[email protected]>'


62
63
64
# File 'library/blur/script.rb', line 62

def Author *authors
  @authors = authors
end

.deinitObject

Called right before the script is being removed from the list of superscripts.



125
# File 'library/blur/script.rb', line 125

def self.deinit; end

.Description(description) ⇒ Object

Sets the description.

Examples:

Description 'This is an example script.'


70
71
72
# File 'library/blur/script.rb', line 70

def Description description
  @description = description
end

.initObject

Called when when the superscript has been loaded and added to the list of superscripts.



121
# File 'library/blur/script.rb', line 121

def self.init; end

.inspectObject



111
112
113
# File 'library/blur/script.rb', line 111

def inspect
  %(#<SuperScript:0x#{object_id.to_s 16}>)
end

.register!(*args) ⇒ Object

Registers events to certain functions.

Examples:

register! message: :on_message, connection_ready: :connected


86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'library/blur/script.rb', line 86

def register! *args
  args.each do |events|
    case events
    when Hash
      events.each do |event, method_name|
        register_event! event, method_name
      end
    when Array
      register! *events
    when Symbol
      register_event! events
    end
  end
end

.register_event!(name, method_name = name) ⇒ Object

Adds the given event name and the name of the method to call once the event is emitted.



103
104
105
# File 'library/blur/script.rb', line 103

def register_event! name, method_name = name
  (@events[name] ||= []) << method_name
end

.to_sObject



107
108
109
# File 'library/blur/script.rb', line 107

def to_s
  inspect
end

.Version(version) ⇒ Object

Sets the version.

Examples:

Version '1.0.0'


78
79
80
# File 'library/blur/script.rb', line 78

def Version version
  @version = version
end

Instance Method Details

#inspectObject

Gets a human-readable representation of the script.



145
146
147
148
149
150
# File 'library/blur/script.rb', line 145

def inspect
  "#<Script(#{self.class.name.inspect}) " \
    "@author=#{self.class.author.inspect} " \
    "@version=#{self.class.version.inspect} " \
    "@description=#{self.class.description.inspect}>"
end

#script(name) ⇒ Object

Gets the instantiated script with name.



140
141
142
# File 'library/blur/script.rb', line 140

def script name
  _client_ref.scripts[name]
end

#to_sObject



152
153
154
# File 'library/blur/script.rb', line 152

def to_s
  inspect
end

#unloadedObject

Called right before the instance of the script is being removed.



137
# File 'library/blur/script.rb', line 137

def unloaded; end