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/not_built.rb,
lib/ronin/script/exceptions/exception.rb,
lib/ronin/script/exceptions/test_failed.rb,
lib/ronin/script/exceptions/build_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:

Defined Under Namespace

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

Class Method Summary (collapse)

Class Method Details

+ (Object) included(base)

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
90
91
92
# 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

    # Validations
    validates_uniqueness_of :version, :scope => [:name]
  end

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

+ (Script) load_from(path)

Loads a script from a file.

Parameters:

  • path (String)

    The path to the file.

Returns:

  • (Script)

    The loaded script.

Since:

  • 1.1.0



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

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