Class: Ronin::Platform::Extension
Included Modules
Contextify, Ronin::Static::Finders, Ronin::UI::Output::Helpers
Attributes
Instance Attributes
| name | [R] | public |
Name of extension. |
|---|---|---|---|
| paths | [R] | public |
Paths of similar extensions. |
Constants
- EXTENSION_FILE
- 'extension.rb'
- LIB_DIR
- 'lib'
- STATIC_DIR
- 'static'
Constructor Summary
Creates a new Extension object.
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ronin/platform/extension.rb', line 81 def initialize(name,&block) @name = name.to_s @paths = [] @setup = false @toredown = true @setup_blocks = [] @teardown_blocks = [] instance_eval(&block) if block end |
Public Visibility
Public Instance Method Summary
| #exposed_methods |
Returns: Array |
|---|---|
| #has_method?(name) |
Searches for a public method with the specified name. Returns: Boolean |
| #include(name, &block) {|ext| ... } |
Includes all extensions with the matching name into the extension. Returns: Extension |
| #include_path(path, &block) {|ext| ... } |
Includes the extension at the specified path into the extension. Returns: Extension |
| #run(&block) {|ext| ... } |
Sets up the extension, passes the extension to the specified. Returns: Extension |
| #setup!(&block) {|ext| ... } |
Calls the setup blocks of the extension. Returns: Extension |
| #setup? |
Returns: Boolean |
| #static_paths(path, &block) | |
| #teardown!(&block) {|ext| ... } |
Run the teardown blocks of the extension. Returns: Extension |
| #tmp_dir |
The temporary directory for the extension. Returns: String |
| #to_s |
Returns: String |
| #toredown? |
Returns: Boolean |
Public Instance Methods Included from Ronin::Static::Finders
each_static_dir, each_static_file, each_static_path, find_static_dir, find_static_dirs, find_static_file, find_static_files, static_find, static_find_all, static_glob, static_glob_all
Public Instance Method Details
exposed_methods
166 167 168 |
# File 'lib/ronin/platform/extension.rb', line 166 def exposed_methods methods(false).map { |name| name.to_sym } end |
has_method?
Searches for a public method with the specified name.
184 185 186 |
# File 'lib/ronin/platform/extension.rb', line 184 def has_method?(name) exposed_methods.include?(name.to_sym) end |
include
Includes all extensions with the matching name into the extension.
110 111 112 113 114 115 116 117 |
# File 'lib/ronin/platform/extension.rb', line 110 def include(name,&block) Platform..extension_paths(name).each do |path| include_path(path) end block.call(self) if block return self end |
include_path
Includes the extension at the specified path into the extension.
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ronin/platform/extension.rb', line 137 def include_path(path,&block) path = File.(path) unless File.directory?(path) raise(ExtensionNotFound,"extension #{path.dump} is not a valid extension",caller) end # add to the search paths @paths << path extension_file = File.join(path,EXTENSION_FILE) if File.file?(extension_file) # instance_eval the extension block context_block = Extension.load_context_block(extension_file) if context_block catch_all { instance_eval(&context_block) } end end block.call(self) if block return self end |
run
Sets up the extension, passes the extension to the specified block and then tears down the extension.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/ronin/platform/extension.rb', line 297 def run(&block) setup! if block if block.arity == 1 block.call(self) else block.call() end end teardown! return self end |
setup!
Calls the setup blocks of the extension.
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ronin/platform/extension.rb', line 210 def setup!(&block) unless @setup @setup_blocks.each do |setup_block| setup_block.call(self) if setup_block end @setup = true @toredown = false end block.call(self) if block return self end |
setup?
228 229 230 |
# File 'lib/ronin/platform/extension.rb', line 228 def setup? @setup == true end |
static_paths
323 324 325 326 327 328 329 330 331 332 |
# File 'lib/ronin/platform/extension.rb', line 323 def static_paths(path,&block) @paths.each do |dir| static_dir = File.join(dir,STATIC_DIR) next unless File.directory?(static_dir) block.call(File.join(static_dir,path)) end super(path,&block) end |
teardown!
Run the teardown blocks of the extension.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/ronin/platform/extension.rb', line 254 def teardown!(&block) block.call(self) if block unless @toredown @teardown_blocks.each do |teardown_block| teardown_block.call(self) if teardown_block end @toredown = true @setup = false end return self end |
tmp_dir
The temporary directory for the extension.
319 320 321 |
# File 'lib/ronin/platform/extension.rb', line 319 def tmp_dir @tmp_dir ||= Config.tmp_dir(@name) end |
to_s
338 339 340 |
# File 'lib/ronin/platform/extension.rb', line 338 def to_s @name.to_s end |
toredown?
273 274 275 |
# File 'lib/ronin/platform/extension.rb', line 273 def toredown? @toredown == true end |
Protected Visibility
Protected Instance Method Summary
| #attr_accessor(*names) |
Defines reader and writer methods for the listed instance variables. |
|---|---|
| #attr_reader(*names) |
Defines reader methods for the listed instance variables. |
| #attr_writer(*names) |
Defines writer methods for the listed instance variables. |
| #setup(&block) |
Adds the specified block to the list of blocks to run in order. |
| #teardown(&block) |
Adds the specified block to the list of blocks to run in order. |
Protected Instance Methods Included from Ronin::UI::Output::Helpers
Protected Instance Method Details
attr_accessor
Defines reader and writer methods for the listed instance variables.
411 412 413 414 |
# File 'lib/ronin/platform/extension.rb', line 411 def attr_accessor(*names) attr_reader(*names) attr_writer(*names) end |
attr_reader
Defines reader methods for the listed instance variables.
356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/ronin/platform/extension.rb', line 356 def attr_reader(*names) names.each do |name| name = name.to_sym ivar_name = "@#{name}" instance_eval %{ def #{name} instance_variable_get(#{ivar_name.dump}) end } end end |
attr_writer
Defines writer methods for the listed instance variables.
381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/ronin/platform/extension.rb', line 381 def attr_writer(*names) names.each do |name| name = name.to_sym ivar_name = "@#{name}" instance_eval %{ def #{name}=(value) instance_variable_set(#{ivar_name.dump},value) end } end end |
setup
Adds the specified block to the list of blocks to run in order to properly setup the extension.
425 426 427 428 |
# File 'lib/ronin/platform/extension.rb', line 425 def setup(&block) @setup_blocks << block if block return self end |
teardown
Adds the specified block to the list of blocks to run in order to properly tear-down the extension.
439 440 441 442 |
# File 'lib/ronin/platform/extension.rb', line 439 def teardown(&block) @teardown_blocks << block if block return self end |