Remove the notion of an "engine" since it's not any useful form of an abstraction
Fixes #49
This commit is contained in:
parent
cd00c74425
commit
18c64cbd5c
|
@ -1,5 +1,8 @@
|
|||
require 'rubygems'
|
||||
require 'fog/core'
|
||||
require 'fog/compute'
|
||||
|
||||
require 'blimpy/box'
|
||||
require 'blimpy/engine'
|
||||
require 'blimpy/fleet'
|
||||
require 'blimpy/version'
|
||||
|
||||
|
@ -13,6 +16,22 @@ module Blimpy
|
|||
fleet
|
||||
end
|
||||
|
||||
def self.load_file(file_content)
|
||||
if file_content.nil? || file_content.empty?
|
||||
raise InvalidBlimpFileError, 'File appears empty'
|
||||
end
|
||||
|
||||
begin
|
||||
fleet = eval(file_content)
|
||||
if fleet and !(fleet.instance_of? Blimpy::Fleet)
|
||||
raise Exception, 'File does not create a Fleet'
|
||||
end
|
||||
rescue Exception => e
|
||||
raise InvalidBlimpFileError, e.to_s
|
||||
end
|
||||
fleet
|
||||
end
|
||||
|
||||
class UnknownError < Exception
|
||||
end
|
||||
class InvalidBlimpFileError < Exception
|
||||
|
|
|
@ -2,7 +2,6 @@ require 'rubygems'
|
|||
require 'thor'
|
||||
|
||||
require 'blimpy'
|
||||
require 'blimpy/engine'
|
||||
|
||||
module Blimpy
|
||||
class CLI < Thor
|
||||
|
@ -16,18 +15,16 @@ module Blimpy
|
|||
end
|
||||
end
|
||||
|
||||
def load_engine
|
||||
engine = Blimpy::Engine.new
|
||||
engine.load_file(File.open(BLIMPFILE).read)
|
||||
engine
|
||||
def load_blimpfile
|
||||
Blimpy.load_file(File.open(BLIMPFILE).read)
|
||||
end
|
||||
|
||||
def box_by_name(name)
|
||||
engine = load_engine
|
||||
fleet = load_blimpfile
|
||||
box = nil
|
||||
ship_id = nil
|
||||
data = nil
|
||||
engine.fleet.members.each do |instance_id, instance_data|
|
||||
fleet.members.each do |instance_id, instance_data|
|
||||
next unless instance_data[:name] == name
|
||||
ship_id = instance_id
|
||||
data = instance_data
|
||||
|
@ -38,7 +35,7 @@ module Blimpy
|
|||
return nil
|
||||
end
|
||||
|
||||
engine.fleet.ships.each do |ship|
|
||||
fleet.ships.each do |ship|
|
||||
next unless ship.name == name
|
||||
ship.with_data(ship_id, data)
|
||||
return ship
|
||||
|
@ -62,7 +59,7 @@ module Blimpy
|
|||
def start
|
||||
ensure_blimpfile
|
||||
begin
|
||||
engine = load_engine
|
||||
fleet = load_blimpfile
|
||||
rescue Blimpy::InvalidBlimpFileError => e
|
||||
puts "The Blimpfile is invalid!"
|
||||
exit 1
|
||||
|
@ -73,7 +70,7 @@ module Blimpy
|
|||
exit 0
|
||||
end
|
||||
|
||||
engine.fleet.start
|
||||
fleet.start
|
||||
end
|
||||
|
||||
desc 'status', 'Show running blimps'
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
|
||||
require 'rubygems'
|
||||
require 'fog/core'
|
||||
require 'fog/compute'
|
||||
|
||||
module Blimpy
|
||||
class Engine
|
||||
attr_reader :fleet
|
||||
|
||||
def initialize
|
||||
@fleet = nil
|
||||
end
|
||||
|
||||
def load_file(file_content)
|
||||
if file_content.nil? || file_content.empty?
|
||||
raise InvalidBlimpFileError, 'File appears empty'
|
||||
end
|
||||
|
||||
begin
|
||||
@fleet = eval(file_content)
|
||||
if @fleet and !(@fleet.instance_of? Blimpy::Fleet)
|
||||
raise Exception, 'File does not create a Fleet'
|
||||
end
|
||||
rescue Exception => e
|
||||
raise InvalidBlimpFileError, e.to_s
|
||||
end
|
||||
@fleet
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Blimpy::Engine do
|
||||
describe '#load_file' do
|
||||
context 'no contents' do
|
||||
let(:content) { '' }
|
||||
|
||||
it 'should raise InvalidBlimpFileError' do
|
||||
expect {
|
||||
subject.load_file(content)
|
||||
}.to raise_error(Blimpy::InvalidBlimpFileError)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'invalid content' do
|
||||
let(:content) do
|
||||
"""
|
||||
this is totally invalid Ruby
|
||||
"""
|
||||
end
|
||||
|
||||
it 'should raise InvalidBlimpFileError' do
|
||||
expect {
|
||||
subject.load_file(content)
|
||||
}.to raise_error(Blimpy::InvalidBlimpFileError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'valid content' do
|
||||
let(:content) do
|
||||
"""
|
||||
Blimpy.fleet do |fleet|
|
||||
fleet.add(:aws) do |ship|
|
||||
ship.image_id = 'ami-349b495d'
|
||||
ship.livery = 'rails'
|
||||
ship.group = 'Simple'
|
||||
ship.region = 'us-west-1'
|
||||
ship.name = 'Rails App Server'
|
||||
end
|
||||
end
|
||||
"""
|
||||
end
|
||||
|
||||
it 'should create the appropriate Fleet object' do
|
||||
result = subject.load_file(content)
|
||||
result.should be_instance_of Blimpy::Fleet
|
||||
result.ships.should be_instance_of Array
|
||||
result.ships.size.should == 1
|
||||
|
||||
ship = result.ships.first
|
||||
ship.group.should == 'Simple'
|
||||
ship.name.should == 'Rails App Server'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,4 +25,58 @@ describe Blimpy do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#load_file' do
|
||||
context 'no contents' do
|
||||
let(:content) { '' }
|
||||
|
||||
it 'should raise InvalidBlimpFileError' do
|
||||
expect {
|
||||
subject.load_file(content)
|
||||
}.to raise_error(Blimpy::InvalidBlimpFileError)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'invalid content' do
|
||||
let(:content) do
|
||||
"""
|
||||
this is totally invalid Ruby
|
||||
"""
|
||||
end
|
||||
|
||||
it 'should raise InvalidBlimpFileError' do
|
||||
expect {
|
||||
subject.load_file(content)
|
||||
}.to raise_error(Blimpy::InvalidBlimpFileError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'valid content' do
|
||||
let(:content) do
|
||||
"""
|
||||
Blimpy.fleet do |fleet|
|
||||
fleet.add(:aws) do |ship|
|
||||
ship.image_id = 'ami-349b495d'
|
||||
ship.livery = 'rails'
|
||||
ship.group = 'Simple'
|
||||
ship.region = 'us-west-1'
|
||||
ship.name = 'Rails App Server'
|
||||
end
|
||||
end
|
||||
"""
|
||||
end
|
||||
|
||||
it 'should create the appropriate Fleet object' do
|
||||
result = subject.load_file(content)
|
||||
result.should be_instance_of Blimpy::Fleet
|
||||
result.ships.should be_instance_of Array
|
||||
result.ships.size.should == 1
|
||||
|
||||
ship = result.ships.first
|
||||
ship.group.should == 'Simple'
|
||||
ship.name.should == 'Rails App Server'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue