a little bit of refactoring
This commit is contained in:
parent
6ba884e459
commit
031113799e
@ -52,6 +52,10 @@ GEM
|
||||
bson (1.2.4)
|
||||
bson_ext (1.2.4)
|
||||
builder (2.1.2)
|
||||
bushido (0.0.10)
|
||||
highline (>= 1.6.1)
|
||||
json (>= 1.4.6)
|
||||
rest-client (>= 1.6.1)
|
||||
capybara (0.4.0)
|
||||
celerity (>= 0.7.9)
|
||||
culerity (>= 0.2.4)
|
||||
@ -125,6 +129,7 @@ GEM
|
||||
json (~> 1.5.1)
|
||||
launchy (~> 0.3.2)
|
||||
rest-client (>= 1.4.0, < 1.7.0)
|
||||
highline (1.6.1)
|
||||
httparty (0.7.4)
|
||||
crack (= 0.1.8)
|
||||
i18n (0.5.0)
|
||||
@ -258,6 +263,7 @@ DEPENDENCIES
|
||||
actionmailer-with-request
|
||||
autotest
|
||||
bson_ext (~> 1.2.1)
|
||||
bushido
|
||||
capybara
|
||||
cucumber (= 0.8.5)
|
||||
cucumber-rails
|
||||
|
@ -8,8 +8,7 @@ require 'locomotive/logger'
|
||||
require 'locomotive/liquid'
|
||||
require 'locomotive/mongoid'
|
||||
require 'locomotive/carrierwave'
|
||||
require 'locomotive/heroku'
|
||||
require 'locomotive/bushido'
|
||||
require 'locomotive/deployment'
|
||||
require 'locomotive/custom_fields'
|
||||
require 'locomotive/httparty'
|
||||
require 'locomotive/inherited_resources'
|
||||
@ -24,8 +23,8 @@ require 'locomotive/session_store'
|
||||
|
||||
module Locomotive
|
||||
|
||||
include Locomotive::Heroku
|
||||
include Locomotive::BushidoSupport
|
||||
include Locomotive::Deployment::Heroku
|
||||
include Locomotive::Deployment::Bushido
|
||||
|
||||
class << self
|
||||
attr_accessor :config
|
||||
|
@ -1,69 +0,0 @@
|
||||
require 'bushido'
|
||||
require 'locomotive/bushido/custom_domain'
|
||||
|
||||
module Locomotive
|
||||
module BushidoSupport
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
class << self
|
||||
attr_accessor :bushido_domains
|
||||
attr_accessor :bushido_subdomain
|
||||
|
||||
puts @bushido_domains
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def bushido?
|
||||
ENV["HOSTING_PLATFORM"] == "bushido"
|
||||
end
|
||||
|
||||
|
||||
def enable_bushido
|
||||
self.enhance_site_model
|
||||
|
||||
self.bushido_domains = Bushido::App.domains
|
||||
self.bushido_subdomain = Bushido::App.subdomain
|
||||
end
|
||||
|
||||
|
||||
def enhance_site_model
|
||||
Site.send :include, Locomotive::BushidoSupport::CustomDomain
|
||||
end
|
||||
|
||||
# manage domains
|
||||
|
||||
def add_bushido_domain(name)
|
||||
Locomotive.logger "[add bushido domain] #{name}"
|
||||
Bushido::App.add_domain(name)
|
||||
|
||||
if Bushido::Command.last_command_successful?
|
||||
self.bushido_domains << name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def remove_bushido_domain(name)
|
||||
Locomotive.logger "[remove bushido domain] #{name}"
|
||||
Bushido::App.remove_domain(name)
|
||||
|
||||
if Bushido::Command.last_command_successful?
|
||||
self.bushido_domains.delete(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def set_bushido_subdomain(name)
|
||||
Locomotive.logger "[set bushido subdomain] #{name}.bushi.do"
|
||||
Bushido::App.set_subdomain(name)
|
||||
|
||||
if Bushido::Command.last_command_successful?
|
||||
self.bushido_subdomain = name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,52 +0,0 @@
|
||||
module Locomotive
|
||||
module BushidoSupport
|
||||
module CustomDomain
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
after_save :add_bushido_domains
|
||||
after_destroy :remove_bushido_domains
|
||||
|
||||
alias_method_chain :add_subdomain_to_domains, :bushido
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
protected
|
||||
|
||||
def add_subdomain_to_domains_with_bushido
|
||||
unless self.domains_change.nil?
|
||||
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
|
||||
@bushido_domains_change = {
|
||||
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
|
||||
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]
|
||||
}
|
||||
end
|
||||
|
||||
add_subdomain_to_domains_without_bushido
|
||||
end
|
||||
|
||||
def add_bushido_domains
|
||||
return if @bushido_domains_change.nil?
|
||||
|
||||
@bushido_domains_change[:added].each do |name|
|
||||
Locomotive.add_bushido_domain(name)
|
||||
end
|
||||
@bushido_domains_change[:removed].each do |name|
|
||||
Locomotive.remove_bushido_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_bushido_domains
|
||||
self.domains_without_subdomain.each do |name|
|
||||
Locomotive.remove_bushido_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
1
lib/locomotive/deployment.rb
Normal file
1
lib/locomotive/deployment.rb
Normal file
@ -0,0 +1 @@
|
||||
Dir[File.join(File.dirname(__FILE__), 'deployment/*.rb')].each { |lib| require lib }
|
68
lib/locomotive/deployment/bushido.rb
Normal file
68
lib/locomotive/deployment/bushido.rb
Normal file
@ -0,0 +1,68 @@
|
||||
require 'bushido'
|
||||
require 'locomotive/deployment/bushido/custom_domain'
|
||||
|
||||
module Locomotive
|
||||
module Deployment
|
||||
module Bushido
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
class << self
|
||||
attr_accessor :bushido_domains
|
||||
attr_accessor :bushido_subdomain
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def bushido?
|
||||
ENV["HOSTING_PLATFORM"] == 'bushido'
|
||||
end
|
||||
|
||||
def enable_bushido
|
||||
self.enhance_site_model
|
||||
|
||||
self.bushido_domains = ::Bushido::App.domains
|
||||
self.bushido_subdomain = ::Bushido::App.subdomain
|
||||
end
|
||||
|
||||
|
||||
def enhance_site_model
|
||||
Site.send :include, Locomotive::Deployment::Bushido::CustomDomain
|
||||
end
|
||||
|
||||
# manage domains
|
||||
|
||||
def add_bushido_domain(name)
|
||||
Locomotive.logger "[add bushido domain] #{name}"
|
||||
::Bushido::App.add_domain(name)
|
||||
|
||||
if ::Bushido::Command.last_command_successful?
|
||||
self.bushido_domains << name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def remove_bushido_domain(name)
|
||||
Locomotive.logger "[remove bushido domain] #{name}"
|
||||
::Bushido::App.remove_domain(name)
|
||||
|
||||
if ::Bushido::Command.last_command_successful?
|
||||
self.bushido_domains.delete(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def set_bushido_subdomain(name)
|
||||
Locomotive.logger "[set bushido subdomain] #{name}.bushi.do"
|
||||
::Bushido::App.set_subdomain(name)
|
||||
|
||||
if ::Bushido::Command.last_command_successful?
|
||||
self.bushido_subdomain = name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
54
lib/locomotive/deployment/bushido/custom_domain.rb
Normal file
54
lib/locomotive/deployment/bushido/custom_domain.rb
Normal file
@ -0,0 +1,54 @@
|
||||
module Locomotive
|
||||
module Deployment
|
||||
module Bushido
|
||||
module CustomDomain
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
after_save :add_bushido_domains
|
||||
after_destroy :remove_bushido_domains
|
||||
|
||||
alias_method_chain :add_subdomain_to_domains, :bushido
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
protected
|
||||
|
||||
def add_subdomain_to_domains_with_bushido
|
||||
unless self.domains_change.nil?
|
||||
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
|
||||
@bushido_domains_change = {
|
||||
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
|
||||
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]
|
||||
}
|
||||
end
|
||||
|
||||
add_subdomain_to_domains_without_bushido
|
||||
end
|
||||
|
||||
def add_bushido_domains
|
||||
return if @bushido_domains_change.nil?
|
||||
|
||||
@bushido_domains_change[:added].each do |name|
|
||||
Locomotive.add_bushido_domain(name)
|
||||
end
|
||||
@bushido_domains_change[:removed].each do |name|
|
||||
Locomotive.remove_bushido_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_bushido_domains
|
||||
self.domains_without_subdomain.each do |name|
|
||||
Locomotive.remove_bushido_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
63
lib/locomotive/deployment/heroku.rb
Normal file
63
lib/locomotive/deployment/heroku.rb
Normal file
@ -0,0 +1,63 @@
|
||||
require 'heroku'
|
||||
require 'heroku/client'
|
||||
require 'locomotive/deployment/heroku/custom_domain'
|
||||
|
||||
module Locomotive
|
||||
module Deployment
|
||||
module Heroku
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
class << self
|
||||
attr_accessor :heroku_connection
|
||||
attr_accessor :heroku_domains
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def heroku?
|
||||
!self.config.heroku.nil? && self.config.heroku.respond_to?(:[])
|
||||
end
|
||||
|
||||
def enable_heroku
|
||||
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
||||
|
||||
self.open_heroku_connection
|
||||
self.enhance_site_model
|
||||
|
||||
# "cache" domains for better performance
|
||||
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
||||
end
|
||||
|
||||
def open_heroku_connection
|
||||
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
||||
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
|
||||
|
||||
self.heroku_connection = ::Heroku::Client.new(login, password)
|
||||
end
|
||||
|
||||
def enhance_site_model
|
||||
Site.send :include, Locomotive::Deployment::Heroku::CustomDomain
|
||||
end
|
||||
|
||||
# manage domains
|
||||
|
||||
def add_heroku_domain(name)
|
||||
Locomotive.logger "[add heroku domain] #{name}"
|
||||
self.heroku_connection.add_domain(self.config.heroku[:name], name)
|
||||
self.heroku_domains << name
|
||||
end
|
||||
|
||||
def remove_heroku_domain(name)
|
||||
Locomotive.logger "[remove heroku domain] #{name}"
|
||||
self.heroku_connection.remove_domain(self.config.heroku[:name], name)
|
||||
self.heroku_domains.delete(name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
54
lib/locomotive/deployment/heroku/custom_domain.rb
Normal file
54
lib/locomotive/deployment/heroku/custom_domain.rb
Normal file
@ -0,0 +1,54 @@
|
||||
module Locomotive
|
||||
module Deployment
|
||||
module Heroku
|
||||
module CustomDomain
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
after_save :add_heroku_domains
|
||||
after_destroy :remove_heroku_domains
|
||||
|
||||
alias_method_chain :add_subdomain_to_domains, :heroku
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
protected
|
||||
|
||||
def add_subdomain_to_domains_with_heroku
|
||||
unless self.domains_change.nil?
|
||||
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
|
||||
@heroku_domains_change = {
|
||||
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
|
||||
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]
|
||||
}
|
||||
end
|
||||
|
||||
add_subdomain_to_domains_without_heroku
|
||||
end
|
||||
|
||||
def add_heroku_domains
|
||||
return if @heroku_domains_change.nil?
|
||||
|
||||
@heroku_domains_change[:added].each do |name|
|
||||
Locomotive.add_heroku_domain(name)
|
||||
end
|
||||
@heroku_domains_change[:removed].each do |name|
|
||||
Locomotive.remove_heroku_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_heroku_domains
|
||||
self.domains_without_subdomain.each do |name|
|
||||
Locomotive.remove_heroku_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -1,61 +0,0 @@
|
||||
require 'heroku'
|
||||
require 'heroku/client'
|
||||
require 'locomotive/heroku/custom_domain'
|
||||
|
||||
module Locomotive
|
||||
module Heroku
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
class << self
|
||||
attr_accessor :heroku_connection
|
||||
attr_accessor :heroku_domains
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def heroku?
|
||||
!self.config.heroku.nil? && self.config.heroku.respond_to?(:[])
|
||||
end
|
||||
|
||||
def enable_heroku
|
||||
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
||||
|
||||
self.open_heroku_connection
|
||||
self.enhance_site_model
|
||||
|
||||
# "cache" domains for better performance
|
||||
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
||||
end
|
||||
|
||||
def open_heroku_connection
|
||||
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
||||
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
|
||||
|
||||
self.heroku_connection = ::Heroku::Client.new(login, password)
|
||||
end
|
||||
|
||||
def enhance_site_model
|
||||
Site.send :include, Locomotive::Heroku::CustomDomain
|
||||
end
|
||||
|
||||
# manage domains
|
||||
|
||||
def add_heroku_domain(name)
|
||||
Locomotive.logger "[add heroku domain] #{name}"
|
||||
self.heroku_connection.add_domain(self.config.heroku[:name], name)
|
||||
self.heroku_domains << name
|
||||
end
|
||||
|
||||
def remove_heroku_domain(name)
|
||||
Locomotive.logger "[remove heroku domain] #{name}"
|
||||
self.heroku_connection.remove_domain(self.config.heroku[:name], name)
|
||||
self.heroku_domains.delete(name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -1,52 +0,0 @@
|
||||
module Locomotive
|
||||
module Heroku
|
||||
module CustomDomain
|
||||
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
|
||||
after_save :add_heroku_domains
|
||||
after_destroy :remove_heroku_domains
|
||||
|
||||
alias_method_chain :add_subdomain_to_domains, :heroku
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
protected
|
||||
|
||||
def add_subdomain_to_domains_with_heroku
|
||||
unless self.domains_change.nil?
|
||||
full_subdomain = "#{self.subdomain}.#{Locomotive.config.default_domain}"
|
||||
@heroku_domains_change = {
|
||||
:added => self.domains_change.last - self.domains_change.first - [full_subdomain],
|
||||
:removed => self.domains_change.first - self.domains_change.last - [full_subdomain]
|
||||
}
|
||||
end
|
||||
|
||||
add_subdomain_to_domains_without_heroku
|
||||
end
|
||||
|
||||
def add_heroku_domains
|
||||
return if @heroku_domains_change.nil?
|
||||
|
||||
@heroku_domains_change[:added].each do |name|
|
||||
Locomotive.add_heroku_domain(name)
|
||||
end
|
||||
@heroku_domains_change[:removed].each do |name|
|
||||
Locomotive.remove_heroku_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_heroku_domains
|
||||
self.domains_without_subdomain.each do |name|
|
||||
Locomotive.remove_heroku_domain(name)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user