rails-zero 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ba6e138cdeb9b604c743e4ea7417b73d7abe2c3
4
- data.tar.gz: eaf3425df9b310abc418f8abad736d390d0c61ba
3
+ metadata.gz: cfd9428cef4a1babfcd55d9a389ecff29e8ce566
4
+ data.tar.gz: 46c0834dfaa93e4ac00ca973c2d45673f3076459
5
5
  SHA512:
6
- metadata.gz: d19b8bc94dd0d5e1e232fce995f0a452f13a1c3a7715be7c26777ae8e05a19c7b6f31dd61ecc8848cc814f493391bd95f165d0c486b3c7870ee8729e439d09db
7
- data.tar.gz: 27e175f061c27cfb5a4b79abba09b9249b0a9e0131b9beee520512e98adc00a9da6d6274a31684996f57656fe3e16cc560d8d21653567dfcba92c5de0db7f0e4
6
+ metadata.gz: 6b2237476ecaaf2149332cccbb8db8e95d3f6024d3422ffb5ea2fbf86e981fd2a03b3379ccc0412e1594f9eed6d5bd75288dc4e555c518dc939ca9229eafa98e
7
+ data.tar.gz: 28bf820a80c5f4e2902525e488c065aa01187892b0fef8115089ede71873e8e40499537cf557079f3f45adbe662fe63806898c4aa80b933c6ee560550b77dfb2
@@ -2,11 +2,14 @@ require_dependency "rails_zero/base_client"
2
2
 
3
3
  module RailsZero
4
4
  class PackagesClient < BaseClient
5
- def get url
6
- remote_url = File.join(url, packages_path)
7
- destination = Rails.root.join('tmp', 'downloads', 'public.tar')
8
- FileUtils.mkdir_p(File.dirname(destination))
9
- command = "curl #{remote_url} > #{destination}"
5
+ def download_destination
6
+ Rails.root.join('tmp', 'rails_zero', 'downloads', 'public.tar').to_s
7
+ end
8
+
9
+ def get
10
+ remote_url = File.join(RailsZero.config.backend.url, packages_path)
11
+ FileUtils.mkdir_p(File.dirname(download_destination))
12
+ command = "curl #{remote_url} > #{download_destination}"
10
13
  stdout_str, stderr_str, status = Open3.capture3(command)
11
14
  end
12
15
  end
@@ -4,8 +4,11 @@ module RailsZero
4
4
  class PackagesController < ApplicationController
5
5
  def index
6
6
  FileUtils.mkdir_p(File.dirname(archive_path))
7
- command = "tar -cf '#{archive_path}' '#{public_path}/'"
8
- stdout_str, stderr_str, status = Open3.capture3(command)
7
+ Dir.chdir(Rails.root) do
8
+ command = "tar -cf '#{archive_path}' 'public/'"
9
+ stdout_str, stderr_str, status = Open3.capture3(command)
10
+
11
+ end
9
12
  send_file archive_path
10
13
  end
11
14
 
@@ -16,10 +19,6 @@ module RailsZero
16
19
 
17
20
  private
18
21
 
19
- def public_path
20
- Rails.root.join('public')
21
- end
22
-
23
22
  def archive_path
24
23
  Rails.root.join('tmp', 'packages', 'public.tar')
25
24
  end
@@ -0,0 +1,57 @@
1
+ module RailsZero
2
+ class GitDeployer
3
+ def run
4
+ remove_dir
5
+ create_dir
6
+ extract_package
7
+ push_package
8
+ end
9
+
10
+ def package_path
11
+ PackagesClient.new.download_destination
12
+ end
13
+
14
+ def dir
15
+ Rails.root.join('tmp', 'rails_zero', 'deploy').to_s
16
+ end
17
+
18
+ def extracted_package_path
19
+ File.join(dir, File.basename(package_path, File.extname(package_path)))
20
+ end
21
+
22
+ def create_dir
23
+ FileUtils.mkdir_p(dir)
24
+ end
25
+
26
+ def remove_dir
27
+ FileUtils.rm_rf(dir)
28
+ end
29
+
30
+ def extract_package
31
+ remove_dir
32
+ create_dir
33
+ command = "tar -xf #{package_path} -C #{dir}"
34
+ stdout_str, stderr_str, status = Open3.capture3(command)
35
+ end
36
+
37
+ def push_package
38
+ Dir.chdir(extracted_package_path) do
39
+ commands = []
40
+ commands << "#{git_binary} init"
41
+ commands << "#{git_binary} remote add origin #{git_remote_url}"
42
+ commands << "#{git_binary} add --all ."
43
+ commands << "#{git_binary} commit -m \"Deploy.\""
44
+ commands << "#{git_binary} push -u --force origin master"
45
+ stdout_str, stderr_str, status = Open3.capture3(commands.join(" && "))
46
+ end
47
+ end
48
+
49
+ def git_binary
50
+ RailsZero.config.deployment.git_binary
51
+ end
52
+
53
+ def git_remote_url
54
+ RailsZero.config.deployment.url
55
+ end
56
+ end
57
+ end
@@ -11,7 +11,7 @@ module RailsZero
11
11
  private
12
12
 
13
13
  def excluded_files
14
- RailsZero.pages_config.paths_to_except_from_cleanup
14
+ RailsZero.config.site.paths_to_except_from_cleanup
15
15
  end
16
16
  end
17
17
  end
@@ -1,9 +1,14 @@
1
1
  module RailsZero
2
2
  class GenerateSiteJob
3
+ include RailsZero::Engine.routes.url_helpers
4
+
3
5
  def run
4
- RailsZero.pages_config.links.each do |path|
6
+ Capybara.app_host = RailsZero.config.backend.url
7
+ Capybara.visit packages_new_path
8
+ RailsZero.config.site.paths.each do |path|
5
9
  Capybara.visit path
6
10
  end
11
+ Capybara.reset_sessions!
7
12
  end
8
13
  end
9
14
  end
@@ -1,14 +1,19 @@
1
1
  require "rails_zero/engine"
2
- require "rails_zero/pages_config"
2
+ require "rails_zero/config"
3
3
  require 'actionpack/page_caching/railtie'
4
+ require 'capybara/dsl'
4
5
  require 'open3'
5
6
 
6
7
  module RailsZero
7
- def self.configure_pages
8
- yield pages_config
8
+ def self.configure
9
+ yield config
9
10
  end
10
11
 
11
- def self.pages_config
12
- @config ||= PagesConfig.new
12
+ def self.config
13
+ @config ||= Config.new
14
+ end
15
+
16
+ def self.path *args
17
+ File.expand_path(File.join('..', '..', *args), __FILE__)
13
18
  end
14
19
  end
@@ -0,0 +1,78 @@
1
+ module RailsZero
2
+ class Config
3
+ class Backend
4
+ attr_accessor :url
5
+
6
+ def url
7
+ @url ||= 'http://localhost:3000'
8
+ end
9
+ end
10
+
11
+ class GitDeployment
12
+ attr_accessor :url,
13
+ :git_binary
14
+
15
+ def git_binary
16
+ @git_binary ||=
17
+ File.expand_path(File.join('..', '..', '..', 'bin', 'git'), __FILE__)
18
+ end
19
+ end
20
+
21
+ class Site
22
+ attr_writer :paths, :paths_builders
23
+
24
+ def paths
25
+ paths = []
26
+ paths.concat(@paths) if defined?(@paths)
27
+ paths.concat(map_paths_from_paths_builders)
28
+ paths.flatten
29
+ end
30
+
31
+ def add_paths paths
32
+ @paths ||= []
33
+ @paths << paths
34
+ end
35
+
36
+ def add_path path
37
+ @paths ||= []
38
+ @paths << path
39
+ end
40
+
41
+ def define_lazy_paths &block
42
+ @lazy_paths = block
43
+ end
44
+
45
+ def paths_to_except_from_cleanup
46
+ @paths_to_except_from_cleanup ||= begin
47
+ %w[ 404.html
48
+ 422.html
49
+ 500.html
50
+ favicon.ico
51
+ ].map do |f|
52
+ Rails.root.join('public', f).to_s
53
+ end
54
+ end
55
+ end
56
+
57
+ private
58
+
59
+ def map_paths_from_paths_builders
60
+ if defined? @paths_builders
61
+ @paths_builders.map{|b| b.call}
62
+ else
63
+ []
64
+ end
65
+ end
66
+ end
67
+
68
+ attr_reader :backend,
69
+ :deployment,
70
+ :site
71
+
72
+ def initialize
73
+ @backend = Backend.new
74
+ @deployment = GitDeployment.new
75
+ @site = Site.new
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ require 'capybara/poltergeist'
2
+ Capybara.register_driver :poltergeist do |app|
3
+ Capybara::Poltergeist::Driver.new(app, {:timeout => 120,
4
+ :js_errors => false})
5
+ end
6
+ Capybara.javascript_driver = :poltergeist
7
+ Capybara.default_driver = :poltergeist
@@ -1,3 +1,3 @@
1
1
  module RailsZero
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,13 @@
1
+ namespace :rails_zero do
2
+ desc 'Generates the Site on the Remote'
3
+ task :generate => :environment do
4
+ RailsZero::GenerateSiteJob.new.run
5
+ end
6
+
7
+ namespace :deploy do
8
+ desc 'Git deployment'
9
+ task :git do
10
+ RailsZero::GitDeployer.new.run
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Bissinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-09 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capybara
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sqlite3
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,17 +80,19 @@ files:
66
80
  - app/clients/rails_zero/packages_client.rb
67
81
  - app/controllers/rails_zero/application_controller.rb
68
82
  - app/controllers/rails_zero/packages_controller.rb
83
+ - app/deployers/rails_zero/git_deployer.rb
69
84
  - app/helpers/rails_zero/application_helper.rb
70
85
  - app/jobs/rails_zero/clean_site_job.rb
71
86
  - app/jobs/rails_zero/generate_site_job.rb
72
87
  - app/views/layouts/rails_zero/application.html.erb
73
88
  - config/routes.rb
74
89
  - lib/rails-zero.rb
90
+ - lib/rails_zero/config.rb
91
+ - lib/rails_zero/drivers/poltergeist.rb
75
92
  - lib/rails_zero/engine.rb
76
- - lib/rails_zero/pages_config.rb
77
93
  - lib/rails_zero/version.rb
78
94
  - lib/rails_zero.rb
79
- - lib/tasks/rails_zero_tasks.rake
95
+ - lib/tasks/rails_zero.rake
80
96
  - MIT-LICENSE
81
97
  - Rakefile
82
98
  homepage: https://github.com/dpree/rails-zero
@@ -1,15 +0,0 @@
1
- module RailsZero
2
- class PagesConfig
3
- def links
4
- @links ||= []
5
- end
6
-
7
- def paths_to_except_from_cleanup
8
- @paths_to_except_from_cleanup ||= begin
9
- %w[ 404.html 422.html 500.html favicon.ico ].map do |f|
10
- Rails.root.join('public', f).to_s
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :rails_zero do
3
- # # Task goes here
4
- # end