Skip to content

Commit

Permalink
Renamed singleton to StorageManager
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Dec 22, 2015
1 parent cb11dee commit fb34cdd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
47 changes: 34 additions & 13 deletions src/lib/storage/singleton.rb → src/lib/storage/storage_manager.rb
Expand Up @@ -28,25 +28,29 @@ module Yast
module Storage
# Singleton class for the libstorage object.
#
# You can simply use Storage.instance to use it and create a libstorage
# instance if there isn't one yet; this will use common default parameters
# for creating it.
# You can simply use StorageManager.instance to use it and create a
# libstorage instance if there isn't one yet; this will use common default
# parameters for creating it.
#
# If you need special parameters for creating it, you can use
# Storage.create_instance with a custom ::Storage::Environment (notice the
# difference between the global ::Storage namespace which is libstorage and
# this Yast::Storage namespace).
# StorageManager.create_instance with a custom ::Storage::Environment
# (notice the difference between the global ::Storage namespace which is
# libstorage and this Yast::Storage namespace).
#
# By default (unless disabled in the ::Storage::Environment), creating the
# instance will also start hardware probing. This is why there is an alias
# name Storage.start_probing to make this explicit.
# name StorageManager.start_probing to make this explicit.
#
class Storage
class StorageManager
include Yast::Logger
class << self
@instance = nil

# Return the singleton for the libstorage object. This will create one
# for the first call, which will also trigger hardware probing.
#
# @return [::Storage::Storage] libstorage object
#
def instance
create_instance unless @instance
@instance
Expand All @@ -55,20 +59,37 @@ def instance
# Create the singleton for the libstorage object.
#
# Create your own Storage::Environment for custom purposes like mocking
# the hardware probing etc.
# the hardware probing etc.; you can use create_environment for the
# default environment, modify it and use it as parameter here.
#
# @return [::Storage::Storage] libstorage object
#
def create_instance(storage_environment = nil)
if storage_environment.nil?
storage_environment = ::Storage::Environment.new(true)
# TO DO: Set up logging
storage_environment = create_environment
end
# FIXME: Remove this
print "Creating Storage object\n"
log.info("Creating Storage object")
@instance = ::Storage::Storage.new(storage_environment)
end

# Create a default storage environment for the libstorage object that
# also sets up logging for libstorage.
#
# @return [::Storage::Environment] storage_environment
#
def create_environment
storage_environment = ::Storage::Environment.new(true)
# TO DO: Set up logging in environment
storage_environment
end

alias_method :start_probing, :create_instance

# Destroy the singleton for the libstorage object.
#
# Notice that it depends on the Ruby garbage collector when the
# underlying object is actually deleted.
#
def destroy_instance
@instance = nil
end
Expand Down
8 changes: 3 additions & 5 deletions src/lib/storage/storage_proposal.rb
Expand Up @@ -24,7 +24,7 @@
require "yast"
require "storage"
require_relative "./disk_size"
require_relative "./singleton"
require_relative "./storage_manager"
require "pp"

# This file can be invoked separately for minimal testing.
Expand Down Expand Up @@ -137,9 +137,7 @@ class SpaceMaker
def initialize(volumes, settings)
@volumes = volumes
@settings = settings
storage = Storage.instance
storage = Storage.instance
storage = Storage.instance
storage = StorageManager.instance
end

# Try to detect empty (unpartitioned) space.
Expand Down Expand Up @@ -227,7 +225,7 @@ def choose_disk
# Create a storage proposal.
def propose
# TO DO: Reset staging
Storage.start_probing
StorageManager.start_probing
space_maker = SpaceMaker.new(@volumes, @settings)
end

Expand Down

0 comments on commit fb34cdd

Please sign in to comment.