nezu 0.5.11 → 0.5.13
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +15 -15
- data/README.md +10 -0
- data/VERSION +1 -1
- data/lib/nezu/generators/application/MANIFEST +2 -1
- data/lib/nezu/generators/application/templates/app/consumers/$app_name.rb.tt +1 -1
- data/lib/nezu/generators/application/templates/app/producers/pong.rb.tt +3 -0
- data/lib/nezu/generators.rb +1 -1
- data/lib/nezu/runner.rb +2 -2
- data/lib/nezu/runtime/consumer.rb +2 -12
- data/lib/nezu/runtime/producer.rb +2 -13
- data/lib/nezu/runtime.rb +35 -5
- data/lib/nezu.rb +7 -3
- data/lib/tasks/nezu_db.rake +94 -0
- data/spec/functional/runtime/consumer_spec.rb +4 -4
- data/spec/functional/runtime/producer_spec.rb +2 -2
- data/spec/support/sample_project/config/nezu.rb +2 -0
- metadata +11 -4
- data/lib/tasks/databases.rake +0 -112
- /data/lib/nezu/generators/application/templates/config/{database.yml.tt → database.yml.example.tt} +0 -0
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nezu (0.
|
4
|
+
nezu (0.5.13)
|
5
5
|
activerecord (~> 3.2.11)
|
6
6
|
activesupport (~> 3.2.11)
|
7
7
|
amqp
|
8
|
-
bunny (>= 0.9.0.
|
8
|
+
bunny (>= 0.9.0.pre8)
|
9
9
|
configatron
|
10
10
|
mysql2
|
11
11
|
term-ansicolor
|
@@ -13,23 +13,23 @@ PATH
|
|
13
13
|
GEM
|
14
14
|
remote: https://rubygems.org/
|
15
15
|
specs:
|
16
|
-
activemodel (3.2.
|
17
|
-
activesupport (= 3.2.
|
16
|
+
activemodel (3.2.13)
|
17
|
+
activesupport (= 3.2.13)
|
18
18
|
builder (~> 3.0.0)
|
19
|
-
activerecord (3.2.
|
20
|
-
activemodel (= 3.2.
|
21
|
-
activesupport (= 3.2.
|
19
|
+
activerecord (3.2.13)
|
20
|
+
activemodel (= 3.2.13)
|
21
|
+
activesupport (= 3.2.13)
|
22
22
|
arel (~> 3.0.2)
|
23
23
|
tzinfo (~> 0.3.29)
|
24
|
-
activesupport (3.2.
|
25
|
-
i18n (
|
24
|
+
activesupport (3.2.13)
|
25
|
+
i18n (= 0.6.1)
|
26
26
|
multi_json (~> 1.0)
|
27
|
-
amq-client (0.
|
27
|
+
amq-client (1.0.0)
|
28
28
|
amq-protocol (>= 1.2.0)
|
29
29
|
eventmachine
|
30
30
|
amq-protocol (1.2.0)
|
31
|
-
amqp (0.
|
32
|
-
amq-client (~> 0.
|
31
|
+
amqp (1.0.0)
|
32
|
+
amq-client (~> 1.0.0)
|
33
33
|
amq-protocol (~> 1.2.0)
|
34
34
|
eventmachine
|
35
35
|
arel (3.0.2)
|
@@ -48,9 +48,9 @@ GEM
|
|
48
48
|
debugger-ruby_core_source (1.2.0)
|
49
49
|
diff-lcs (1.2.1)
|
50
50
|
eventmachine (1.0.3)
|
51
|
-
i18n (0.6.
|
51
|
+
i18n (0.6.1)
|
52
52
|
json (1.7.7)
|
53
|
-
multi_json (1.
|
53
|
+
multi_json (1.7.1)
|
54
54
|
mysql2 (0.3.11)
|
55
55
|
rake (10.0.3)
|
56
56
|
rdoc (3.12.2)
|
@@ -66,7 +66,7 @@ GEM
|
|
66
66
|
sdoc (0.3.20)
|
67
67
|
json (>= 1.1.3)
|
68
68
|
rdoc (~> 3.10)
|
69
|
-
term-ansicolor (1.1.
|
69
|
+
term-ansicolor (1.1.4)
|
70
70
|
tzinfo (0.3.37)
|
71
71
|
yamler (0.1.0)
|
72
72
|
|
data/README.md
CHANGED
@@ -9,6 +9,16 @@ It has two major modes of usage:
|
|
9
9
|
2. (bundle exec) nezu run
|
10
10
|
inside your app folder starts your application and subscribes all your consumers to their appropriate queues
|
11
11
|
|
12
|
+
3. Start
|
13
|
+
amqp-consume --queue="test.pong.dev" cat
|
14
|
+
in other shell
|
15
|
+
|
16
|
+
4. Do
|
17
|
+
amqp-publish --routing-key=test.your_app_name.dev --body='{"__action":"ping","__reply_to":"test.pong.dev","test":23}'
|
18
|
+
in 3rd shell, now you should see the result:
|
19
|
+
{"test":23,"__action":"ping_result"}
|
20
|
+
in the output of amqp-consume an debug messages in "nezu run" output
|
21
|
+
|
12
22
|
*BIGFATALPHAWARNING:*
|
13
23
|
This hasn`t been fully tested yet. So if your working on a nuclear plant or so, go back to sleep this will be a lower risk
|
14
24
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.13
|
@@ -6,9 +6,10 @@ app/consumers/$app_name.rb.tt
|
|
6
6
|
app/consumers/.gitkeep
|
7
7
|
app/models/.gitkeep
|
8
8
|
app/producers/.gitkeep
|
9
|
+
app/producers/pong.rb.tt
|
9
10
|
config/amqp.yml.tt
|
10
11
|
config/boot.rb.tt
|
11
|
-
config/database.yml.tt
|
12
|
+
config/database.yml.example.tt
|
12
13
|
config/initializers/.gitkeep
|
13
14
|
config/nezu.rb.tt
|
14
15
|
db/.gitkeep
|
data/lib/nezu/generators.rb
CHANGED
@@ -5,7 +5,7 @@ require 'nezu/generators/application/app_generator'
|
|
5
5
|
module Nezu
|
6
6
|
module Generators
|
7
7
|
|
8
|
-
configatron.template_paths = [
|
8
|
+
configatron.template_paths = [Nezu.gem_path.join('lib/nezu/generators/application/templates')] + ENV['NEZU_TEMPLATES'].to_s.split(':')
|
9
9
|
configatron.file_suffixes = %w(tt)
|
10
10
|
|
11
11
|
def template_to(filename) # e.g. "config/amqp.yml"
|
data/lib/nezu/runner.rb
CHANGED
@@ -9,8 +9,8 @@ module Nezu
|
|
9
9
|
# this is the starting point for every application running with "$> nezu run"
|
10
10
|
# it get called from cli.rb
|
11
11
|
def self.start
|
12
|
-
AMQP.start(configatron.amqp.url) do |connection, open_ok|
|
13
|
-
Nezu.logger.debug("[Nezu Runner] AMQP connection #{configatron.amqp.url}")
|
12
|
+
AMQP.start(configatron.amqp.send(Nezu.env.to_sym).url) do |connection, open_ok|
|
13
|
+
Nezu.logger.debug("[Nezu Runner] AMQP connection #{configatron.amqp.send(Nezu.env.to_sym).url}")
|
14
14
|
channel = AMQP::Channel.new(connection, :auto_recovery => true)
|
15
15
|
Nezu.logger.debug("[Nezu Runner] AMQP channel #{channel}")
|
16
16
|
Nezu::Runtime::Consumer.descendants.each do |consumer|
|
@@ -1,23 +1,13 @@
|
|
1
1
|
module Nezu
|
2
2
|
module Runtime
|
3
3
|
class Consumer
|
4
|
-
|
5
|
-
subclass.class_eval {cattr_accessor :queue_name}
|
6
|
-
subclass.queue_name = ''
|
7
|
-
subclass.queue_name << "#{configatron.amqp.queue_prefix}." unless configatron.amqp.queue_prefix.nil?
|
8
|
-
subclass.queue_name << subclass.to_s.gsub(/::/, '.').underscore
|
9
|
-
subclass.queue_name << ".#{configatron.amqp.queue_postfix}" unless configatron.amqp.queue_postfix.nil?
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.descendants
|
13
|
-
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
14
|
-
end
|
4
|
+
extend Nezu::Runtime::Common
|
15
5
|
|
16
6
|
def handle_message(metadata, payload)
|
17
7
|
Nezu.logger.debug("NEZU Consumer[#{self.class}] payload: #{payload}")
|
18
8
|
params = JSON.parse(payload.to_s)
|
19
9
|
action = params.delete('__action')
|
20
|
-
reply_to = params
|
10
|
+
reply_to = params['__reply_to']
|
21
11
|
result = self.send(action.to_sym, params)
|
22
12
|
if reply_to
|
23
13
|
result.reverse_merge!('__action' => "#{action}_result")
|
@@ -1,21 +1,10 @@
|
|
1
1
|
module Nezu
|
2
2
|
module Runtime
|
3
3
|
class Producer
|
4
|
-
|
5
|
-
subclass.class_eval {cattr_accessor :queue_name} #:exchange_name?
|
6
|
-
subclass.queue_name = ''
|
7
|
-
subclass.queue_name << "#{configatron.amqp.queue_prefix}." unless configatron.amqp.queue_prefix.nil?
|
8
|
-
subclass.queue_name << subclass.to_s.gsub(/::/, '.').underscore
|
9
|
-
subclass.queue_name << ".#{configatron.amqp.queue_postfix}" unless configatron.amqp.queue_postfix.nil?
|
10
|
-
subclass.queue_name
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.descendants
|
14
|
-
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
15
|
-
end
|
4
|
+
extend Nezu::Runtime::Common
|
16
5
|
|
17
6
|
def self.push!(params = {})
|
18
|
-
conn = Bunny.new(configatron.amqp.url)
|
7
|
+
conn = Bunny.new(configatron.amqp.send(Nezu.env.to_sym).url)
|
19
8
|
conn.start
|
20
9
|
ch = conn.create_channel
|
21
10
|
q = ch.queue(queue_name)
|
data/lib/nezu/runtime.rb
CHANGED
@@ -14,10 +14,10 @@ module Nezu
|
|
14
14
|
Nezu.logger.fatal("[Nezu Runner] no amqp config please create one in config/amqp.yml") unless configatron.amqp.present?
|
15
15
|
raise
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
ActiveRecord::Base.establish_connection(configatron.database.to_hash)
|
20
|
-
ActiveRecord::Base.logger = Logger.new(
|
17
|
+
if configatron.database.send(Nezu.env).database.present? && !Class.const_defined?(:Rails)
|
18
|
+
require configatron.database.send(Nezu.env).adapter
|
19
|
+
ActiveRecord::Base.establish_connection(configatron.database.send(Nezu.env.to_sym).to_hash)
|
20
|
+
ActiveRecord::Base.logger = Logger.new(Nezu.root.join('log/', 'database.log'))
|
21
21
|
end
|
22
22
|
|
23
23
|
req_files = Dir.glob(Nezu.root.join('app', 'consumers', '*.rb'))
|
@@ -34,10 +34,40 @@ module Nezu
|
|
34
34
|
Nezu.logger.debug(configatron.amqp)
|
35
35
|
end
|
36
36
|
|
37
|
+
module Common
|
38
|
+
|
39
|
+
# creates a class method ::queue_name with a queue name derived from the class name and pre- and posfixes.
|
40
|
+
# e.g if a classes name is Foo the queue_name will be "your_prefix.foo.your_postfix"
|
41
|
+
# to avoid naming conflicts it is also possible to scope the class in modules "Producers" or "Consumers"
|
42
|
+
# so a somthing like:
|
43
|
+
#:code
|
44
|
+
# module Producers
|
45
|
+
# class FooBar < Nezu::Runtime::Producer
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# will result in a queue "your_prefix.foo_bar.your_postfix"
|
50
|
+
# the same goes for module "Consumers". This is especially useful if you need a consumer and a producer
|
51
|
+
# on the same queue
|
52
|
+
#
|
53
|
+
def inherited(subclass)
|
54
|
+
subclass.class_eval {cattr_accessor :queue_name} #:exchange_name?
|
55
|
+
subclass.queue_name = ''
|
56
|
+
subclass.queue_name << "#{configatron.amqp.send(Nezu.env.to_sym).queue_prefix}." unless configatron.amqp.send(Nezu.env.to_sym).queue_prefix.nil?
|
57
|
+
subclass.queue_name << subclass.to_s.gsub(/^(Producers|Consumers)::/, '').gsub(/::/, '.').underscore
|
58
|
+
subclass.queue_name << ".#{configatron.amqp.send(Nezu.env.to_sym).queue_postfix}" unless configatron.amqp.send(Nezu.env.to_sym).queue_postfix.nil?
|
59
|
+
subclass.queue_name
|
60
|
+
end
|
61
|
+
|
62
|
+
def descendants
|
63
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
37
67
|
private
|
38
68
|
|
39
69
|
def self.configure_from_yaml(yaml_file) #:nodoc:
|
40
|
-
yaml = YAML.load_file(Nezu.root.join('config', yaml_file))
|
70
|
+
yaml = YAML.load_file(Nezu.root.join('config', yaml_file))
|
41
71
|
configatron.configure_from_hash(File.basename(yaml_file.sub(/.yml/, '')) => yaml)
|
42
72
|
end
|
43
73
|
end
|
data/lib/nezu.rb
CHANGED
@@ -11,8 +11,6 @@ require 'nezu/runtime'
|
|
11
11
|
module Nezu
|
12
12
|
mattr_accessor :logger
|
13
13
|
|
14
|
-
GEM_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
15
|
-
|
16
14
|
#used by Nezu.env and Nezu.env.developent? etc.
|
17
15
|
class Env < String
|
18
16
|
def method_missing(meth, params=nil) #:nodoc:
|
@@ -28,11 +26,12 @@ module Nezu
|
|
28
26
|
|
29
27
|
class Root < String
|
30
28
|
APP_PATH = self.new(File.expand_path(Dir.pwd))
|
29
|
+
GEM_PATH = self.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
31
30
|
|
32
31
|
# you can do Nezu.root.join('path', 'to', 'your', 'stuff') and get the
|
33
32
|
# absolute path of your stuff
|
34
33
|
def join(*params)
|
35
|
-
File.join(
|
34
|
+
File.join(self, params)
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
@@ -106,6 +105,11 @@ module Nezu
|
|
106
105
|
Root::APP_PATH
|
107
106
|
end
|
108
107
|
|
108
|
+
# Returns a String like object with the gems absolute root
|
109
|
+
def self.gem_path
|
110
|
+
Root::GEM_PATH
|
111
|
+
end
|
112
|
+
|
109
113
|
# turn errors into warnings if used in verbose mode (Nezu.try(true) { ... })
|
110
114
|
# useful if you find it acceptable that something isn't
|
111
115
|
# working
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#require 'nezu/runner'
|
2
|
+
require 'active_support/core_ext/object/inclusion'
|
3
|
+
require 'active_record'
|
4
|
+
require 'debugger'
|
5
|
+
|
6
|
+
namespace :nezu do
|
7
|
+
db_namespace = namespace :db do
|
8
|
+
task :load_config do
|
9
|
+
Nezu.logger.level = Logger::INFO
|
10
|
+
Nezu::Runtime.load_config
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Create all the local databases defined in config/database.yml'
|
14
|
+
task :create => [:load_config] do
|
15
|
+
databases = YAML.load_file(File.join(Nezu.root.join('config', 'database.yml'))).map {|k,v| v }.uniq
|
16
|
+
databases.each do |db|
|
17
|
+
print "creating #{db['database']}..."
|
18
|
+
ActiveRecord::Base.establish_connection(db.merge({'database' => nil}))
|
19
|
+
ActiveRecord::Base.connection.create_database(db['database']) rescue (puts 'ERROR'; next)
|
20
|
+
puts 'done'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
|
25
|
+
task :migrate => [:load_config] do
|
26
|
+
ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
|
27
|
+
ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration|
|
28
|
+
ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope)
|
29
|
+
end
|
30
|
+
db_namespace["schema:dump"].invoke
|
31
|
+
end
|
32
|
+
|
33
|
+
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
34
|
+
task :rollback => [:load_config] do
|
35
|
+
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
36
|
+
ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
|
37
|
+
db_namespace['schema:dump'].invoke
|
38
|
+
end
|
39
|
+
|
40
|
+
namespace :migrate do
|
41
|
+
# desc 'Resets your database using your migrations for the current environment'
|
42
|
+
#task :reset => ['db:drop', 'db:create', 'db:migrate']
|
43
|
+
|
44
|
+
desc 'Runs the "up" for a given migration VERSION.'
|
45
|
+
task :up => [:load_config] do
|
46
|
+
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
47
|
+
raise 'VERSION is required' unless version
|
48
|
+
ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_paths, version)
|
49
|
+
db_namespace['dump'].invoke
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Runs the "down" for a given migration VERSION.'
|
53
|
+
task :down => [:load_config] do
|
54
|
+
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
55
|
+
raise 'VERSION is required' unless version
|
56
|
+
ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_paths, version)
|
57
|
+
db_namespace['_dump'].invoke
|
58
|
+
end
|
59
|
+
|
60
|
+
# desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
61
|
+
task :redo => [:load_config] do
|
62
|
+
if ENV['VERSION']
|
63
|
+
db_namespace['migrate:down'].invoke
|
64
|
+
db_namespace['migrate:up'].invoke
|
65
|
+
else
|
66
|
+
db_namespace['rollback'].invoke
|
67
|
+
db_namespace['migrate'].invoke
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
namespace :schema do
|
73
|
+
desc 'Create a db/schema.rb file'
|
74
|
+
task :dump => [:load_config] do
|
75
|
+
require 'active_record/schema_dumper'
|
76
|
+
filename = ENV['SCHEMA'] || "#{Nezu.root}/db/schema.rb"
|
77
|
+
File.open(filename, "w:utf-8") do |file|
|
78
|
+
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
desc 'Create a db from schema.rb file'
|
83
|
+
task :load => [:load_config] do
|
84
|
+
#require 'active_record/schema_dumper'
|
85
|
+
#filename = ENV['SCHEMA'] || "#{Nezu.root}/db/schema.rb"
|
86
|
+
#File.open(filename, "w:utf-8") do |file|
|
87
|
+
#ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
88
|
+
#end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
@@ -30,17 +30,17 @@ describe Nezu::Runtime::Consumer do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should use the queue_prefix if its set' do
|
33
|
-
configatron.amqp.queue_prefix = 'the_prefix'
|
33
|
+
configatron.amqp.send(Nezu.env.to_sym).queue_prefix = 'the_prefix'
|
34
34
|
module JustAModule;class ConsumerWithPrefix<Nezu::Runtime::Consumer;end;end
|
35
35
|
JustAModule::ConsumerWithPrefix.queue_name.should == 'the_prefix.just_a_module.consumer_with_prefix'
|
36
|
-
configatron.amqp.queue_prefix = nil
|
36
|
+
configatron.amqp.send(Nezu.env.to_sym).queue_prefix = nil
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'should use the queue_postfix if its set' do
|
40
|
-
configatron.amqp.queue_postfix = 'the_postfix'
|
40
|
+
configatron.amqp.send(Nezu.env.to_sym).queue_postfix = 'the_postfix'
|
41
41
|
module JustAModule;class ConsumerWithPostfix<Nezu::Runtime::Consumer;end;end
|
42
42
|
JustAModule::ConsumerWithPostfix.queue_name.should == 'just_a_module.consumer_with_postfix.the_postfix'
|
43
|
-
configatron.amqp.queue_postfix = nil
|
43
|
+
configatron.amqp.send(Nezu.env.to_sym).queue_postfix = nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -7,8 +7,8 @@ describe Nezu::Runtime::Producer do
|
|
7
7
|
|
8
8
|
describe '::push!' do
|
9
9
|
it 'should create a new message on the server' do
|
10
|
-
configatron.amqp.url = 'amqp://127.0.0.1'
|
11
|
-
Bunny.should_receive(:new).with(configatron.amqp.url).and_return(AlwaysHappy.new)
|
10
|
+
configatron.amqp.send(Nezu.env.to_sym).url = 'amqp://127.0.0.1'
|
11
|
+
Bunny.should_receive(:new).with(configatron.amqp.send(Nezu.env.to_sym).url).and_return(AlwaysHappy.new)
|
12
12
|
module ExampleProducers;class MyQueue<Nezu::Runtime::Producer;end;end
|
13
13
|
ExampleProducers::MyQueue.push!(:foo => 'bar')
|
14
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nezu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.13
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-03-
|
13
|
+
date: 2013-03-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: amqp
|
@@ -217,9 +217,10 @@ files:
|
|
217
217
|
- lib/nezu/generators/application/templates/app/consumers/.gitkeep
|
218
218
|
- lib/nezu/generators/application/templates/app/models/.gitkeep
|
219
219
|
- lib/nezu/generators/application/templates/app/producers/.gitkeep
|
220
|
+
- lib/nezu/generators/application/templates/app/producers/pong.rb.tt
|
220
221
|
- lib/nezu/generators/application/templates/config/amqp.yml.tt
|
221
222
|
- lib/nezu/generators/application/templates/config/boot.rb.tt
|
222
|
-
- lib/nezu/generators/application/templates/config/database.yml.tt
|
223
|
+
- lib/nezu/generators/application/templates/config/database.yml.example.tt
|
223
224
|
- lib/nezu/generators/application/templates/config/initializers/.gitkeep
|
224
225
|
- lib/nezu/generators/application/templates/config/nezu.rb.tt
|
225
226
|
- lib/nezu/generators/application/templates/db/.gitkeep
|
@@ -231,7 +232,7 @@ files:
|
|
231
232
|
- lib/nezu/runtime/producer.rb
|
232
233
|
- lib/nezu/runtime/recipient.rb
|
233
234
|
- lib/nezu/runtime/worker.rb
|
234
|
-
- lib/tasks/
|
235
|
+
- lib/tasks/nezu_db.rake
|
235
236
|
- nezu.gemspec
|
236
237
|
- spec/functional/generators/app_generator_spec.rb
|
237
238
|
- spec/functional/generators_spec.rb
|
@@ -272,12 +273,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
272
273
|
- - ! '>='
|
273
274
|
- !ruby/object:Gem::Version
|
274
275
|
version: '0'
|
276
|
+
segments:
|
277
|
+
- 0
|
278
|
+
hash: -1835155368988834994
|
275
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
280
|
none: false
|
277
281
|
requirements:
|
278
282
|
- - ! '>='
|
279
283
|
- !ruby/object:Gem::Version
|
280
284
|
version: '0'
|
285
|
+
segments:
|
286
|
+
- 0
|
287
|
+
hash: -1835155368988834994
|
281
288
|
requirements: []
|
282
289
|
rubyforge_project:
|
283
290
|
rubygems_version: 1.8.23
|
data/lib/tasks/databases.rake
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
#require 'nezu/runner'
|
2
|
-
require 'active_support/core_ext/object/inclusion'
|
3
|
-
require 'active_record'
|
4
|
-
require 'debugger'
|
5
|
-
|
6
|
-
#def load_config
|
7
|
-
#yaml = YAML.load_file(File.join(Nezu.root.join('config', 'database.yml')))
|
8
|
-
#configatron.databases.configure_from_hash(yaml)
|
9
|
-
#end
|
10
|
-
|
11
|
-
def connect_to(env, without_db=false)
|
12
|
-
config = configatron.databases.send(env).to_hash
|
13
|
-
config.delete(:database) if without_db
|
14
|
-
@connection = ActiveRecord::Base.establish_connection(config)
|
15
|
-
end
|
16
|
-
|
17
|
-
db_namespace = namespace :db do
|
18
|
-
task :load_config do
|
19
|
-
yaml = YAML.load_file(File.join(Nezu.root.join('config', 'database.yml')))
|
20
|
-
configatron.databases.configure_from_hash(yaml)
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'Create all the local databases defined in config/database.yml'
|
24
|
-
task :create do
|
25
|
-
begin
|
26
|
-
load_config
|
27
|
-
configatron.databases.to_hash.each do |k,v|
|
28
|
-
print "creating #{k}`s db (#{v}) ... "
|
29
|
-
connect_to(k, true)
|
30
|
-
ActiveRecord::Base.connection.create_database(v[:database])
|
31
|
-
puts 'done'
|
32
|
-
end
|
33
|
-
rescue Mysql2::Error => e
|
34
|
-
puts "not done (#{e.to_s})"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
task :migrate => [:load_config] do
|
39
|
-
connect_to(Nezu.env)
|
40
|
-
if ENV['VERSION']
|
41
|
-
db_namespace['migrate:down'].invoke
|
42
|
-
db_namespace['migrate:up'].invoke
|
43
|
-
else
|
44
|
-
ActiveRecord::Migrator.migrate(Nezu.root.join('db', 'migrate')) do |migration|
|
45
|
-
migration.migrate(:up)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
desc 'Rolls the schema back to the previous version (specify steps w/ STEP=n).'
|
51
|
-
task :rollback => [:environment, :load_config] do
|
52
|
-
connect_to(Nezu.env)
|
53
|
-
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
54
|
-
ActiveRecord::Migrator.rollback(ActiveRecord::Migrator.migrations_paths, step)
|
55
|
-
db_namespace['schema:dump'].invoke
|
56
|
-
end
|
57
|
-
|
58
|
-
namespace :migrate do
|
59
|
-
# desc 'Resets your database using your migrations for the current environment'
|
60
|
-
#task :reset => ['db:drop', 'db:create', 'db:migrate']
|
61
|
-
|
62
|
-
desc 'Runs the "up" for a given migration VERSION.'
|
63
|
-
task :up => [:environment, :load_config] do
|
64
|
-
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
65
|
-
raise 'VERSION is required' unless version
|
66
|
-
ActiveRecord::Migrator.run(:up, ActiveRecord::Migrator.migrations_paths, version)
|
67
|
-
db_namespace['dump'].invoke
|
68
|
-
end
|
69
|
-
|
70
|
-
desc 'Runs the "down" for a given migration VERSION.'
|
71
|
-
task :down => [:environment, :load_config] do
|
72
|
-
version = ENV['VERSION'] ? ENV['VERSION'].to_i : nil
|
73
|
-
raise 'VERSION is required' unless version
|
74
|
-
ActiveRecord::Migrator.run(:down, ActiveRecord::Migrator.migrations_paths, version)
|
75
|
-
db_namespace['_dump'].invoke
|
76
|
-
end
|
77
|
-
|
78
|
-
# desc 'Rollbacks the database one migration and re migrate up (options: STEP=x, VERSION=x).'
|
79
|
-
task :redo => [:environment, :load_config] do
|
80
|
-
if ENV['VERSION']
|
81
|
-
db_namespace['migrate:down'].invoke
|
82
|
-
db_namespace['migrate:up'].invoke
|
83
|
-
else
|
84
|
-
db_namespace['rollback'].invoke
|
85
|
-
db_namespace['migrate'].invoke
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
namespace :schema do
|
91
|
-
desc 'Create a db/schema.rb file'
|
92
|
-
task :dump => [:environment, :load_config] do
|
93
|
-
require 'active_record/schema_dumper'
|
94
|
-
connect_to(Nezu.env)
|
95
|
-
filename = ENV['SCHEMA'] || "#{Nezu.root}/db/schema.rb"
|
96
|
-
File.open(filename, "w:utf-8") do |file|
|
97
|
-
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
desc 'Create a db from schema.rb file'
|
102
|
-
task :load => [:load_config] do
|
103
|
-
#require 'active_record/schema_dumper'
|
104
|
-
connect_to(Nezu.env)
|
105
|
-
#filename = ENV['SCHEMA'] || "#{Nezu.root}/db/schema.rb"
|
106
|
-
#File.open(filename, "w:utf-8") do |file|
|
107
|
-
#ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
108
|
-
#end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
/data/lib/nezu/generators/application/templates/config/{database.yml.tt → database.yml.example.tt}
RENAMED
File without changes
|