fish0 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2b9ab2cb9d1ba9a260041b1c56e0fa42225aca8
4
- data.tar.gz: be489b5a7a623cbaeb0c91a758da070ac60c1e9a
3
+ metadata.gz: c4ea27a40ff37fcc325b73bb219e76a5e23aeadb
4
+ data.tar.gz: 8492357144680757b2f7a31a5ff5d3417eb49785
5
5
  SHA512:
6
- metadata.gz: 002ed4cd27ee9cde21cef90914d32d79b3377868a88558923bbec097ae9eb65a295ca5b50a9e84c4182403075d18e90df9d1e5b6d6fb3655419b41ae4b31410b
7
- data.tar.gz: cae77ee8d41315b8b003275a1e5337a4434c4a3092de51e066a9fdae2b5cdd35d54da3028edc562281abff242484536fbd4c82972c1f4d603721a01a44393271
6
+ metadata.gz: eaacc7b77a8d7b5744129b884aeef8278c3912f5b0f21d213986314240bf700ed36fbe18c3b76b46a961a22ec0815c8acedd55820847cb39dbc175396a7481a0
7
+ data.tar.gz: 5e5a584979c2488dfbabeb21130e52692363d1d6f46d957839e088d461b6fd52b10bafa0ccb36492d4c3eacaebaa611b59e867a32d4fadbc4a669155cc02c435
data/README.md CHANGED
@@ -35,6 +35,7 @@ production:
35
35
  Inherit your model class from `Fish0::Model` and feel the power of the Fish!
36
36
 
37
37
  With `attribute` define your attributes and with `primary_key` set your main primary key, e.g. `id`, `slug`, etc.
38
+
38
39
  ```ruby
39
40
  # app/models/article.rb
40
41
  class Article < Fish0::Model
@@ -94,7 +95,7 @@ class ArticlesController < ApplicationController
94
95
  # ...
95
96
 
96
97
  def show
97
- @article = ArticleRepository.new.where(slug: params[:slug]).first!
98
+ @article = Article.where(slug: params[:slug]).published.first!
98
99
  end
99
100
 
100
101
  # ...
@@ -109,7 +110,7 @@ class ArticlesController < ApplicationController
109
110
  include Fish0::Concerns::Paginatable
110
111
 
111
112
  def index
112
- @articles = paginate(ArticleRepository.new.published)
113
+ @articles = paginate(Article.published)
113
114
  end
114
115
 
115
116
  # ...
@@ -153,7 +154,7 @@ Your model should respond to `:updated_at` with DateTime object.
153
154
  # app/models/article.rb
154
155
  class Article
155
156
  # ...
156
- include Fish0::Concerns::Cacheable
157
+ cacheable
157
158
 
158
159
  # ...
159
160
  end
@@ -163,7 +164,7 @@ class ArticlesController < ApplicationController
163
164
  # ...
164
165
 
165
166
  def show
166
- @article = ArticleRepository.new.where(slug: params[:slug]).first!
167
+ @article = Article.where(slug: params[:slug]).first!
167
168
  if stale?(@article)
168
169
  respond_to do |format|
169
170
  format.html
@@ -3,7 +3,13 @@ module Fish0
3
3
  module Base
4
4
  extend ActiveSupport::Concern
5
5
 
6
- cattr_accessor :primary_key, instance_writer: false
6
+ def primary_key
7
+ self.class.primary_key
8
+ end
9
+
10
+ def primary_key_value
11
+ send(primary_key)
12
+ end
7
13
 
8
14
  included do
9
15
  class << self
@@ -13,25 +19,23 @@ module Fish0
13
19
  @primary_key
14
20
  end
15
21
 
16
- delegate :all, to: :repository
17
- delegate :where, to: :repository
18
- delegate :first, to: :repository
19
- delegate :last, to: :repository
20
- delegate :search, to: :repository
21
- delegate :order_by, to: :repository
22
- delegate :limit, to: :repository
23
- delegate :skip, to: :repository
24
- delegate :projection, to: :repository
22
+ def cacheable
23
+ include Concerns::Cacheable
24
+ end
25
25
 
26
- def first!
27
- first || raise(RecordNotFound, "can't find in #{collection} with #{conditions}")
26
+ def method_missing(method_name, *arguments, &block)
27
+ if repository.respond_to?(method_name)
28
+ repository.send(method_name, *arguments, &block)
29
+ else
30
+ super
31
+ end
28
32
  end
29
33
 
30
- def last!
31
- last || raise(RecordNotFound, "can't find in #{collection} with #{conditions}")
34
+ def respond_to_missing?(method_name, include_private = false)
35
+ repository.respond_to?(method_name) || super
32
36
  end
33
37
 
34
- private
38
+ protected
35
39
 
36
40
  def default_primary_key
37
41
  :slug
@@ -46,6 +50,9 @@ module Fish0
46
50
  end
47
51
 
48
52
  def repository
53
+ if "#{entity.to_s}Repository".safe_constantize
54
+ return "#{entity.to_s}Repository".constantize.new(collection, entity)
55
+ end
49
56
  Fish0::Repository.new(collection, entity)
50
57
  end
51
58
  end
@@ -18,10 +18,6 @@ module Fish0
18
18
 
19
19
  private
20
20
 
21
- def primary_key_value
22
- send(primary_key)
23
- end
24
-
25
21
  def timestamp_attributes_for_update
26
22
  [:updated_at]
27
23
  end
@@ -38,11 +38,19 @@ module Fish0
38
38
  to_entity.call(element) if element
39
39
  end
40
40
 
41
+ def first!
42
+ first || raise(RecordNotFound, "can't find in #{collection} with #{conditions}")
43
+ end
44
+
41
45
  def last
42
46
  element = all.last
43
47
  to_entity.call(element) if element
44
48
  end
45
49
 
50
+ def last!
51
+ last || raise(RecordNotFound, "can't find in #{collection} with #{conditions}")
52
+ end
53
+
46
54
  def where(query)
47
55
  conditions.merge!(query)
48
56
  self
data/lib/fish0/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Fish0
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.0.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fish0
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Zuev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-07 00:00:00.000000000 Z
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails