sinja-sequel 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/Gemfile +3 -1
- data/README.md +20 -9
- data/lib/sinja/sequel.rb +4 -4
- data/lib/sinja/sequel/core.rb +10 -2
- data/lib/sinja/sequel/helpers.rb +3 -3
- data/lib/sinja/sequel/version.rb +1 -1
- data/sinja-sequel.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1760457e554a3c32e7986732018fbf8aba0ebc
|
4
|
+
data.tar.gz: 527006ae41bc69e3c17382eeb262f1154e54b1f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0576ac7375b2b40101dabf6c098e119f8356f4f84495f07f1cc6aec73356ce5c09912991f82c6247612ca352ca670abdcad7fce354032104372e546ba09755d3
|
7
|
+
data.tar.gz: f3e3fcfa3ee266d870e520991dcabf9a3402823e90d5db0d85093282278c0e7ab4d993895ad7ac603fd4b88af396588f185dfb6a9fbad85c54b67f00c52d4b58
|
data/.gitignore
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -8,6 +8,7 @@
|
|
8
8
|
-->
|
9
9
|
|
10
10
|
[![Gem Version](https://badge.fury.io/rb/sinja-sequel.svg)](https://badge.fury.io/rb/sinja-sequel)
|
11
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/mwpastore/sinja-sequel.svg)](https://gemnasium.com/github.com/mwpastore/sinja-sequel)
|
11
12
|
|
12
13
|
Sinja::Sequel configures your [Sinja][1] application to work with [Sequel][2]
|
13
14
|
out of the box, and provides additional helpers to greatly simplify the process
|
@@ -90,7 +91,7 @@ class Bar < Sequel::Model
|
|
90
91
|
end
|
91
92
|
```
|
92
93
|
|
93
|
-
See "
|
94
|
+
See "Avoiding Null Foreign Keys" in the [Sinja][1] documentation for more
|
94
95
|
information.
|
95
96
|
|
96
97
|
Finally, enable the `:pagination` extension on your connection (before
|
@@ -98,7 +99,7 @@ prepending Core) to enable pagination!
|
|
98
99
|
|
99
100
|
### Core
|
100
101
|
|
101
|
-
Prepend [Sinja::Sequel::Core](/
|
102
|
+
Prepend [Sinja::Sequel::Core](/lib/sinja/sequel/core.rb)
|
102
103
|
after registering Sinja:
|
103
104
|
|
104
105
|
```ruby
|
@@ -150,7 +151,7 @@ Sequel plugins and features.
|
|
150
151
|
### Helpers
|
151
152
|
|
152
153
|
Include
|
153
|
-
[Sinja::Sequel::Helpers](/
|
154
|
+
[Sinja::Sequel::Helpers](/lib/sinja/sequel/helpers.rb) after
|
154
155
|
registering Sinja:
|
155
156
|
|
156
157
|
```ruby
|
@@ -223,7 +224,7 @@ breeze!
|
|
223
224
|
|
224
225
|
### Extension
|
225
226
|
|
226
|
-
Register [Sinja::Sequel](/
|
227
|
+
Register [Sinja::Sequel](/lib/sinja/sequel.rb) after
|
227
228
|
registering Sinja:
|
228
229
|
|
229
230
|
```ruby
|
@@ -239,10 +240,20 @@ end
|
|
239
240
|
**Note that registering the extension will automatically include Helpers!**
|
240
241
|
|
241
242
|
After registering the extension, the `resource`, `has_many`, and `has_one` DSL
|
242
|
-
keywords will generate basic action helpers.
|
243
|
-
|
244
|
-
|
245
|
-
|
243
|
+
keywords will generate basic action helpers.
|
244
|
+
|
245
|
+
* `resource` and `has_many` take an optional second argument that specifies the
|
246
|
+
method to use to cast the ID of the resource or each resource identifier
|
247
|
+
object (`:to_i` by default).
|
248
|
+
|
249
|
+
* The generated `create` action helper does not support client-generated IDs.
|
250
|
+
|
251
|
+
* Optionally define a `settable_fields` helper in each resource that returns an
|
252
|
+
array of symbols to pass to `Sequel::Model#set_fields`.
|
253
|
+
|
254
|
+
These action helpers can be subsequently overridden, customized by setting
|
255
|
+
action helper options (i.e. `:roles`) and/or defining `before_<action>` hooks,
|
256
|
+
or removed entirely with `remove_<action>`.
|
246
257
|
|
247
258
|
## Development
|
248
259
|
|
@@ -259,7 +270,7 @@ git commits and tags, and push the `.gem` file to
|
|
259
270
|
## Contributing
|
260
271
|
|
261
272
|
Bug reports and pull requests are welcome on GitHub at
|
262
|
-
https://github.com/mwpastore/sinja.
|
273
|
+
https://github.com/mwpastore/sinja-sequel.
|
263
274
|
|
264
275
|
## License
|
265
276
|
|
data/lib/sinja/sequel.rb
CHANGED
@@ -80,7 +80,7 @@ module Sinja
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
def has_many(rel, &block)
|
83
|
+
def has_many(rel, try_convert=:to_i, &block)
|
84
84
|
super(rel) do
|
85
85
|
fetch do
|
86
86
|
resource.send("#{rel}_dataset")
|
@@ -91,15 +91,15 @@ module Sinja
|
|
91
91
|
end
|
92
92
|
|
93
93
|
replace(:sideload_on=>:update) do |rios|
|
94
|
-
add_remove(rel, rios)
|
94
|
+
add_remove(rel, rios, try_convert)
|
95
95
|
end
|
96
96
|
|
97
97
|
merge(:sideload_on=>:create) do |rios|
|
98
|
-
add_missing(rel, rios)
|
98
|
+
add_missing(rel, rios, try_convert)
|
99
99
|
end
|
100
100
|
|
101
101
|
subtract do |rios|
|
102
|
-
remove_present(rel, rios)
|
102
|
+
remove_present(rel, rios, try_convert)
|
103
103
|
end
|
104
104
|
|
105
105
|
instance_eval(&block) if block
|
data/lib/sinja/sequel/core.rb
CHANGED
@@ -15,7 +15,11 @@ module Sinja
|
|
15
15
|
c.validation_formatter = ->(e) { e.errors.keys.zip(e.errors.full_messages) }
|
16
16
|
end
|
17
17
|
|
18
|
-
base.
|
18
|
+
base.prepend Pagination if ::Sequel::Database::EXTENSIONS.key?(:pagination)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.included(_)
|
22
|
+
abort "You must `prepend' Sinja::Sequel::Core, not `include' it!"
|
19
23
|
end
|
20
24
|
|
21
25
|
def_delegator ::Sequel::Model, :db, :database
|
@@ -36,7 +40,7 @@ module Sinja
|
|
36
40
|
end
|
37
41
|
|
38
42
|
module Pagination
|
39
|
-
def self.
|
43
|
+
def self.prepended(base)
|
40
44
|
base.sinja { |c| c.page_using = {
|
41
45
|
:number=>1,
|
42
46
|
:size=>10,
|
@@ -44,6 +48,10 @@ module Sinja
|
|
44
48
|
}}
|
45
49
|
end
|
46
50
|
|
51
|
+
def self.included(_)
|
52
|
+
abort "You must `prepend' Sinja::Sequel::Pagination, not `include' it!"
|
53
|
+
end
|
54
|
+
|
47
55
|
def page(collection, opts)
|
48
56
|
collection = collection.dataset unless collection.respond_to?(:paginate)
|
49
57
|
|
data/lib/sinja/sequel/helpers.rb
CHANGED
@@ -25,15 +25,15 @@ module Sinja
|
|
25
25
|
transaction do
|
26
26
|
resource.lock!
|
27
27
|
old_ids = dataset.select_map(klass.primary_key)
|
28
|
-
|
28
|
+
ids_in_common = old_ids & new_ids
|
29
29
|
|
30
|
-
(new_ids -
|
30
|
+
(new_ids - ids_in_common).each do |id|
|
31
31
|
subresource = klass.with_pk!(id)
|
32
32
|
resource.send(add_meth, subresource) \
|
33
33
|
unless block_given? && !yield(subresource)
|
34
34
|
end
|
35
35
|
|
36
|
-
(old_ids -
|
36
|
+
(old_ids - ids_in_common).each do |id|
|
37
37
|
subresource = klass.with_pk!(id)
|
38
38
|
resource.send(remove_meth, subresource) \
|
39
39
|
unless block_given? && !yield(subresource)
|
data/lib/sinja/sequel/version.rb
CHANGED
data/sinja-sequel.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ['mike@oobak.org']
|
11
11
|
|
12
12
|
spec.summary = 'Sequel-specific Helpers and DSL for Sinja'
|
13
|
-
spec.homepage = 'https://github.com/mwpastore/sinja
|
13
|
+
spec.homepage = 'https://github.com/mwpastore/sinja-sequel'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinja-sequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Pastore
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -93,6 +93,7 @@ executables: []
|
|
93
93
|
extensions: []
|
94
94
|
extra_rdoc_files: []
|
95
95
|
files:
|
96
|
+
- ".gitignore"
|
96
97
|
- Gemfile
|
97
98
|
- LICENSE.txt
|
98
99
|
- README.md
|
@@ -106,7 +107,7 @@ files:
|
|
106
107
|
- lib/sinja/sequel/helpers.rb
|
107
108
|
- lib/sinja/sequel/version.rb
|
108
109
|
- sinja-sequel.gemspec
|
109
|
-
homepage: https://github.com/mwpastore/sinja
|
110
|
+
homepage: https://github.com/mwpastore/sinja-sequel
|
110
111
|
licenses:
|
111
112
|
- MIT
|
112
113
|
metadata: {}
|