Module: Ronin::Script::InstanceMethods
- Defined in:
- lib/ronin/script/script.rb
Overview
Instance methods for an Ronin::Script.
Instance Method Summary collapse
-
#cache { ... } ⇒ Boolean
protected
Will call the given block only once, in order to prepare the object for caching.
-
#cached? ⇒ Boolean
private
Indicates whether the object has been cached.
-
#initialize(*arguments, &block) ⇒ Object
Initializes the Ronin Script.
-
#inspect ⇒ String
Inspects both the properties and parameters of the Ronin Script.
-
#load_script! ⇒ Boolean
private
Loads the code from the cached file for the object, and instance evaluates it into the object.
-
#prepared_for_cache? ⇒ Boolean
private
Specifies whether the object has been prepared to be cached,.
-
#run(*arguments) ⇒ Object
Default method which invokes the script.
-
#script_loaded? ⇒ Boolean
private
Determines if the original code, from the cache file, has been loaded into the object.
-
#script_type ⇒ String
The script type.
-
#to_s ⇒ String
Converts the script to a String.
Instance Method Details
#cache { ... } ⇒ Boolean (protected)
Will call the given block only once, in order to prepare the object for caching.
336 337 338 339 340 341 342 343 344 345 |
# File 'lib/ronin/script/script.rb', line 336 def cache if (block_given? && !(cached? || prepared_for_cache?)) @cache_prepared = true yield return true end return false end |
#cached? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Indicates whether the object has been cached.
255 256 257 |
# File 'lib/ronin/script/script.rb', line 255 def cached? (saved? && self.script_path) end |
#initialize(*arguments, &block) ⇒ Object
Initializes the Ronin Script.
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ronin/script/script.rb', line 169 def initialize(*arguments,&block) @script_loaded = false @cache_prepared = false if arguments.first.kind_of?(Hash) initialize_params(arguments.first) end super(*arguments,&block) end |
#inspect ⇒ String
Inspects both the properties and parameters of the Ronin Script.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/ronin/script/script.rb', line 300 def inspect body = [] self.attributes.each do |name,value| body << "#{name}: #{value.inspect}" end param_pairs = [] self.params.each do |name,param| param_pairs << "#{name}: #{param.value.inspect}" end body << "params: {#{param_pairs.join(', ')}}" return "#<#{self.class}: #{body.join(', ')}>" end |
#load_script! ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Loads the code from the cached file for the object, and instance evaluates it into the object.
221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ronin/script/script.rb', line 221 def load_script! if (cached? && !script_loaded?) block = self.class.load_object_block(self.script_path.path) @script_loaded = true instance_eval(&block) if block return true end return false end |
#prepared_for_cache? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Specifies whether the object has been prepared to be cached,.
241 242 243 |
# File 'lib/ronin/script/script.rb', line 241 def prepared_for_cache? @cache_prepared == true end |
#run(*arguments) ⇒ Object
Default method which invokes the script.
267 268 |
# File 'lib/ronin/script/script.rb', line 267 def run(*arguments) end |
#script_loaded? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if the original code, from the cache file, has been loaded into the object.
206 207 208 |
# File 'lib/ronin/script/script.rb', line 206 def script_loaded? @script_loaded == true end |
#script_type ⇒ String
The script type.
190 191 192 |
# File 'lib/ronin/script/script.rb', line 190 def script_type @script_type ||= self.class.base_model.name.split('::').last end |
#to_s ⇒ String
Converts the script to a String.
280 281 282 283 284 285 286 287 288 |
# File 'lib/ronin/script/script.rb', line 280 def to_s if (self.name && self.version) "#{self.name} #{self.version}" elsif self.name super elsif self.version self.version.to_s end end |