findit 0.1.0 → 1.0.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: a2e4ae4411e438b0ca6b05ee3c908af0705c33e1
4
- data.tar.gz: 2e227b91fa3311eaf118e342065e45f1de42c4a0
3
+ metadata.gz: b6aa33998f5217a364e18c0baa9a200db22bf7e4
4
+ data.tar.gz: f4a9c78c55428e9847e126f5ec55bb439f157977
5
5
  SHA512:
6
- metadata.gz: 2104233901b47ecabf8062e6641fdf78c3bcd1f54d19ec923623e9548362c5c4cef814cdf4609deee08e05317906d268bd7564d4a5e56c7c031597b6a3383e74
7
- data.tar.gz: b717349e17368e0e70fed8c1f8a9515a55d608b5d5312fc3057adeeb002bf250da6a64f7a16d41524930314deab01f08781cf68544e1fede45f805d852ad243a
6
+ metadata.gz: 0ac341fc995d8f86a510f6e496a4ff356c8f5e2f1f4034a09cf32c25ddc4a8963e650b19cb184287ee7c24c0e1e8c4d22fab0e1aca941863245bf99dcc7198bb
7
+ data.tar.gz: 5c9c935939a362afa6e347e2a916468bbdc44d8652a338179f1e06c44670b6bc57548631350874ba82e05709b9e0da64daea1d94ca59f47cb1fb9693c35a1dea
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Findit
2
2
 
3
- Tired of writing fat controllers? But you must do all these queries.. There is a solution, move it to a Finder class.
3
+ Tired of writing fat controllers? But you must do all these queries.. There is a solution, move it to a special Finder class!
4
4
 
5
- Don't write this:
5
+ Stop writing this:
6
6
 
7
7
  ```ruby
8
8
  class SomeController
@@ -47,7 +47,9 @@ class SomeFinder
47
47
  # some initialize, maybe params parse
48
48
  end
49
49
 
50
- def call
50
+ private
51
+
52
+ def find
51
53
  # put here you find logic
52
54
  end
53
55
  end
@@ -91,13 +93,15 @@ Or install it yourself as:
91
93
 
92
94
  ### Collections
93
95
 
94
- It makes Finder work as Enumerator.
95
- Result can be accessed with `each`, `[]` and `size` methods, but to make things work you *must* implement `call` method.
96
+ It makes Finder work as Enumerator with lazy load.
97
+ Result can be accessed with `each`, `[]` and `size` methods, but to make things work you *must* implement `find` method.
96
98
  ```
97
99
  class PostFinder
98
100
  incliude Findit::Collections
99
101
 
100
- def call
102
+ private # make it private, so no one call it without lazy load
103
+
104
+ def find
101
105
  Post.where(user_id: 1)
102
106
  end
103
107
  end
@@ -130,13 +134,14 @@ class PostFinder
130
134
  end
131
135
 
132
136
  # custom initializer, do whatever you want here
133
- def initialize(user, options = {})
134
- @user = user
137
+ def initialize(options = {})
138
+ @user = options.fetch(:user)
135
139
  @query = options[:query]
136
140
  end
137
141
 
142
+ private
138
143
  # Here we fetch results. You MUST implement it
139
- def call
144
+ def find
140
145
  scope = scope.where(user_id: @user.id)
141
146
  scope = scope.where('description like :query', query: @query) if @query.present?
142
147
  scope
@@ -9,18 +9,14 @@
9
9
  # [@user.id, @query]
10
10
  # end
11
11
  #
12
- # cache_tags do
13
- # {user_id: @user.id}
14
- # end
15
- #
16
- # expire_in 30.minutes
17
- #
18
12
  # def initialize(user, options = {})
19
13
  # @user = user
20
14
  # @query = options[:query]
21
15
  # end
22
16
  #
23
- # def call
17
+ # private
18
+ #
19
+ # def find
24
20
  # scope = scope.where(user_id: @user.id)
25
21
  # scope = scope.where('description like :query', query: @query) if @query.present?
26
22
  # scope
@@ -44,24 +40,24 @@ module Findit
44
40
  extend ActiveSupport::Concern
45
41
 
46
42
  included do
47
- delegate :each, :[], :size, :empty?, to: :data
43
+ delegate :each, :[], :size, :empty?, to: :call
48
44
  end
49
45
 
50
46
  module ClassMethods
51
47
  def cache_key(&block)
52
48
  define_method :cache_key do
53
- @cache_key ||= ActiveSupport::Cache.expand_cache_key(instance_exec(&block))
49
+ @cache_key ||= ActiveSupport::Cache.expand_cache_key(instance_exec(&block), self.class.name.underscore)
54
50
  end
55
51
  end
56
52
  end
57
53
 
58
- def call
54
+ def find
59
55
  end
60
- undef :call
56
+ undef :find
61
57
 
62
- def data
58
+ def call
63
59
  return @data if defined?(@data)
64
- @data = call
60
+ @data = find
65
61
  end
66
62
  end
67
63
  end
@@ -1,3 +1,3 @@
1
1
  module Findit
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: findit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Korobicyn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-04 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  version_requirements: !ruby/object:Gem::Requirement