Class: Lucid::CLI::Profile

Inherits:
Object show all
Defined in:
lib/lucid/cli/profile.rb

Instance Method Summary collapse

Constructor Details

#initializeProfile

Returns a new instance of Profile.



7
8
9
# File 'lib/lucid/cli/profile.rb', line 7

def initialize
  @lucid_yml = nil
end

Instance Method Details

#args_from(profile) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/lucid/cli/profile.rb', line 11

def args_from(profile)
  unless lucid_yml.has_key?(profile)
    raise(ProfileNotFound, <<-END_OF_ERROR)
Could not find profile: '#{profile}'

Defined profiles in lucid.yml:
  * #{lucid_yml.keys.sort.join("\n  * ")}
  END_OF_ERROR
  end

  args_from_yml = lucid_yml[profile] || ''

  case(args_from_yml)
    when String
      raise YmlLoadError, ["The '#{profile}' profile in lucid.yml was blank. You must define",
                           "command line arguments if you are are going to include a profile",
                           "in lucid.yml.\n"].join("\n") if args_from_yml =~ /^\s*$/
      if(Lucid::WINDOWS)
        args_from_yml = args_from_yml.split
        args_from_yml = args_from_yml.collect {|x| x.gsub(/^\"(.*)\"/,'\1') }
      else
        require 'shellwords'
        args_from_yml = Shellwords.shellwords(args_from_yml)
      end
    when Array
      raise YmlLoadError, ["The '#{profile}' profile in lucid.yml contained an empty array.",
                           "You must define any command line arguments within the array.\n"].join("\n") if args_from_yml.empty?
    else
      raise YmlLoadError, ["The '#{profile}' profile in lucid.yml was a #{args_from_yml.class}.",
                           "A profile must be a a String or an Array."].join("\n")
  end
  args_from_yml
end

#has_profile?(profile) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/lucid/cli/profile.rb', line 45

def has_profile?(profile)
  lucid_yml.has_key?(profile)
end

#lucid_yml_defined?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/lucid/cli/profile.rb', line 49

def lucid_yml_defined?
  lucid_file && File.exist?(lucid_file)
end