after_party 0.0.1 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1fc9b24b5cfb9e2f0e46f71e1122ee2ceb80e7f
4
+ data.tar.gz: 022ed0dff055749f8b7e52d408bb9139d8d0780a
5
+ SHA512:
6
+ metadata.gz: e8f29fb1a2b000228c482ac6593939ceb8e957310e22aeddd9588d5cab051fd12af99b41f25cdfe7a8dac1dbc7c67366c67b0deb982438ebb1eca687a550d078
7
+ data.tar.gz: a40296c727981c5a40bc021b70999c24677f3b3620c4f42a83cd2cb99f22d112c6ab4b44ff8698f71f3032f4a6c8993bfab097677e4838ee70e18faf8e3c6f5c
@@ -0,0 +1,7 @@
1
+ module AfterParty
2
+ require "after_party/railtie.rb" if defined?(Rails)
3
+
4
+ def self.setup
5
+ yield self
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require "after_party/models/active_record/task_record.rb"
@@ -0,0 +1,8 @@
1
+ class TaskRecord < ActiveRecord::Base
2
+ attr_accessible :version
3
+
4
+ def self.completed_task?(version)
5
+ all.any?{|t| t.version == version}
6
+ end
7
+
8
+ end
@@ -0,0 +1,13 @@
1
+ class TaskRecord
2
+ include Mongoid::Document
3
+ include Mongoid::Timestamps
4
+
5
+ field :version, type: String
6
+
7
+
8
+ def self.completed_task?(version)
9
+ all.any?{|t| t.version == version}
10
+ end
11
+
12
+ end
13
+
@@ -0,0 +1,27 @@
1
+
2
+
3
+ class TaskRecorder
4
+ include ActiveModel::Naming
5
+ attr_reader :filename, :timestamp, :task_name
6
+
7
+ FILE_MASK = File.join(Rails.root, "lib/tasks/deployment/*.rake")
8
+
9
+ def self.pending_files
10
+ Dir[FILE_MASK].collect{ |f| TaskRecorder.new(f) }.select{ |f| f.pending? }.sort{ |x,y| x.timestamp <=> y.timestamp }
11
+ end
12
+
13
+ def initialize(filename='')
14
+ @filename = filename
15
+ parse_filename
16
+ end
17
+
18
+ def pending?
19
+ timestamp && !TaskRecord.completed_task?(timestamp)
20
+ end
21
+
22
+ def parse_filename
23
+ /(\d+)_(.+)\.rake/.match(Pathname(@filename).basename.to_s)
24
+ @timestamp = $1
25
+ @task_name = $2
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require "after_party/models/mongoid/task_record.rb"
@@ -0,0 +1,22 @@
1
+ require 'after_party'
2
+ require 'after_party'
3
+ require 'rails'
4
+ module AfterParty
5
+ class Railtie < Rails::Railtie
6
+ #railtie is loaded from lib/after_party.rb. So all load paths need to be relative to /lib
7
+ rake_tasks do
8
+ load "tasks/deploy_task_runner.rake"
9
+ end
10
+
11
+ initializer "load_task_record_models" do
12
+ load "after_party/models/task_recorder.rb"
13
+ end
14
+
15
+ generators do
16
+ load "generators/task/task_generator.rb"
17
+ load "generators/install/install_generator.rb"
18
+ end
19
+ end
20
+
21
+
22
+ end
@@ -0,0 +1,17 @@
1
+ Description:
2
+ Generates the required files for after_party to generate and run deploy tasks
3
+ Accepts an optional parameter as the name of your ORM, default is "active_record", also accepts "mongoid"
4
+
5
+ Example:
6
+ rails generate after_party:install
7
+
8
+ This will create:
9
+ config/initializers/after_party.rb
10
+ db/migrate/{timestamp}_create_task_records.rb
11
+
12
+ Non-migrating ORMs:
13
+ rails generate after_party:install mongoid
14
+
15
+ This will create:
16
+ config/initializers/after_party.rb
17
+
@@ -0,0 +1,42 @@
1
+ require 'rails/generators'
2
+
3
+ module AfterParty
4
+ module Generators
5
+
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ argument :orm_name, :type => :string, :default => "active_record"
9
+
10
+ def create_initializer_file
11
+ template "after_party.rb", "config/initializers/after_party.rb"
12
+ end
13
+
14
+ def copy_migration
15
+ if requires_migration?
16
+ template "migration.rb", "db/migrate/#{timestamp}_create_#{table_name}.rb"
17
+ end
18
+ end
19
+
20
+ private
21
+ def timestamp
22
+ @timestamp ||= Time.now.utc.strftime("%Y%m%d%H%M%S")
23
+ end
24
+
25
+ def migration_exists?
26
+ absolute = File.expand_path("db/migrate/", destination_root)
27
+ #dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
28
+ Dir.glob("#{absolute}/[0-9]*_create_#{table_name}.rb").first
29
+ end
30
+
31
+ def requires_migration?
32
+ orm_name == "active_record" && !migration_exists?
33
+ end
34
+
35
+ def table_name
36
+ table = "task_record"
37
+ ActiveRecord::Base.pluralize_table_names ? table.pluralize : table
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,7 @@
1
+ AfterParty.setup do |config|
2
+ # ==> ORM configuration
3
+ # Load and configure the ORM. Supports :active_record (default) and
4
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
5
+ # available as additional gems.
6
+ require "after_party/<%= orm_name %>.rb"
7
+ end
@@ -0,0 +1,7 @@
1
+ class CreateTaskRecords < ActiveRecord::Migration
2
+ def change
3
+ create_table <%= table_name %>, :id => false do |t|
4
+ t.string :version, :null => false
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates a rake task that will be included at the end of the deployment task. An optional
3
+ second parameter with the task description is recommended.
4
+
5
+ Example:
6
+ rails generate deploy_task data_update
7
+
8
+ This will create:
9
+ lib/tasks/deployment/<timestamp>_data_update.rake
@@ -0,0 +1,29 @@
1
+ require 'date'
2
+ module AfterParty
3
+ module Generators
4
+ class TaskGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ argument :name, :type => :string
7
+ argument :description, :type => :string, :default => :nil
8
+
9
+ def copy_deploy_task
10
+
11
+ template "deploy.rake", "lib/tasks/deployment/#{timestamp}_#{file_name}.rake"
12
+
13
+ end
14
+
15
+ private
16
+ def file_name
17
+ name.underscore.tr(" ", "_")
18
+ end
19
+
20
+ def task_description
21
+ "Deployment task: #{description || file_name}"
22
+ end
23
+
24
+ def timestamp
25
+ @timestamp ||= Time.now.utc.strftime("%Y%m%d%H%M%S")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ namespace :after_party do
2
+
3
+ desc "<%= task_description %>"
4
+ task :<%= file_name %> => :environment do
5
+ Dir[Rails.root.join("lib/after_party/*.rb")].each {|f| require f}
6
+ puts "running deploy task '<%= file_name %>'"
7
+
8
+ # put your task implementation here
9
+
10
+ # update task as completed. If you remove the line below, the task will run with every deploy (or every time you call after_party:run)
11
+ TaskRecord.create :version => '<%= timestamp %>'
12
+ end
13
+
14
+ end
@@ -0,0 +1,13 @@
1
+ namespace :after_party do
2
+ desc "runs (in order) all pending after_party deployment tasks, if they have not run yet against the current db."
3
+ task :run => :environment do
4
+ tasks = TaskRecorder.pending_files.map {|f| "after_party:#{f.task_name}"}
5
+
6
+ tasks.each {|t| Rake::Task[t].invoke}
7
+
8
+ if tasks.empty?
9
+ puts "no pending tasks to run"
10
+ end
11
+
12
+ end
13
+ end
metadata CHANGED
@@ -1,45 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: after_party
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: '1.1'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Steve Mitchell
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
11
+ date: 2013-12-30 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description:
15
14
  email:
16
15
  executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
- files: []
18
+ files:
19
+ - lib/after_party/active_record.rb
20
+ - lib/after_party/models/active_record/task_record.rb
21
+ - lib/after_party/models/mongoid/task_record.rb
22
+ - lib/after_party/models/task_recorder.rb
23
+ - lib/after_party/mongoid.rb
24
+ - lib/after_party/railtie.rb
25
+ - lib/after_party.rb
26
+ - lib/generators/install/install_generator.rb
27
+ - lib/generators/install/templates/after_party.rb
28
+ - lib/generators/install/templates/migration.rb
29
+ - lib/generators/install/USAGE
30
+ - lib/generators/task/task_generator.rb
31
+ - lib/generators/task/templates/deploy.rake
32
+ - lib/generators/task/USAGE
33
+ - lib/tasks/deploy_task_runner.rake
20
34
  homepage: http://github.com/theSteveMitchell/after_party
21
35
  licenses: []
36
+ metadata: {}
22
37
  post_install_message:
23
38
  rdoc_options: []
24
39
  require_paths:
25
- - - lib
40
+ - lib
26
41
  required_ruby_version: !ruby/object:Gem::Requirement
27
- none: false
28
42
  requirements:
29
- - - ! '>='
43
+ - - '>='
30
44
  - !ruby/object:Gem::Version
31
45
  version: '0'
32
46
  required_rubygems_version: !ruby/object:Gem::Requirement
33
- none: false
34
47
  requirements:
35
- - - ! '>='
48
+ - - '>='
36
49
  - !ruby/object:Gem::Version
37
50
  version: '0'
38
51
  requirements: []
39
52
  rubyforge_project:
40
- rubygems_version: 1.8.24
53
+ rubygems_version: 2.0.6
41
54
  signing_key:
42
- specification_version: 3
55
+ specification_version: 4
43
56
  summary: Automated post-deploy tasks for Ruby/Rails. Your deployment is the party.
44
57
  This is the after party
45
58
  test_files: []