From 164e57695ea622c372497b706dcce24f61c5b784 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Mon, 1 Apr 2013 21:05:19 -0300 Subject: [PATCH] :bomb: BaseAction --- lib/vagrant-lxc/action.rb | 4 ---- lib/vagrant-lxc/action/base_action.rb | 11 ----------- lib/vagrant-lxc/action/boot.rb | 6 +++++- lib/vagrant-lxc/action/check_created.rb | 6 +++++- lib/vagrant-lxc/action/check_running.rb | 6 +++++- lib/vagrant-lxc/action/create.rb | 6 +++++- lib/vagrant-lxc/action/created.rb | 6 +++++- lib/vagrant-lxc/action/destroy.rb | 6 +++++- lib/vagrant-lxc/action/disconnect.rb | 6 +++++- lib/vagrant-lxc/action/handle_box_metadata.rb | 4 ++-- lib/vagrant-lxc/action/is_running.rb | 6 +++++- lib/vagrant-lxc/action/network.rb | 7 +++++-- lib/vagrant-lxc/action/share_folders.rb | 6 +++++- spec/unit/action/handle_box_metadata_spec.rb | 1 - 14 files changed, 52 insertions(+), 29 deletions(-) delete mode 100644 lib/vagrant-lxc/action/base_action.rb diff --git a/lib/vagrant-lxc/action.rb b/lib/vagrant-lxc/action.rb index c5f97d3..6337d29 100644 --- a/lib/vagrant-lxc/action.rb +++ b/lib/vagrant-lxc/action.rb @@ -1,7 +1,3 @@ -# TODO: Remove base action -require 'vagrant-lxc/action/base_action' - -# TODO: Use require_relative require 'vagrant-lxc/action/boot' require 'vagrant-lxc/action/check_created' require 'vagrant-lxc/action/check_running' diff --git a/lib/vagrant-lxc/action/base_action.rb b/lib/vagrant-lxc/action/base_action.rb deleted file mode 100644 index 6c58c2a..0000000 --- a/lib/vagrant-lxc/action/base_action.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Vagrant - module LXC - module Action - class BaseAction - def initialize(app, env) - @app = app - end - end - end - end -end diff --git a/lib/vagrant-lxc/action/boot.rb b/lib/vagrant-lxc/action/boot.rb index 5d0a0ce..361ae1e 100644 --- a/lib/vagrant-lxc/action/boot.rb +++ b/lib/vagrant-lxc/action/boot.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class Boot < BaseAction + class Boot + def initialize(app, env) + @app = app + end + def call(env) @env = env diff --git a/lib/vagrant-lxc/action/check_created.rb b/lib/vagrant-lxc/action/check_created.rb index 7c43455..d7bde98 100644 --- a/lib/vagrant-lxc/action/check_created.rb +++ b/lib/vagrant-lxc/action/check_created.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class CheckCreated < BaseAction + class CheckCreated + def initialize(app, env) + @app = app + end + def call(env) unless env[:machine].state.created? raise Vagrant::Errors::VMNotCreatedError diff --git a/lib/vagrant-lxc/action/check_running.rb b/lib/vagrant-lxc/action/check_running.rb index 9f6d189..4d849ea 100644 --- a/lib/vagrant-lxc/action/check_running.rb +++ b/lib/vagrant-lxc/action/check_running.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class CheckRunning < BaseAction + class CheckRunning + def initialize(app, env) + @app = app + end + def call(env) unless env[:machine].state.running? raise Vagrant::Errors::VMNotRunningError diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index 1cb8e9a..5dd8d56 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class Create < BaseAction + class Create + def initialize(app, env) + @app = app + end + def call(env) base_name = env[:root_path].basename.to_s base_name.gsub!(/[^-a-z0-9_]/i, "") diff --git a/lib/vagrant-lxc/action/created.rb b/lib/vagrant-lxc/action/created.rb index b4c4cc7..3c0420a 100644 --- a/lib/vagrant-lxc/action/created.rb +++ b/lib/vagrant-lxc/action/created.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class Created < BaseAction + class Created + def initialize(app, env) + @app = app + end + def call(env) # Set the result to be true if the machine is created. env[:result] = env[:machine].state.created? diff --git a/lib/vagrant-lxc/action/destroy.rb b/lib/vagrant-lxc/action/destroy.rb index a0014c1..4c47c79 100644 --- a/lib/vagrant-lxc/action/destroy.rb +++ b/lib/vagrant-lxc/action/destroy.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class Destroy < BaseAction + class Destroy + def initialize(app, env) + @app = app + end + def call(env) env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying") env[:machine].provider.container.destroy diff --git a/lib/vagrant-lxc/action/disconnect.rb b/lib/vagrant-lxc/action/disconnect.rb index 5ad86f0..69aee10 100644 --- a/lib/vagrant-lxc/action/disconnect.rb +++ b/lib/vagrant-lxc/action/disconnect.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class Disconnect < BaseAction + class Disconnect + def initialize(app, env) + @app = app + end + def call(env) @app.call env # FIXME: Vagrant >= 1.1.3 should not need this diff --git a/lib/vagrant-lxc/action/handle_box_metadata.rb b/lib/vagrant-lxc/action/handle_box_metadata.rb index d59a442..9047a35 100644 --- a/lib/vagrant-lxc/action/handle_box_metadata.rb +++ b/lib/vagrant-lxc/action/handle_box_metadata.rb @@ -2,12 +2,12 @@ module Vagrant module LXC module Action # Prepare arguments to be used for lxc-create - class HandleBoxMetadata < BaseAction + class HandleBoxMetadata LXC_TEMPLATES_PATH = Pathname.new("/usr/share/lxc/templates") TEMP_PREFIX = "vagrant-lxc-rootfs-temp-" def initialize(app, env) - super + @app = app @logger = Log4r::Logger.new("vagrant::lxc::action::handle_box_metadata") end diff --git a/lib/vagrant-lxc/action/is_running.rb b/lib/vagrant-lxc/action/is_running.rb index d3087b7..05c035c 100644 --- a/lib/vagrant-lxc/action/is_running.rb +++ b/lib/vagrant-lxc/action/is_running.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class IsRunning < BaseAction + class IsRunning + def initialize(app, env) + @app = app + end + def call(env) env[:result] = env[:machine].state.running? diff --git a/lib/vagrant-lxc/action/network.rb b/lib/vagrant-lxc/action/network.rb index 1c34651..5e1e7d7 100644 --- a/lib/vagrant-lxc/action/network.rb +++ b/lib/vagrant-lxc/action/network.rb @@ -1,9 +1,12 @@ module Vagrant module LXC module Action - class Network < BaseAction + class Network + def initialize(app, env) + @app = app + end + def call(env) - # TODO: Validate network configuration prior to anything below @env = env env[:machine].config.vm.networks.each do |type, options| diff --git a/lib/vagrant-lxc/action/share_folders.rb b/lib/vagrant-lxc/action/share_folders.rb index 81ab3b7..11bc96e 100644 --- a/lib/vagrant-lxc/action/share_folders.rb +++ b/lib/vagrant-lxc/action/share_folders.rb @@ -1,7 +1,11 @@ module Vagrant module LXC module Action - class ShareFolders < BaseAction + class ShareFolders + def initialize(app, env) + @app = app + end + def call(env) @env = env prepare_folders diff --git a/spec/unit/action/handle_box_metadata_spec.rb b/spec/unit/action/handle_box_metadata_spec.rb index e70f309..4721e7f 100644 --- a/spec/unit/action/handle_box_metadata_spec.rb +++ b/spec/unit/action/handle_box_metadata_spec.rb @@ -1,6 +1,5 @@ require 'unit_helper' -require 'vagrant-lxc/action/base_action' require 'vagrant-lxc/action/handle_box_metadata' describe Vagrant::LXC::Action::HandleBoxMetadata do