Module: Ronin::Script::InstanceMethods

Defined in:
lib/ronin/script/script.rb

Overview

Instance methods for an Ronin::Script.

Since:

  • 1.1.0

Instance Method Summary collapse

Instance Method Details

#cache { ... } ⇒ Boolean (protected)

Will call the given block only once, in order to prepare the object for caching.

Yields:

  • [] The block will be ran inside the object when the object is to be prepared for caching.

Returns:

  • (Boolean)

    Specifies whether the object was successfully prepared for caching.

Since:

  • 1.1.0


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.

Returns:

  • (Boolean)

    Specifies whether the object has been previously cached.

Since:

  • 1.1.0


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.

Parameters:

  • arguments (Array)

    Arguments for initializing the Script.

Since:

  • 1.1.0


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

#inspectString

Inspects both the properties and parameters of the Ronin Script.

Returns:

  • (String)

    The inspected Ronin Script.

Since:

  • 1.1.0


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.

Returns:

  • (Boolean)

    Indicates the original code was successfully loaded.

Since:

  • 1.1.0


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,.

Returns:

  • (Boolean)

    Specifies whether the object has been prepared to be cached,

Since:

  • 1.1.0


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.

Parameters:

  • arguments (Array)

    Optional arguments.

Since:

  • 1.1.0


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.

Returns:

  • (Boolean)

    Specifies whether the original code has been loaded into the object.

Since:

  • 1.1.0


206
207
208
# File 'lib/ronin/script/script.rb', line 206

def script_loaded?
  @script_loaded == true
end

#script_typeString

The script type.

Returns:

  • (String)

    The name of the script class.

Since:

  • 1.1.0


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_sString

Converts the script to a String.

Returns:

  • (String)

    The name and version of the script.

Since:

  • 1.1.0


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