napa 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/napa/active_record_extensions/stats.rb +16 -12
- data/lib/napa/cli.rb +5 -2
- data/lib/napa/grape_extensions/grape_helpers.rb +1 -1
- data/lib/napa/version.rb +1 -1
- data/lib/tasks/db.rake +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2718b1367fa6291f248a6355cbd7805307d605ef
|
4
|
+
data.tar.gz: 66b0551ef54b97b7d73d5bcbd1521254f35df2b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8270a158da3bcc9fb032ff5f32efaef70c470d43580cdd11e37e77c812e2e29ee55a3ff4300c2652df3e4b96d0cd2c6f7763e43684f9d528546555f0b519ab3c
|
7
|
+
data.tar.gz: 33596208d45629e9fc4498c28cb3d5d25a2802a26ebec8ca1c19a4e44c10639ede89909e4298c7efa787fc927c9aaeed88415b048c2e916fe1ec45cb6b66bac0
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
master
|
2
2
|
===
|
3
3
|
|
4
|
+
0.2.1
|
5
|
+
===
|
6
|
+
* Updated Napa console. It now takes an optional environment parameter, i.e. `napa console production`.
|
7
|
+
* Added `c` alias for Napa console, i.e. `napa c` or `napa c production`
|
8
|
+
* Fixed a bug causing `rake db:schema:load` to fail
|
9
|
+
* Fixed a bug affecting `rake db:create` and `rake db:drop` using Postgres
|
10
|
+
* Fixed a bug Napa::GrapeHelpers to bypass the representer when given an array
|
11
|
+
|
4
12
|
0.2.0
|
5
13
|
===
|
6
14
|
* The console is now run with `napa console`, added support for racksh
|
@@ -16,22 +16,26 @@ if defined?(ActiveSupport)
|
|
16
16
|
[m[:table], 'SELECT']
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.
|
19
|
+
def self.extract_sql_updates(query)
|
20
20
|
m = query.match(SQL_UPDATE_REGEXP)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
[m[:table], 'UPDATE']
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.extract_sql_content(query)
|
25
|
+
table = action = nil
|
26
|
+
if query.match(SQL_UPDATE_REGEXP)
|
27
|
+
table, action = extract_sql_updates(query)
|
28
|
+
elsif query.match(SQL_SELECT_REGEXP)
|
29
|
+
table, action = extract_sql_selects(query)
|
30
|
+
elsif query.match(SQL_INSERT_DELETE_PARSER_REGEXP)
|
31
|
+
table, action = extract_from_sql_inserts_deletes(query)
|
25
32
|
end
|
33
|
+
[table, action]
|
26
34
|
end
|
27
35
|
|
28
36
|
ActiveSupport::Notifications.subscribe 'sql.active_record' do |name, start, finish, id, payload|
|
29
|
-
if payload[:
|
30
|
-
table, action =
|
31
|
-
elsif payload[:name] =~ /.* Load$/
|
32
|
-
table, action = extract_sql_selects(payload[:sql])
|
33
|
-
elsif !payload[:name]
|
34
|
-
table, action = guess_sql_content(payload[:sql])
|
37
|
+
if payload[:sql].match(/(select|update|insert|delete)(.+)/i)
|
38
|
+
table, action = extract_sql_content(payload[:sql])
|
35
39
|
end
|
36
40
|
|
37
41
|
if table
|
@@ -43,4 +47,4 @@ if defined?(ActiveSupport)
|
|
43
47
|
end
|
44
48
|
end
|
45
49
|
end
|
46
|
-
end
|
50
|
+
end
|
data/lib/napa/cli.rb
CHANGED
@@ -28,8 +28,11 @@ module Napa
|
|
28
28
|
say Napa::VERSION
|
29
29
|
end
|
30
30
|
|
31
|
-
desc 'console', 'Start the Napa console'
|
32
|
-
|
31
|
+
desc 'console [environment]', 'Start the Napa console'
|
32
|
+
options aliases: 'c'
|
33
|
+
def console(environment = 'development' )
|
34
|
+
ENV['RACK_ENV'] = environment
|
35
|
+
|
33
36
|
require 'racksh/init'
|
34
37
|
|
35
38
|
begin
|
@@ -4,7 +4,7 @@ module Napa
|
|
4
4
|
raise ArgumentError.new(":with option is required") if with.nil?
|
5
5
|
|
6
6
|
if data.respond_to?(:to_a)
|
7
|
-
return { data: data.
|
7
|
+
return { data: data.map{ |item| with.new(item).to_hash(args) } }
|
8
8
|
else
|
9
9
|
return { data: with.new(data).to_hash(args)}
|
10
10
|
end
|
data/lib/napa/version.rb
CHANGED
data/lib/tasks/db.rake
CHANGED
@@ -19,7 +19,7 @@ unless defined?(Rails)
|
|
19
19
|
|
20
20
|
options = {}.tap do |o|
|
21
21
|
o[:adapter] = db['adapter']
|
22
|
-
o[:database] = 'postgres' if db['adapter'] == '
|
22
|
+
o[:database] = 'postgres' if db['adapter'] == 'postgresql'
|
23
23
|
end
|
24
24
|
|
25
25
|
ActiveRecord::Base.establish_connection(options)
|
@@ -33,7 +33,7 @@ unless defined?(Rails)
|
|
33
33
|
|
34
34
|
options = {}.tap do |o|
|
35
35
|
o[:adapter] = db['adapter']
|
36
|
-
o[:database] = 'postgres' if db['adapter'] == '
|
36
|
+
o[:database] = 'postgres' if db['adapter'] == 'postgresql'
|
37
37
|
end
|
38
38
|
|
39
39
|
ActiveRecord::Base.establish_connection(options)
|
@@ -59,6 +59,9 @@ unless defined?(Rails)
|
|
59
59
|
desc "Load a schema.rb file into the database"
|
60
60
|
task :load => :environment do
|
61
61
|
file = ENV['SCHEMA'] || "db/schema.rb"
|
62
|
+
db = YAML.load(ERB.new(File.read('./config/database.yml')).result)[Napa.env]
|
63
|
+
ActiveRecord::Base.establish_connection(db)
|
64
|
+
ActiveRecord::Schema.verbose = true
|
62
65
|
load(file)
|
63
66
|
end
|
64
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darby Frey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|