expose_query 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +3 -0
- data/.travis.yml +9 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +10 -0
- data/expose_query.gemspec +27 -0
- data/lib/expose_query.rb +19 -0
- data/lib/expose_query/active_record_query_strategy.rb +9 -0
- data/lib/expose_query/base_query.rb +15 -0
- data/lib/expose_query/controller_dsl.rb +21 -0
- data/lib/expose_query/version.rb +3 -0
- data/spec/expose_query/active_record_query_strategy_spec.rb +52 -0
- data/spec/expose_query/controller_dsl_spec.rb +51 -0
- data/spec/spec_helper.rb +10 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64c564ae2dcd3f4495f673b6f1184e9d4db503b0
|
4
|
+
data.tar.gz: e45667d9271f9991a90b468d7ddca49995562c1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8981e0aabc43c8ea8695ccb88970733e478a84e2ed07fa870cca47491862eaf2c212934ee99d90ab77a4ce9d81da7eb445fbc81a7a5d7dd92096dead64a54e5
|
7
|
+
data.tar.gz: 47ad677a7e9744e4946d838b9b6a4db29ae6387d8212fd35a2aebe67295480502557c6fdec1a55fd64ca9a1cdc9e8dd9ba357b18bbff44cde034cece977182ca
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
.idea
|
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
addons:
|
7
|
+
code_climate:
|
8
|
+
repo_token:
|
9
|
+
secure: NfFT/grGZN8mu41KVqTYba7c6FfLVyDBo0jmtzYEk2NVub/SuhY1pQneR3qSyNPz955RLMEhKhC8CqfmzuAdj9Md8ye8vFq1JP1IZrBVtrK5o5htPNOMSURnIHfRkQnnlXNiCLF5HQFkvLx2LRNtMB7xxCljUTabrCf3tBiqX4E=
|
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in expose_query.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'rails'
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'guard-rspec', require: false
|
10
|
+
end
|
11
|
+
|
12
|
+
group :test do
|
13
|
+
gem 'codeclimate-test-reporter', require: nil
|
14
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Nick Chubarov
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/chubarovNick/expose_query.png)](https://codeclimate.com/github/chubarovNick/expose_query)
|
2
|
+
|
3
|
+
# ExposeQuery
|
4
|
+
|
5
|
+
Add query benefit for exposed decent_exsposure values
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'expose_query'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install expose_query
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
TODO: Write usage instructions here
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
1. Fork it ( https://github.com/[my-github-username]/expose_query/fork )
|
27
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
28
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
29
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
30
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'expose_query/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "expose_query"
|
8
|
+
spec.version = ExposeQuery::VERSION
|
9
|
+
spec.authors = ["Nick Chubarov"]
|
10
|
+
spec.email = ["nick.chubarov@gmail.com"]
|
11
|
+
spec.summary = %q{A helper for creating declaretive interface for decent_exposure queries}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'decent_exposure', '~> 2.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rspec-rails'
|
24
|
+
spec.add_development_dependency 'actionpack', '>= 3.1.0'
|
25
|
+
spec.add_development_dependency 'activesupport', '>= 3.1.0'
|
26
|
+
|
27
|
+
end
|
data/lib/expose_query.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'expose_query/version'
|
2
|
+
require 'expose_query/base_query'
|
3
|
+
require 'expose_query/controller_dsl'
|
4
|
+
require 'expose_query/active_record_query_strategy'
|
5
|
+
require 'decent_exposure'
|
6
|
+
|
7
|
+
ActiveSupport.on_load(:action_controller) do
|
8
|
+
include ExposeQuery::ControllerDsl
|
9
|
+
end
|
10
|
+
|
11
|
+
DecentExposure::ActiveRecordStrategy.class_eval do
|
12
|
+
include ExposeQuery::ActiveRecordQueryStrategy
|
13
|
+
|
14
|
+
alias_method :original_resource, :resource
|
15
|
+
|
16
|
+
def resource
|
17
|
+
filtered_resource
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
2
|
+
class ExposeQuery::BaseQuery
|
3
|
+
attr_reader :controller
|
4
|
+
|
5
|
+
delegate :params, to: :controller
|
6
|
+
|
7
|
+
def initialize(controller)
|
8
|
+
@controller = controller
|
9
|
+
end
|
10
|
+
|
11
|
+
def apply(source_scope)
|
12
|
+
source_scope
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
module ExposeQuery
|
3
|
+
module ControllerDsl
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
|
8
|
+
cattr_accessor :query_classes
|
9
|
+
|
10
|
+
def self.expose_query(*filter_classes)
|
11
|
+
self.query_classes = Array.wrap(filter_classes.to_a)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def apply_filters(source_scope)
|
17
|
+
query_classes ? query_classes.reduce(source_scope){|scope, filter| filter.new(self).apply(scope)} : source_scope
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'expose_query'
|
3
|
+
|
4
|
+
describe ExposeQuery::ActiveRecordQueryStrategy do
|
5
|
+
|
6
|
+
let(:inflector) do
|
7
|
+
double("Inflector", parameter: 'model_id', plural?: plural, plural: 'models', singular: 'model')
|
8
|
+
end
|
9
|
+
let(:model) { double('Model', new: nil) }
|
10
|
+
let(:params) { Hash.new }
|
11
|
+
let(:request) { double('request', post?: false, put?: false, patch?: false) }
|
12
|
+
let(:config) { double('config', options: {}) }
|
13
|
+
let(:controller_class) do
|
14
|
+
double('controller_class', _decent_configurations: Hash.new(config))
|
15
|
+
end
|
16
|
+
let(:controller) { double('controller', params: params, request: request, class: controller_class) }
|
17
|
+
|
18
|
+
let(:strategy) { DecentExposure::ActiveRecordStrategy.new(controller, inflector) }
|
19
|
+
|
20
|
+
before do
|
21
|
+
strategy.model = model
|
22
|
+
strategy.inflector = inflector
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#resource' do
|
26
|
+
let(:plural) { true }
|
27
|
+
let(:scoped) { double('Scoped') }
|
28
|
+
subject { strategy.resource }
|
29
|
+
|
30
|
+
context 'with ActiveRecord 3' do
|
31
|
+
before do
|
32
|
+
stub_const('ActiveRecord::VERSION::MAJOR', 3)
|
33
|
+
end
|
34
|
+
it 'returns the scoped collection' do
|
35
|
+
expect(model).to receive(:scoped).and_return(scoped)
|
36
|
+
expect(controller).to receive(:apply_filters).and_return(scoped)
|
37
|
+
expect(subject).to eq(scoped)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with ActiveRecord 4' do
|
42
|
+
before do
|
43
|
+
stub_const('ActiveRecord::VERSION::MAJOR', 4)
|
44
|
+
end
|
45
|
+
it 'returns the scoped collection' do
|
46
|
+
expect(model).to receive(:all).and_return(scoped)
|
47
|
+
expect(controller).to receive(:apply_filters).and_return(scoped)
|
48
|
+
expect(subject).to eq(scoped)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'decent_exposure/expose'
|
3
|
+
require 'action_controller'
|
4
|
+
|
5
|
+
class DummyQuery < ExposeQuery::BaseQuery
|
6
|
+
|
7
|
+
def apply(source_scope)
|
8
|
+
source_scope
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class DummyController < ActionController::Base
|
14
|
+
include ExposeQuery::ControllerDsl
|
15
|
+
extend DecentExposure::Expose
|
16
|
+
expose(:bird) #{ 'Bird' }
|
17
|
+
expose_query DummyQuery
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe ExposeQuery::ControllerDsl do
|
22
|
+
|
23
|
+
describe '.expose_query' do
|
24
|
+
subject { DummyController }
|
25
|
+
|
26
|
+
it { should respond_to(:expose_query) }
|
27
|
+
|
28
|
+
it { should respond_to(:query_classes) }
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '.query_classes' do
|
33
|
+
subject { DummyController.query_classes }
|
34
|
+
|
35
|
+
it { is_expected.to include(DummyQuery) }
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '' do
|
40
|
+
let(:controller) { DummyController.new }
|
41
|
+
let(:scope) {double(:scope)}
|
42
|
+
before { expect_any_instance_of(DummyQuery).to receive(:apply).and_call_original }
|
43
|
+
subject { controller.apply_filters(scope) }
|
44
|
+
|
45
|
+
it { is_expected.to eq(scope) }
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
require 'codeclimate-test-reporter'
|
4
|
+
CodeClimate::TestReporter.start if ENV['CODECLIMATE_REPO_TOKEN']
|
5
|
+
|
6
|
+
require 'expose_query' # and any other gems you need
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
# some (optional) config here
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: expose_query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Chubarov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: decent_exposure
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: actionpack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.0
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- nick.chubarov@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- expose_query.gemspec
|
98
|
+
- lib/expose_query.rb
|
99
|
+
- lib/expose_query/active_record_query_strategy.rb
|
100
|
+
- lib/expose_query/base_query.rb
|
101
|
+
- lib/expose_query/controller_dsl.rb
|
102
|
+
- lib/expose_query/version.rb
|
103
|
+
- spec/expose_query/active_record_query_strategy_spec.rb
|
104
|
+
- spec/expose_query/controller_dsl_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
homepage: ''
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.2.2
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: A helper for creating declaretive interface for decent_exposure queries
|
130
|
+
test_files:
|
131
|
+
- spec/expose_query/active_record_query_strategy_spec.rb
|
132
|
+
- spec/expose_query/controller_dsl_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
has_rdoc:
|