sequel-active_record 1.0.0 → 1.1.0

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: 60fa60644b0d5cf6f0a41428577babe904811485
4
- data.tar.gz: 644201ffd082a9d8f9c048915b560dc94d014b3f
3
+ metadata.gz: 9ea3f5b9a5e7e8b4bf526da21bd8d5a84ed87172
4
+ data.tar.gz: fb8462d50560a2ac5b331b45e70c4552b026e542
5
5
  SHA512:
6
- metadata.gz: ec02760204a2569dac9b2ae438d9e5eb03016b8242e7d5eb11f43572f5e97e54b1ec359686363d4a9216193e6d5711c61e89ac2b7562b29ea036e66de60c3eb0
7
- data.tar.gz: 836b936c7919c6ff1208cf3d9c5e59ea11b6e56b2567fb016f5733479a1a7d449a8e0fc2f69e1d8fe61c3cac6647ce8dc3a79b0b4225a8c434e852aad1f890f8
6
+ metadata.gz: 252cad59e00087d05db382bb41f4b60cf3004694ebb07e9cbdc1dfb14bcc2cd05e2185cfd2903f67cc0249fa2999583c94b6bcf995308ac1fb67fe452f087837
7
+ data.tar.gz: a3ebbb924e3267b8878c9eb22b0875b0ff766155db51aa2daa43a70afd470ce7eff610629e580ee71dffddbbf9f83d41942b50858013d5cea0dbe553dd00d118
@@ -2,17 +2,12 @@ module Sequel
2
2
  module Plugins
3
3
  module ActiveRecord
4
4
 
5
- DEFAULT_FEATURES = [
6
- :first,
7
- :last
8
- ].freeze
9
-
10
5
  FEATURES = Dir[File.expand_path('../', __FILE__) + "/active_record/*.rb"].map{ |f|
11
6
  File.basename(f, '.rb').to_sym
12
7
  }
13
8
 
14
9
  # Loads requested features as plugins on the model
15
- def self.configure model, features: DEFAULT_FEATURES
10
+ def self.configure model, features: FEATURES
16
11
 
17
12
  # Ensure an array
18
13
  features = [features] unless Array === features
@@ -0,0 +1,42 @@
1
+ module Sequel
2
+ module Plugins
3
+ module ActiveRecord
4
+ module FinderMethods
5
+
6
+ # Implements find_by methods
7
+ def method_missing(name, *args, **kwargs, &block)
8
+
9
+ strict = name.to_s.ends_with?("!")
10
+
11
+ case name
12
+
13
+ # Emulate find_by
14
+ when :find_by, :find_by!
15
+ dataset = self.where(*args)
16
+ result = dataset.[](**kwargs)
17
+ raise Sequel::NoMatchingRow.new(dataset) if strict && !result
18
+ result
19
+
20
+ # Emulate dynamic finders
21
+ when /^find_by_/
22
+ terms = name.to_s.sub("find_by_", "").chomp("!").split("_and_").map(&:to_sym)
23
+ raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected #{terms.count})" unless args.count == terms.count
24
+ dataset = self.where(terms.zip(args).to_h)
25
+ result = dataset.first
26
+ raise Sequel::NoMatchingRow.new(dataset) if strict && !result
27
+ result
28
+
29
+ # Move up the chain
30
+ else
31
+ super
32
+ end
33
+
34
+ end
35
+
36
+ DatasetMethods = FinderMethods
37
+ ClassMethods = FinderMethods
38
+
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,14 +2,11 @@ module Sequel
2
2
  module Plugins
3
3
  module ActiveRecord
4
4
  module Last
5
- module DatasetMethods
6
- def last!(*args, &block)
7
- last(*args, &block) || raise(Sequel::NoMatchingRow.new(dataset))
8
- end
9
- end
10
- module ClassMethods
11
- Sequel::Plugins.def_dataset_methods(self, :last!)
5
+ def last!(*args, &block)
6
+ last(*args, &block) || raise(Sequel::NoMatchingRow.new(dataset))
12
7
  end
8
+ DatasetMethods = Last
9
+ ClassMethods = Last
13
10
  end
14
11
  end
15
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel-active_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kenaniah Cerny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -130,6 +130,7 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - lib/sequel/plugins/active_record.rb
133
+ - lib/sequel/plugins/active_record/finder_methods.rb
133
134
  - lib/sequel/plugins/active_record/first.rb
134
135
  - lib/sequel/plugins/active_record/last.rb
135
136
  homepage: https://github.com/kenaniah/sequel-active_record
@@ -143,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
144
  requirements:
144
145
  - - ">="
145
146
  - !ruby/object:Gem::Version
146
- version: '0'
147
+ version: '2.0'
147
148
  required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  requirements:
149
150
  - - ">="