Parent

Syckle::Script

Syckle Script Domain

The DSL class is the heart of Syckle, it provides all the convenece methods that make Syckle services so convenient to write.

TODO: Better name?

Attributes

cli[RW]

The cli method provides delagated access to commandline arguments and options via the CLI interface.

io[RW]

Delagate input/output routines to IO object.

project[R]

POM::Project object.

shell[RW]

Delagate file operations to Shell.

Public Class Methods

new(options={}) click to toggle source
# File lib/syckle/script.rb, line 30
def initialize(options={})
  extend self

  @project = POM::Project.new(:lookup=>true) #, :load=>true)

  options.each do |k, v|
    send("#{k}=", v) if respond_to?("#{k}=")
  end

  @cli ||= CLI.new
  @io  ||= IO.new(@cli)

  path = @project.root || Dir.pwd   # TODO: error or pwd ?

  mode = {
    :noop    => @cli.trial?,
    :verbose => @cli.trace? || (@cli.trial? && !@cli.quiet?),
    :quiet   => @cli.quiet?
  }

  @shell = Shell.new(path, mode)
end

Public Instance Methods

apply_naming_policy(name, ext) click to toggle source
# File lib/syckle/script.rb, line 146
def apply_naming_policy(name, ext)
  naming_policy.each do |policy|
    case policy.to_s
    when /^low/, /^down/
      name = name.downcase
    when /^up/
      name = name.upcase
    when /^cap/
      name = name.capitalize
    when /^ext/
      name = name + ".#{ext}"
    end
  end
  name
end
configuration(file) click to toggle source

Load configuration data from a file. Results are cached and and empty Hash is returned if the file is not found.

Since they are YAML files, they can optionally end with ‘.yaml’ or ‘.yml’.

# File lib/syckle/script.rb, line 103
def configuration(file)
  @configuration ||= {}
  @configuration[file] ||= (
    begin
      configuration!(file)
    rescue LoadError
      Hash.new{ |h,k| h[k] = {} }
    end
  )
end
configuration!(file) click to toggle source

Load configuration data from a file. The “bang” version will raise an error if file is not found. It also does not cache the results.

Since they are YAML files, they can optionally end with ‘.yaml’ or ‘.yml’.

# File lib/syckle/script.rb, line 121
def configuration!(file)
  @configuration ||= {}
  patt = file + "{.yml,.yaml,}"
  path = Dir.glob(patt, File::FNM_CASEFOLD).find{ |f| File.file?(f) }
  if path
    # The || {} is in case the file is empty.
    data = YAML::load(File.open(path)) || {}
    @configuration[file] = data
  else
    raise LoadError, "Missing file -- #{path}"
  end
end
current_platform() click to toggle source

Current platform.

# File lib/syckle/script.rb, line 80
def current_platform
  Platform.local.to_s
end
debug?() click to toggle source
# File lib/syckle/script.rb, line 59
def debug?   ; cli.debug?   ; end
email(options) click to toggle source

Email function to easily send out an email.

Settings:

subject      Subject of email message.
from         Message FROM address [email].
to           Email address to send announcemnt.
server       Email server to route message.
port         Email server's port.
domain       Email server's domain name.
account      Email account name if needed.
password     Password for login..
login        Login type: plain, cram_md5 or login [plain].
secure       Uses TLS security, true or false? [false]
message      Mesage to send -or-
file         File that contains message.
# File lib/syckle/script.rb, line 179
def email(options)
  emailer = Emailer.new(options.rekey)
  success = emailer.email
  if Exception === success
    puts "Email failed: #{success.message}."
  else
    puts "Email sent successfully to #{success.join(';')}."
  end
end
force?() click to toggle source
# File lib/syckle/script.rb, line 53
def force?   ; cli.force?   ; end
metadata() click to toggle source

POM::Metadata object, derived from Project.

# File lib/syckle/script.rb, line 75
def metadata
  project.metadata
end
method_missing(s, *a, &b) click to toggle source

Delegate to Shell.

# File lib/syckle/script.rb, line 85
def method_missing(s, *a, &b)
  if @shell.respond_to?(s)
    @shell.__send__(s, *a, &b)
  else
    if @io.respond_to?(s)
      @io.__send__(s, *a, &b)
    else
      super
    end
  end
end
naming_policy(*policies) click to toggle source
# File lib/syckle/script.rb, line 136
def naming_policy(*policies)
  if policies.empty?
    @naming_policy ||= ['down', 'ext']
  else
    @naming_policy = policies
  end
end
quiet?() click to toggle source
# File lib/syckle/script.rb, line 54
def quiet?   ; cli.quiet?   ; end
trace?() click to toggle source
# File lib/syckle/script.rb, line 57
def trace?   ; cli.trace?   ; end
trial?() click to toggle source
# File lib/syckle/script.rb, line 58
def trial?   ; cli.trial?   ; end
verbose?() click to toggle source
# File lib/syckle/script.rb, line 55
def verbose? ; cli.verbose? ; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.