scopie_rails 1.0.1 → 1.1.1

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: d5010bb357210ad76c8bddbfba9786d2f4806a89
4
- data.tar.gz: d14954d7b994d237c71279fe37f4538d04d4d3f9
3
+ metadata.gz: c74975fde612d205c6c5e0f74b0c4939d6ba0ac6
4
+ data.tar.gz: 445d27e9da50cc477811e561fa208ddc991a510b
5
5
  SHA512:
6
- metadata.gz: 2c42060708b27571d46d63d80222f7e902aac086100431c9537de68f3347c768b31ed89e0dd110e31a1e4774b5dcb55e587fb543704c573c59fb0f7c3d8f56b1
7
- data.tar.gz: ce2891386b44af6db7efbeeb7989c0afcd67f325259eb7417de553da9082bd823605f5dead6b2c101e48c8a6c907932857ad2c01fe348ff81c4bed9fef21784d
6
+ metadata.gz: 2ac70de4033ed79c3da88cd517264c7e3831e4732cbbe6561370172f66a967954236819cdfe59d9d8fb7a3f109f46ae54c97b2df669e9fb7da1aad7b0d94d50b
7
+ data.tar.gz: fbeb34488d40978aa21100de898ef086aaa7cad144bbdaa27be2fed41c0eddbdad4d34a181fe5f7e8dedabeff6ad579447b36dbcdf6ecfbf1b17580b826de940
data/README.md CHANGED
@@ -13,8 +13,8 @@ ScopieRails allows you to map incoming controller parameters to named scopes in
13
13
  Motivation:
14
14
 
15
15
  * Dedicated class for scopes mapping, so that the logic is isolated and your controller is skinny.
16
- * Ability to override default mapping behavior by definition of a method with the same name as scope in the scopie class.
17
- * Ability to DRY your custom scopes mapping logic using private methods defined in scopie class and use the same scopie class in multiple controllers.
16
+ * Ability to override default mapping behavior by definition of a method having the same name as a scope in the scopie class.
17
+ * Ability to use the object oriented approach to DRY your custom scopes mapping logic and reuse the scopie class.
18
18
 
19
19
  Imagine the following model called graduations:
20
20
 
@@ -121,6 +121,10 @@ Add `scopie_rails` to your Gemfile or install it from Rubygems.
121
121
  gem 'scopie_rails'
122
122
  ```
123
123
 
124
+ ## Mutation testing
125
+
126
+ mutant --include lib --require scopie_rails --use rspec ScopieRails*
127
+
124
128
  ## Options
125
129
 
126
130
  Scopie supports several options:
@@ -137,17 +141,19 @@ Scopie supports several options:
137
141
 
138
142
  * `:allow_blank` - Blank values are not sent to scopes by default. Set to true to overwrite.
139
143
 
144
+ * `:ignore_blank` - Set to true to not apply the scope if blank value is given.
145
+
140
146
  * `:default` - Default value for the scope. Whenever supplied the scope is always called.
141
147
 
142
148
  ## Rails
143
149
 
144
150
  ScopieRails provides Rails integration for [Scopie][s].
145
151
 
146
- Among other things it adds a 'controller' method to scopies.
152
+ Among other things it adds a `controller` method to scopies.
147
153
 
148
154
  ## Thanks
149
155
 
150
- Scopie was inspired by [has_scope](http://github.com/plataformatec/has_scope) and [pundit](http://github.com/elabs/pubdit).
156
+ Scopie was inspired by [has_scope](http://github.com/plataformatec/has_scope) and [pundit](http://github.com/elabs/pundit).
151
157
 
152
158
  Thanks to both.
153
159
 
@@ -0,0 +1,11 @@
1
+ module Rspec
2
+ module Generators
3
+ class ScopieGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ def create_scopie_spec
7
+ template 'scopie_spec.rb', File.join('spec/scopies', class_path, "#{file_name}_scopie_spec.rb")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
2
+
3
+ RSpec.describe <%= class_name %>Scopie do
4
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generates a scopie for a controller with the given name.
3
+
4
+ Example:
5
+ rails generate scopie_rails:scopie items
6
+
7
+ This will create:
8
+ app/scopies/items_scopie.rb
@@ -0,0 +1,13 @@
1
+ module ScopieRails
2
+ module Generators
3
+ class ScopieGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
5
+
6
+ def create_scopie
7
+ template 'scopie.rb', File.join('app/scopies', class_path, "#{file_name}_scopie.rb")
8
+ end
9
+
10
+ hook_for :test_framework
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Scopie < ScopieRails::Base
3
+ end
4
+ <% end -%>
data/lib/scopie_rails.rb CHANGED
@@ -7,8 +7,9 @@ require 'active_support/core_ext/string/inflections'
7
7
 
8
8
  module ScopieRails
9
9
 
10
- SCOPIE_SUFFIX = '_scopie'
10
+ SCOPIE_SUFFIX = '_scopie'.freeze
11
11
 
12
+ require 'scopie_rails/version'
12
13
  require 'scopie_rails/engine' if defined?(Rails)
13
14
  require 'scopie_rails/base'
14
15
  require 'scopie_rails/controller'
@@ -10,21 +10,35 @@ module ScopieRails::Controller
10
10
  @default_scopie ||= find_scopie_class.new(self)
11
11
  end
12
12
 
13
+ # Receives an object where scopes will be applied to.
14
+ #
15
+ # class GraduationsScopie < Scopie::Base
16
+ # has_scope :featured, type: :boolean
17
+ # has_scope :by_degree, :by_period
18
+ # end
19
+ #
20
+ # class GraduationsController < ApplicationController
21
+ # include ScopieRails::Controller
22
+ #
23
+ # def index
24
+ # @graduations = apply_scopes(Graduation).all
25
+ # end
26
+ # end
27
+ #
13
28
  def apply_scopes(target, scopie: default_scopie, hash: params)
14
29
  Scopie.apply_scopes(target, hash, method: hash[:action], scopie: scopie)
15
30
  end
16
31
 
32
+ # Returns the scopes used in this action.
17
33
  def current_scopes(scopie: default_scopie, hash: params)
18
34
  Scopie.current_scopes(hash, method: hash[:action], scopie: scopie)
19
35
  end
20
36
 
21
37
  def find_scopie_class
22
- return self.class.scopie_class if self.class.scopie_class
38
+ return scopie_class if scopie_class
23
39
 
24
40
  scopie_name = params[:controller] + ScopieRails::SCOPIE_SUFFIX
25
41
 
26
- self.class.scopie_class = scopie_name.camelize.constantize
27
-
28
- self.class.scopie_class
42
+ self.scopie_class = scopie_name.camelize.constantize
29
43
  end
30
44
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ScopieRails
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.1'.freeze
5
5
  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: 1.0.1
4
+ version: 1.1.1
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-25 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scopie
@@ -73,6 +73,11 @@ extra_rdoc_files: []
73
73
  files:
74
74
  - LICENSE
75
75
  - README.md
76
+ - lib/generators/rspec/scopie_generator.rb
77
+ - lib/generators/rspec/templates/scopie_spec.rb
78
+ - lib/generators/scopie_rails/scopie/USAGE
79
+ - lib/generators/scopie_rails/scopie/scopie_generator.rb
80
+ - lib/generators/scopie_rails/scopie/templates/scopie.rb
76
81
  - lib/scopie_rails.rb
77
82
  - lib/scopie_rails/base.rb
78
83
  - lib/scopie_rails/controller.rb