services 0.2.14 → 0.3.4

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: ac839c9acd73ecdeb861be1d8b484bb3c49b39b6
4
- data.tar.gz: a00b6d2cd4e15da02bf55e90d8f18c1d250fda2a
3
+ metadata.gz: 4987f523acb227a70a5fddee85a8fae8aab86f8c
4
+ data.tar.gz: 3c4f1ca4a27990a08b9f5fa691392e66329ce76c
5
5
  SHA512:
6
- metadata.gz: cdbe4970cf52f2ccd1648e617bfb83483f6e3d8d47e9c183209385383975b8e51184e96f1ab0f16690de8955e6bb1fee03b12f8e74f5ab5dc179cc456c000d5a
7
- data.tar.gz: 960d6879ba1b08c6592e724f2d8e642157d37ce6133383ab75d52daa626d2cb2daefdbdcc32a32b3d060d2808be599e9b67c5fdbc8ac106a105701541318f1ec
6
+ metadata.gz: 4ecc46999894ba5049d92c79c33a7d1745d4ebd6bd2db3b61037ed940ed0cd936800df117926b8b76694868771ab78ba78b99a0da84d80cd40258431e987bbcb
7
+ data.tar.gz: 6d9c4a3d5e7360f4e8422395b1b78148bd21f567dc2949610256836316277dc29d86d38057bbb60f5499bb41562b723b0628b178ff020eaa42c389322daeebbb
data/lib/services/base.rb CHANGED
@@ -48,7 +48,7 @@ module Services
48
48
 
49
49
  def find_object(*args)
50
50
  find_objects(*args).tap do |objects|
51
- raise "Expected only one object but found #{objects.size}" unless objects.size == 1
51
+ raise "Expected exactly one object but found #{objects.size}" unless objects.size == 1
52
52
  end.first
53
53
  end
54
54
 
@@ -0,0 +1,36 @@
1
+ module Services
2
+ class BaseFinder < Services::Base
3
+ def call(ids = [], conditions = {})
4
+ ids, conditions = Array(ids), conditions.symbolize_keys
5
+ special_conditions = conditions.extract!(:order, :limit, :page, :per_page)
6
+ scope = service_class
7
+ .select("DISTINCT #{service_class.table_name}.id")
8
+ .order("#{service_class.table_name}.id")
9
+ scope = scope.where(id: ids) unless ids.empty?
10
+
11
+ scope = process(scope, conditions)
12
+
13
+ scope = service_class.where(id: scope)
14
+ special_conditions.each do |k, v|
15
+ case k
16
+ when :order
17
+ order = if v == 'random'
18
+ 'RANDOM()'
19
+ else
20
+ "#{service_class.table_name}.#{v}"
21
+ end
22
+ scope = scope.order(order)
23
+ when :limit
24
+ scope = scope.limit(v)
25
+ when :page
26
+ scope = scope.page(v)
27
+ when :per_page
28
+ scope = scope.per(v)
29
+ else
30
+ raise ArgumentError, "Unexpected special condition: #{k}"
31
+ end
32
+ end
33
+ scope
34
+ end
35
+ end
36
+ end
@@ -97,7 +97,7 @@ module Services
97
97
  def uniqueness_key(args)
98
98
  [
99
99
  KEY_PREFIX,
100
- self.class.to_s
100
+ self.class.to_s.gsub(':', '_')
101
101
  ].tap do |key|
102
102
  key << Digest::MD5.hexdigest(args.to_s) unless args.empty?
103
103
  end.join(':')
@@ -107,7 +107,7 @@ module Services
107
107
  [
108
108
  KEY_PREFIX,
109
109
  'errors',
110
- self.class.to_s
110
+ self.class.to_s.gsub(':', '_')
111
111
  ].tap do |key|
112
112
  key << Digest::MD5.hexdigest(@service_args.to_s) unless @service_args.empty?
113
113
  end.join(':')
@@ -1,5 +1,11 @@
1
1
  module Services
2
2
  class Railtie < Rails::Railtie
3
+ # Require the base finder here since it relies
4
+ # on Rails.application to be present
5
+ initializer 'services.load_base_finder' do
6
+ require 'services/base_finder'
7
+ end
8
+
3
9
  config.after_initialize do
4
10
  Services.configuration.log_dir = Rails.root.join('log')
5
11
  end
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '0.2.14'
2
+ VERSION = '0.3.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -138,6 +138,7 @@ files:
138
138
  - lib/services.rb
139
139
  - lib/services/asyncable.rb
140
140
  - lib/services/base.rb
141
+ - lib/services/base_finder.rb
141
142
  - lib/services/logger.rb
142
143
  - lib/services/modules/call_logger.rb
143
144
  - lib/services/modules/exception_wrapper.rb