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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c303631113443a38699bded25a0f869222f86a
4
- data.tar.gz: 33c810492456288eba6f4e0bfc041db253fa8aef
3
+ metadata.gz: 2718b1367fa6291f248a6355cbd7805307d605ef
4
+ data.tar.gz: 66b0551ef54b97b7d73d5bcbd1521254f35df2b9
5
5
  SHA512:
6
- metadata.gz: 3b7bb38860e58f64c4909d5647bb4f3d3ade3fb6f685cd3f0fdbdad72573018d316992068fd346b06d274e8bd3f7d872a6af364348efa699de66932f126c4a5c
7
- data.tar.gz: 0c85828fa6035881434a92aa4d43d29103476d620233cab74ef951f68e1b3605b9e5cf9b4710a92a9c735f2153d8996f021d4db612f3a9d189182c33f372d50f
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.guess_sql_content(query)
19
+ def self.extract_sql_updates(query)
20
20
  m = query.match(SQL_UPDATE_REGEXP)
21
- return [m[:table], 'UPDATE'] if m
22
- unless m
23
- m = query.match(SQL_SELECT_REGEXP)
24
- extract_sql_selects(query) if m
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[:name] == 'SQL'
30
- table, action = extract_from_sql_inserts_deletes(payload[:sql])
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
- def console
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.each{ |item| with.new(item).to_hash(args) } }
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
@@ -1,5 +1,5 @@
1
1
  module Napa
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
 
4
4
  class Version
5
5
  class << self
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'] == 'postgres'
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'] == 'postgres'
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.0
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 00:00:00.000000000 Z
11
+ date: 2014-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake