shared_tasks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +1 -0
- data/lib/generators/shared_tasks/install_generator.rb +32 -0
- data/lib/generators/shared_tasks/shared_task_generator.rb +50 -0
- data/lib/generators/shared_tasks/templates/migration.rb +8 -0
- data/lib/shared_tasks/config.rb +14 -0
- data/lib/shared_tasks/railtie.rb +8 -0
- data/lib/shared_tasks/version.rb +3 -0
- data/lib/shared_tasks.rb +146 -0
- data/lib/tasks/shared_tasks.rake +15 -0
- data/shared_tasks.gemspec +23 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2564ee3cca5554fc703870b9faac5f6bd14fd8d4
|
4
|
+
data.tar.gz: 29571d5fcfc739fc9d472e2d8f5f0ada0dc4b296
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 525c96feb63c3be019e4cf5a1efeaef97a0bcffa2aca3c6807f81095303a8665599c051e85141d98ab4a1661e327e5861fce945db94f9065b0c7a36b65fd2eae
|
7
|
+
data.tar.gz: 15c9c7db7157f72f76200a9db0b75e0dd9637dd9ab3443c459c4853a81801970f34aaa66b5d88d902c701498c41bd753908d4c14b001a213893989db00377686
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Erick
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# SharedTasks
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'shared_tasks'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install shared_tasks
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Generate migration and shared_tasks folder
|
22
|
+
|
23
|
+
$ rails g shared_tasks:install
|
24
|
+
|
25
|
+
Create a new task
|
26
|
+
|
27
|
+
$ rails g shared_tasks:shared_task new_task_name
|
28
|
+
|
29
|
+
Run tasks
|
30
|
+
|
31
|
+
$ rake shared_tasks:tasks
|
32
|
+
|
33
|
+
Run single task
|
34
|
+
|
35
|
+
$ rake shared_tasks:task[file_name, task_name]
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
1. Fork it
|
43
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
44
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
45
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
46
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module SharedTasks
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
desc "Generates tasks migration"
|
8
|
+
|
9
|
+
# Commandline options can be defined here using Thor-like options:
|
10
|
+
# class_option :my_opt, :type => :boolean, :default => false, :desc => "My Option"
|
11
|
+
# I can later access that option using:
|
12
|
+
# options[:my_opt]
|
13
|
+
# Code goes here ;)
|
14
|
+
# source_root File.expand_path("../templates", __FILE__)
|
15
|
+
|
16
|
+
route_file = File.join(File.dirname(__FILE__), "templates/")
|
17
|
+
source_root route_file
|
18
|
+
#puts route_file
|
19
|
+
|
20
|
+
def self.next_migration_number(path)
|
21
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_migration
|
25
|
+
migration_template 'migration.rb', "db/migrate/create_shared_tasks"
|
26
|
+
empty_directory("lib/shared_tasks")
|
27
|
+
end
|
28
|
+
|
29
|
+
# Generator Code. Remember this is just suped-up Thor so methods are executed in order
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module SharedTasks
|
4
|
+
module Generators
|
5
|
+
class SharedTaskGenerator < Rails::Generators::NamedBase
|
6
|
+
#rails g shared_task file_name
|
7
|
+
desc "Creates a file for a shared task"
|
8
|
+
def create_initializer_file
|
9
|
+
verify_name
|
10
|
+
number = ActiveRecord::Migration.next_migration_number(1)
|
11
|
+
full_name = "#{number}_#{file_name.underscore}"
|
12
|
+
puts "Generating file #{full_name}"
|
13
|
+
create_file "lib/shared_tasks/#{full_name}.rb", file_content
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def file_content
|
20
|
+
%(class #{file_name.camelize}Shared
|
21
|
+
|
22
|
+
class << self
|
23
|
+
|
24
|
+
def method_1
|
25
|
+
#Actions to execute
|
26
|
+
end
|
27
|
+
|
28
|
+
def destroy_actions
|
29
|
+
#Actions before destroy
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def verify_name
|
39
|
+
route = "#{Rails.root}/lib/shared_tasks"
|
40
|
+
files = Dir.entries(route).select {|f| !File.directory? f}.map{|f| f.split("_").drop(1).join("_").split(".").remove_last(1)}.flatten
|
41
|
+
if files.include?("#{file_name}")
|
42
|
+
message = "There is a file with same name. -Change file name-"
|
43
|
+
puts message.center(100, ".")
|
44
|
+
raise message
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/shared_tasks.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
require "shared_tasks/version"
|
2
|
+
require "shared_tasks/config"
|
3
|
+
require 'shared_tasks/railtie' ##Esential!
|
4
|
+
|
5
|
+
Array.module_eval do
|
6
|
+
def remove_last(n = 1)
|
7
|
+
self.first(self.size - n)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
module SharedTasks
|
13
|
+
# Your code goes here...
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def config
|
17
|
+
@@config ||= SharedTasks::Config.instance
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Task < ::ActiveRecord::Base
|
22
|
+
self.table_name = SharedTasks.config.table_name
|
23
|
+
before_destroy :rollback_actions
|
24
|
+
|
25
|
+
|
26
|
+
def rollback_actions
|
27
|
+
@file = Dir.entries(route).select {|f| !File.directory?(f) && f.include?(self.task) }.first
|
28
|
+
if @file && File.exist?(file_route)
|
29
|
+
load_file
|
30
|
+
run_task("destroy_actions")
|
31
|
+
else
|
32
|
+
message = "There isnt a file with name given - destroying data"
|
33
|
+
puts message.center(100, ".")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def route
|
39
|
+
"lib/shared_tasks"
|
40
|
+
end
|
41
|
+
|
42
|
+
def file_route
|
43
|
+
"lib/shared_tasks/#{@file}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_file
|
47
|
+
load(file_route)
|
48
|
+
end
|
49
|
+
|
50
|
+
def file_name
|
51
|
+
@file.split("_").drop(1).join("_").split(".").remove_last.first
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_task(task = file_name)
|
55
|
+
class_name = "#{file_name.camelize}Shared".constantize
|
56
|
+
task_to_run = "#{class_name}.#{task}"
|
57
|
+
puts ".......#{@file}..=> #{task_to_run}......"
|
58
|
+
if class_name.respond_to?(task.to_sym)
|
59
|
+
eval(task_to_run)
|
60
|
+
else
|
61
|
+
puts "method not allowed"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
public
|
67
|
+
|
68
|
+
class << self
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def run_tasks
|
74
|
+
puts "Running shared tasks"
|
75
|
+
files = Dir.entries(route).select {|f| !File.directory?(f)}
|
76
|
+
files.each do |file|
|
77
|
+
@file = file
|
78
|
+
SharedTasks::Task.where(task: file_date).first_or_create do
|
79
|
+
load_and_run_task if File.exist?(file_route)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def run_single_task(name, task)
|
86
|
+
@file = Dir.entries(route).select {|f| (!File.directory?(f) && f.include?("#{name}")) }.first
|
87
|
+
if @file && File.exist?(file_route)
|
88
|
+
load_and_run_task(task)
|
89
|
+
else
|
90
|
+
message = "There isnt a file with name given"
|
91
|
+
puts message.center(100, ".")
|
92
|
+
raise message
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def load_and_run_task(task = file_name)
|
97
|
+
load_file
|
98
|
+
run_task(task)
|
99
|
+
end
|
100
|
+
|
101
|
+
def load_file
|
102
|
+
load(file_route)
|
103
|
+
end
|
104
|
+
|
105
|
+
def run_task(task = file_name)
|
106
|
+
class_name = "#{file_name.camelize}Shared".constantize
|
107
|
+
puts "Start at #{Time.zone.now}"
|
108
|
+
if task == file_name
|
109
|
+
class_name.methods(false).each do |metad|
|
110
|
+
if metad != :destroy_actions && metad != :_validators
|
111
|
+
puts "Running: #{metad.to_s} at #{Time.zone.now}"
|
112
|
+
eval("#{class_name}.#{metad.to_s}")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
else
|
116
|
+
if class_name.methods(false).include?(task.to_sym)
|
117
|
+
puts "Running single task: #{task} at #{Time.zone.now}"
|
118
|
+
eval("#{class_name}.#{task}")
|
119
|
+
else
|
120
|
+
raise "There isnt a task with name given => #{class_name}.#{task} "
|
121
|
+
end
|
122
|
+
end
|
123
|
+
puts "End at #{Time.zone.now}"
|
124
|
+
end
|
125
|
+
|
126
|
+
def route
|
127
|
+
"lib/shared_tasks"
|
128
|
+
end
|
129
|
+
|
130
|
+
def file_route
|
131
|
+
"lib/shared_tasks/#{@file}"
|
132
|
+
end
|
133
|
+
|
134
|
+
def file_name
|
135
|
+
@file.split("_").drop(1).join("_").split(".").remove_last.first
|
136
|
+
end
|
137
|
+
|
138
|
+
def file_date
|
139
|
+
@file.split("_").shift
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
#/Public
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :shared_tasks do
|
2
|
+
|
3
|
+
#rake shared_tasks:tasks
|
4
|
+
desc "Run shared tasks"
|
5
|
+
task :tasks => :environment do
|
6
|
+
SharedTasks::Task.run_tasks
|
7
|
+
end
|
8
|
+
|
9
|
+
#rake shared_tasks:task[file_name,task_name]
|
10
|
+
desc "Run single task"
|
11
|
+
task :task, [:file_name, :task_name] => :environment do |t, args|
|
12
|
+
SharedTasks::Task.run_single_task(args.file_name, args.task_name)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shared_tasks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "shared_tasks"
|
8
|
+
spec.version = SharedTasks::VERSION
|
9
|
+
spec.authors = ["Erick"]
|
10
|
+
spec.email = ["erick_8911@hotmail.com"]
|
11
|
+
spec.description = %q{Create tasks to run at different envs}
|
12
|
+
spec.summary = %q{Create tasks}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shared_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Create tasks to run at different envs
|
42
|
+
email:
|
43
|
+
- erick_8911@hotmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/generators/shared_tasks/install_generator.rb
|
54
|
+
- lib/generators/shared_tasks/shared_task_generator.rb
|
55
|
+
- lib/generators/shared_tasks/templates/migration.rb
|
56
|
+
- lib/shared_tasks.rb
|
57
|
+
- lib/shared_tasks/config.rb
|
58
|
+
- lib/shared_tasks/railtie.rb
|
59
|
+
- lib/shared_tasks/version.rb
|
60
|
+
- lib/tasks/shared_tasks.rake
|
61
|
+
- shared_tasks.gemspec
|
62
|
+
homepage: ''
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.5
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Create tasks
|
86
|
+
test_files: []
|