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 +4 -4
- data/README.md +5 -4
- data/lib/fish0/concerns/base.rb +22 -15
- data/lib/fish0/concerns/cacheable.rb +0 -4
- data/lib/fish0/repository.rb +8 -0
- data/lib/fish0/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4ea27a40ff37fcc325b73bb219e76a5e23aeadb
|
4
|
+
data.tar.gz: 8492357144680757b2f7a31a5ff5d3417eb49785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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(
|
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
|
-
|
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 =
|
167
|
+
@article = Article.where(slug: params[:slug]).first!
|
167
168
|
if stale?(@article)
|
168
169
|
respond_to do |format|
|
169
170
|
format.html
|
data/lib/fish0/concerns/base.rb
CHANGED
@@ -3,7 +3,13 @@ module Fish0
|
|
3
3
|
module Base
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
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
|
27
|
-
|
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
|
31
|
-
|
34
|
+
def respond_to_missing?(method_name, include_private = false)
|
35
|
+
repository.respond_to?(method_name) || super
|
32
36
|
end
|
33
37
|
|
34
|
-
|
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
|
data/lib/fish0/repository.rb
CHANGED
@@ -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
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
|
+
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-
|
11
|
+
date: 2016-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|