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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f7b795742fcfdbe13930f92bd6946f3de0d89ed
4
- data.tar.gz: c12983f2a42794564b744ecfef193c84f6ef064e
3
+ metadata.gz: df1760457e554a3c32e7986732018fbf8aba0ebc
4
+ data.tar.gz: 527006ae41bc69e3c17382eeb262f1154e54b1f8
5
5
  SHA512:
6
- metadata.gz: d619607435ab470cef5837a7603d0b60845ef346133962d1332f9a29d1eb48961a959449c865f94b7fb179909d10a2a0935c0401490801ee7ffdf6d2cb7b4f24
7
- data.tar.gz: 129a26fe0d65b9a69c886c010202229bb6a11603aee4348e119c2ef71372dbdf7c69bae15ee10fc3c2066f9049e75750374a384ef4bf7ab563eb0841de36213d
6
+ metadata.gz: 0576ac7375b2b40101dabf6c098e119f8356f4f84495f07f1cc6aec73356ce5c09912991f82c6247612ca352ca670abdcad7fce354032104372e546ba09755d3
7
+ data.tar.gz: f3e3fcfa3ee266d870e520991dcabf9a3402823e90d5db0d85093282278c0e7ab4d993895ad7ac603fd4b88af396588f185dfb6a9fbad85c54b67f00c52d4b58
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /test*.rb
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
- gem 'sinja', :require=>false, :path=>'../..'
4
+
5
+ gem 'sinja', :require=>false,
6
+ :git=>'https://github.com/mwpastore/sinja.git', :branch=>'master'
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 "Avoding Null Foreign Keys" in the [Sinja][1] documentation for more
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](/extensions/sequel/lib/sinja/sequel/core.rb)
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](/extensions/sequel/lib/sinja/sequel/helpers.rb) after
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](/extensions/sequel/lib/sinja/sequel.rb) after
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. The default `create` action helper
243
- does not support client-generated IDs. These action helpers can be subsequently
244
- overridden, customized by setting action helper options (i.e. `:roles`) and/or
245
- defining `before_<action>` hooks, or removed entirely with `remove_<action>`.
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
@@ -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.include Pagination if ::Sequel::Database::EXTENSIONS.key?(:pagination)
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.included(base)
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
 
@@ -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
- in_common = old_ids & new_ids
28
+ ids_in_common = old_ids & new_ids
29
29
 
30
- (new_ids - in_common).each do |id|
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 - in_common).each do |id|
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)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Sinja
3
3
  module Sequel
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
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/tree/master/extensions/sequel'
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.0
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-14 00:00:00.000000000 Z
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/tree/master/extensions/sequel
110
+ homepage: https://github.com/mwpastore/sinja-sequel
110
111
  licenses:
111
112
  - MIT
112
113
  metadata: {}