squirm 0.0.2 → 0.0.3

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.
data/README.md CHANGED
@@ -42,13 +42,17 @@ Here's a quick demo of how you might use it:
42
42
  id = create.call(email: "johndoe@example.com", name: "John Doe")
43
43
 
44
44
  In and of itself, Squirm offers very little, but is meant to be a basic building
45
- block for other libraries.
45
+ block for other libraries, such as [Squirm
46
+ Model](https://github.com/bvision/squirm_model), which supplies an Active Model
47
+ compatible ORM based on stored procedures.
46
48
 
47
- One such library is Squirm Model, which is currently under development.
49
+ ## Using it with Rails
48
50
 
49
- This library will offer an ActiveModel-compatible, ORM-like library that uses
50
- stored procedures and SQL rather than generating the SQL for you. Stay tuned
51
- for more details.
51
+ Squirm can use Active Record's connection pool rather than its own, all you have
52
+ to do is pass in the pool to `Squirm.connect`:
53
+
54
+ # in config/initializers/squirm.rb
55
+ Squirm.connect pool: ActiveRecord::Base.connection_pool
52
56
 
53
57
  ## Author
54
58
 
data/lib/squirm.rb CHANGED
@@ -59,7 +59,15 @@ some reason you want to use them:
59
59
  proc.call("Jan 1, 2011") #=> "2011-01-01"
60
60
 
61
61
  =end
62
+
63
+
62
64
  module Squirm
63
65
  Rollback, Timeout = 2.times.map { Class.new RuntimeError }
64
66
  extend Core
65
67
  end
68
+
69
+ module Kernel
70
+ def Squirm(&block)
71
+ Squirm.instance_eval(&block)
72
+ end
73
+ end
data/lib/squirm/core.rb CHANGED
@@ -40,6 +40,10 @@ module Squirm
40
40
  end
41
41
  end
42
42
 
43
+ def procedure(*args)
44
+ Procedure.load(*args)
45
+ end
46
+
43
47
  # Gets the connection pool.
44
48
  # @return [Squirm::Pool] The connection pool.
45
49
  def pool
@@ -60,8 +64,10 @@ module Squirm
60
64
  end
61
65
 
62
66
  # Rolls back from inside a #transaction block.
63
- def rollback
64
- raise Rollback
67
+ # When called with block, performs a transaction inside a block and rolls
68
+ # back when it gets to the end. This can be useful in tests.
69
+ def rollback(&block)
70
+ block_given? ? transaction {yield; rollback} : (raise Rollback)
65
71
  end
66
72
 
67
73
  # Checks out a connection and uses it for all database access inside the
@@ -70,7 +76,7 @@ module Squirm
70
76
  conn = @pool.checkout
71
77
  begin
72
78
  Thread.current[:squirm_connection] = conn
73
- yield conn
79
+ yield conn.respond_to?(:raw_connection) ? conn.raw_connection : conn
74
80
  ensure
75
81
  Thread.current[:squirm_connection] = nil
76
82
  @pool.checkin conn
@@ -49,6 +49,11 @@ module Squirm
49
49
  @arguments = Arguments.new(options[:args]) if options[:args]
50
50
  end
51
51
 
52
+ # Creates procedure and loads it right away.
53
+ def self.load(*args)
54
+ new(*args).load
55
+ end
56
+
52
57
  # Loads meta info about the stored procedure.
53
58
  #
54
59
  # This action is not performed in the constructor to allow instances to
@@ -86,6 +91,11 @@ module Squirm
86
91
 
87
92
  alias [] call
88
93
 
94
+ # Gets a Ruby proc that calls this procedure.
95
+ def to_proc
96
+ ->(*args) {call(*args)}
97
+ end
98
+
89
99
  # Checks the number of values returned when looking up meta info about
90
100
  # the procedure.
91
101
  # @see #load
@@ -1,3 +1,3 @@
1
1
  module Squirm
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squirm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-19 00:00:00.000000000 Z
12
+ date: 2011-12-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70156030613100 !ruby/object:Gem::Requirement
16
+ requirement: &70214491275780 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70156030613100
24
+ version_requirements: *70214491275780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: pg
27
- requirement: &70156030612340 !ruby/object:Gem::Requirement
27
+ requirement: &70214494717880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.11.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70156030612340
35
+ version_requirements: *70214494717880
36
36
  description: ! '"Squirm is an anti-ORM for database-loving programmers"'
37
37
  email:
38
38
  - norman@njclarke.com
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  requirements: []
78
78
  rubyforge_project:
79
- rubygems_version: 1.8.5
79
+ rubygems_version: 1.8.10
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: ! '"An anti-ORM for database-loving programmers"'
@@ -85,3 +85,4 @@ test_files:
85
85
  - spec/helper.rb
86
86
  - spec/pool_spec.rb
87
87
  - spec/procedure_spec.rb
88
+ has_rdoc: