Module: Ronin::Script

Includes:
UI::Output::Helpers
Defined in:
lib/ronin/script/script.rb,
lib/ronin/script/path.rb,
lib/ronin/script/testable.rb,
lib/ronin/script/buildable.rb,
lib/ronin/script/deployable.rb,
lib/ronin/script/exceptions/exception.rb,
lib/ronin/script/exceptions/not_built.rb,
lib/ronin/script/exceptions/test_failed.rb,
lib/ronin/script/exceptions/deploy_failed.rb

Overview

Script is a high-level module that enables a Class to load instances from files and cache them into the Database. Classes that include Script, may also include Script sub-modules that define behaviors of the Script Class:

Since:

  • 1.1.0

Defined Under Namespace

Modules: Buildable, ClassMethods, Deployable, InstanceMethods, Testable Classes: DeployFailed, Exception, NotBuilt, Path, TestFailed

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Since:

  • 1.1.0


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ronin/script/script.rb', line 66

def self.included(base)
  base.send :include, InstanceMethods,
                      Model,
                      Model::HasName,
                      Model::HasDescription,
                      Model::HasVersion,
                      Model::HasLicense,
                      Model::HasAuthors,
                      ObjectLoader,
                      DataPaths::Finders,
                      Parameters

  base.send :extend, ClassMethods

  base.module_eval do
    # The class-name of the cached object
    property :type, DataMapper::Property::Discriminator

    # The cached file of the object
    belongs_to :script_path, Ronin::Script::Path, :required => false
  end

  Path.has 1, base.relationship_name, base, :child_key => [:script_path_id]
end

.load_from(path) ⇒ Script

Loads a script from a file.

Parameters:

  • path (String)

    The path to the file.

Returns:

  • (Script)

    The loaded script.

Since:

  • 1.1.0


361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# File 'lib/ronin/script/script.rb', line 361

def Script.load_from(path)
  path = File.expand_path(path)
  script = ObjectLoader.load_objects(path).find do |obj|
    obj.class < Script
  end

  unless script
    raise("No cacheable object defined in #{path.dump}")
  end

  script.instance_variable_set('@script_loaded',true)
  script.script_path = Path.new(
    :path => path,
    :timestamp => File.mtime(path),
    :class_name => script.class.to_s
  )

  return script
end