scopie_rails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -8
  3. data/lib/scopie_rails/version.rb +1 -1
  4. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e56563f6e72158575391b7da2f3a82e22737a46
4
- data.tar.gz: 21af9647d32257149b14ddd4878720039d461dc5
3
+ metadata.gz: c34fb74189d43684b3e608fc38ced2a8aa3f1646
4
+ data.tar.gz: 857a9c86d98119e449a7a6991dab6f46c4663c63
5
5
  SHA512:
6
- metadata.gz: c8de2a74842924f0a452664058ee620a676132c75e2dede33bfa10d364a88cf2f173aa3c311dd7f7688f4bc8a3673129cabc4092809d13a1db3369d9f7c12d68
7
- data.tar.gz: 0fda698f097b7d25b4e3728e83bfe8ea5536e0f06bc5c7f08615f483be4406035b09fad9b23155fa24f08918e80ad3c9f09ec79b18462a504b54bd46f02e8bd5
6
+ metadata.gz: 8976afa949ae119339df01d806c509cdf097c643c4fcee414ad76397db3bba33e9d31f67336a4f657f401f133ae71069ebc5d0eccc94c10b46ad0d5955566f0d
7
+ data.tar.gz: c4367389c842a91331d63dbe1e361847069d766987f71cd0102b7cc20e4dfe33ea25425896fd74627f258192f873e5dd372706f999141bdf128a2648522a40ad
data/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  ## ScopieRails
2
- Scopie for Rails
2
+ [Scopie][s] for Rails
3
+
4
+ ScopieRails allows you to map incoming controller parameters to named scopes in your resources and decouple mapping logic from controller.
5
+ ScopieRails is the yet another implementation of [has_scope](http://github.com/plataformatec/has_scope). The key difference is dedicated class where
6
+ the scopes are defined. To override default mapping behavior you don't need to pass a block - just define a method with the same name as scope.
7
+ You can DRY your custom scopes mapping logic by using helper methods defined in scopie class and use the same scopie class in multiple controllers.
3
8
 
4
- ScopieRails allows you to map incoming controller parameters to named scopes in your resources.
5
9
  Imagine the following model called graduations:
6
10
 
7
11
  ```ruby
8
12
  class Graduation < ActiveRecord::Base
9
- scope :featured, -> { where(:featured => true) }
10
- scope :by_degree, -> degree { where(:degree => degree) }
11
- scope :by_period, -> started_at, ended_at { where("started_at = ? AND ended_at = ?", started_at, ended_at) }
13
+ scope :featured, -> { where(featured: true) }
14
+ scope :by_degree, -> (degree) { where(degree: degree) }
15
+ scope :by_period, -> (started_at, ended_at) { where('started_at = ? AND ended_at = ?', started_at, ended_at) }
12
16
  end
13
17
  ```
14
18
 
@@ -17,8 +21,9 @@ You can use those named scopes as filters by declaring them on your scopie:
17
21
  ```ruby
18
22
  class Scopies::GraduationsScopie < ScopieRails::Base
19
23
  has_scope :featured, type: :boolean
20
- has_scope :by_degree
21
- has_scope :by_period
24
+ has_scope :by_degree, :by_period
25
+ has_scope :page, default: 1
26
+ has_scope :per, default: 30
22
27
 
23
28
  def by_period(scope, value, _hash)
24
29
  scope.by_period(value[:started_at], value[:ended_at])
@@ -66,10 +71,26 @@ gem 'scopie_rails'
66
71
 
67
72
  Scopie supports several options:
68
73
 
69
- * `:type` - Checks the type of the parameter sent.
74
+ * `:type` - Coerces the type of the parameter sent.
70
75
 
71
76
  * `:only` - In which actions the scope is applied.
72
77
 
73
78
  * `:except` - In which actions the scope is not applied.
74
79
 
80
+ * `:as` - The key in the params hash expected to find the scope. Defaults to the scope name.
81
+
75
82
  * `:default` - Default value for the scope. Whenever supplied the scope is always called.
83
+
84
+ ## Rails
85
+
86
+ ScopieRails provides Rails integration for [Scopie][s].
87
+
88
+ Among other things it adds a 'controller' method to scopies.
89
+
90
+ ## Thanks
91
+
92
+ Scopie was inspired by [has_scope](http://github.com/plataformatec/has_scope) and [pundit](http://github.com/elabs/pubdit).
93
+
94
+ Thanks to both.
95
+
96
+ [s]: https://github.com/beorc/scopie
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ScopieRails
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scopie_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Kotov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scopie
@@ -120,6 +120,20 @@ dependencies:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: simplecov
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
123
137
  description: scopie_rails provides integration between scopie and rails
124
138
  email:
125
139
  - non.gi.suong@ya.ru