Class: Pione::LiterateAction::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/literate-action/handler.rb

Overview

Handler handles action documents.

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ Handler

Returns a new instance of Handler.



5
6
7
8
# File 'lib/pione/literate-action/handler.rb', line 5

def initialize(action)
  @lang = action[:lang] || "sh"
  @content = action[:content]
end

Instance Method Details

#execute(options = {}) ⇒ Boolean

Execute the action.

Parameters:

  • options (Hash) (defaults to: {})

    the options

Options Hash (options):

  • :domain_dump (DomainDump)

    domain dump

  • :chdir (Loacation)

    the location of working directory for action

  • :out (Location)

    the file writing STDOUT

Returns:

  • (Boolean)

    true if the action succeeded



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pione/literate-action/handler.rb', line 27

def execute(options={})
  location = Location[Temppath.create]
  location.write(("#!/usr/bin/env %s\n" % @lang) + textize(options[:domain_dump]))
  location.path.chmod(0700)

  _options = {}
  _options[:chdir] = options[:chdir] ? options[:chdir].path.to_s : Location[Global.pwd].path.to_s
  _options[:out] = options[:out].path.to_s if options.has_key?(:out)

  return system(location.path.to_s, _options)
end

#textize(domain_dump) ⇒ Object

Convert the action to a string.



11
12
13
# File 'lib/pione/literate-action/handler.rb', line 11

def textize(domain_dump)
  @content.to_s
end