Module: SSC::Handler::Helper::InstanceMethods

Includes:
DirectoryManager
Defined in:
lib/handlers/helper.rb

Defined Under Namespace

Classes: ApplianceDirectoryError

Instance Method Summary collapse

Instance Method Details

#connect(user, pass, connection_options) ⇒ Object

Establish connection to Suse Studio with username, password



58
59
60
61
# File 'lib/handlers/helper.rb', line 58

def connect(user, pass, connection_options)
  @connection= StudioApi::Connection.new(user, pass, self.class::API_URL, connection_options)
  StudioApi::Util.configure_studio_connection @connection
end

#filter_options(options, keys) ⇒ Object



63
64
65
66
67
# File 'lib/handlers/helper.rb', line 63

def filter_options(options, keys)
  keys.inject({}) do |out, key|
    (options.respond_to?(key) && options.send(key)) ? out.merge({ key => options.send(key) }) : out
  end
end

#require_applianceObject



83
84
85
86
87
88
89
# File 'lib/handlers/helper.rb', line 83

def require_appliance
  if options.appliance_id
    yield(StudioApi::Appliance.find(options.appliance_id))
  else
    raise "Unable to find the appliance"
  end
end

#require_appliance_directoryObject



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/handlers/helper.rb', line 93

def require_appliance_directory
  if File.exist?('./.sscrc')
    require_appliance do |appliance|
      files= {
        :package    => PackageFile.new,
        :repository => RepositoryFile.new,
        :file_list  => FileListFile.new }
      yield(appliance, files)
    end
  else
    raise ApplianceDirectoryError, 'Appliance directory not found'
  end
end

#say_array(array, color = nil) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/handlers/helper.rb', line 69

def say_array(array, color= nil)
  # NOTE
  # Included for those methods that still return arrays for printing
  # Can be removed eventually
  # Still seems to be a nice way to format the text output of methods
  if array.is_a?(Array)
    array= array.collect {|i| yield(i)} if block_given?
    say array.join("\n"), color
  else
    say "\n"
  end
  array
end