forty_facets 0.0.8 → 0.0.9

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: 3667e156a13134b58e742270c9a19671cd6e81b0
4
- data.tar.gz: 692413b311dc68334826c7fa9460fd9acab6f403
3
+ metadata.gz: 2ebaa1971ee0830ae8723e8eec222fa2f4ea9227
4
+ data.tar.gz: c6d056a6e4714b5aa21715fed17587cc467129fb
5
5
  SHA512:
6
- metadata.gz: 6344847f3c58519bd965b018910c9146851c5276ebf0a678227b3295f35efc37d4abc9459ad09592ee048521941c8f22e08151de01ad8892d18417c4da0656df
7
- data.tar.gz: 85db56a26bdc57ba0eded2681c7f9554e397feb175c6250a946a30a7d6b101f25a635f36200cf16371a6550a1e2a989d5821e78367cefaf1c2f5113a628673a6
6
+ metadata.gz: 1fd1e8a57e598c2c5216a77a81824514c4a56e3bae3b54223b8cab467b60ed3eb63cf9b3e2cf4b979ad2bcff6a800fa5616f6eb78a0e1be7bb8c069325605c5f
7
+ data.tar.gz: d960db30251ddbd60848c5dbba003631790018b4c3d24eddff4357f8ef32a7da7628550a2327a59ebef9cbe6b3b85bf4010c1ee2a5e4f2a8bbd0321a93276117
data/.gitignore CHANGED
@@ -16,4 +16,4 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .idea
19
-
19
+ .*.swp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ forty_facets
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
data/forty_facets.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "minitest"
24
24
  spec.add_development_dependency "sqlite3"
25
25
  spec.add_development_dependency "coveralls"
26
- spec.add_development_dependency "activerecord", ">= 4.0"
27
- spec.add_development_dependency "byebug"
26
+ spec.add_development_dependency "activerecord", "= 4.1.0"
27
+ # spec.add_development_dependency "byebug" # travis doenst like byebug
28
28
  end
@@ -32,7 +32,7 @@ module FortyFacets
32
32
  end
33
33
 
34
34
  def facet(model_field, opts = {})
35
- reflection = self.root_scope.reflect_on_association(model_field)
35
+ reflection = self.root_class.reflect_on_association(model_field)
36
36
  if reflection
37
37
  if reflection.macro == :belongs_to
38
38
  definitions << BelongsToFilterDefinition.new(self, model_field, opts)
@@ -74,7 +74,7 @@ module FortyFacets
74
74
  end
75
75
  end
76
76
 
77
- def initialize(request_params = {})
77
+ def initialize(request_params = {}, root = nil)
78
78
  params = request_to_search_params(request_params)
79
79
  @filters = self.class.definitions.inject([]) do |filters, definition|
80
80
  filters << definition.build_filter(self, params[definition.request_param])
@@ -84,10 +84,11 @@ module FortyFacets
84
84
  orders << definition.build(self, params[:order])
85
85
  end
86
86
 
87
+ @root = root
87
88
  end
88
89
 
89
- def self.new_unwrapped(params)
90
- self.new(request_param_name => params)
90
+ def self.new_unwrapped(params, root)
91
+ self.new({request_param_name => params}, root)
91
92
  end
92
93
 
93
94
  def filter(filter_name)
@@ -101,7 +102,7 @@ module FortyFacets
101
102
  end
102
103
 
103
104
  def result
104
- query = @filters.inject(self.class.root_scope) do |previous, filter|
105
+ query = @filters.inject(root) do |previous, filter|
105
106
  filter.build_scope.call(previous)
106
107
  end
107
108
  query = query.order(order.definition.clause) if order
@@ -129,6 +130,10 @@ module FortyFacets
129
130
  @filters.reject(&:empty?).empty?
130
131
  end
131
132
 
133
+ def root
134
+ @root || self.class.root_scope
135
+ end
136
+
132
137
  private
133
138
 
134
139
  def request_to_search_params(request_params)
@@ -28,14 +28,14 @@ module FortyFacets
28
28
  old_values = new_params[filter_definition.request_param]
29
29
  old_values.delete(value.to_s)
30
30
  new_params.delete(filter_definition.request_param) if old_values.empty?
31
- search_instance.class.new_unwrapped(new_params)
31
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
32
32
  end
33
33
 
34
34
  def add(value)
35
35
  new_params = search_instance.params || {}
36
36
  old_values = new_params[filter_definition.request_param] ||= []
37
37
  old_values << value.to_s
38
- search_instance.class.new_unwrapped(new_params)
38
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
39
39
  end
40
40
  end
41
41
 
@@ -38,14 +38,14 @@ module FortyFacets
38
38
  old_values = new_params[filter_definition.request_param]
39
39
  old_values.delete(entity.id.to_s)
40
40
  new_params.delete(filter_definition.request_param) if old_values.empty?
41
- search_instance.class.new_unwrapped(new_params)
41
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
42
42
  end
43
43
 
44
44
  def add(entity)
45
45
  new_params = search_instance.params || {}
46
46
  old_values = new_params[filter_definition.request_param] ||= []
47
47
  old_values << entity.id.to_s
48
- search_instance.class.new_unwrapped(new_params)
48
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
49
49
  end
50
50
 
51
51
  end
@@ -53,14 +53,14 @@ module FortyFacets
53
53
  old_values = new_params[filter_definition.request_param]
54
54
  old_values.delete(entity.id.to_s)
55
55
  new_params.delete(filter_definition.request_param) if old_values.empty?
56
- search_instance.class.new_unwrapped(new_params)
56
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
57
57
  end
58
58
 
59
59
  def add(entity)
60
60
  new_params = search_instance.params || {}
61
61
  old_values = new_params[filter_definition.request_param] ||= []
62
62
  old_values << entity.id.to_s
63
- search_instance.class.new_unwrapped(new_params)
63
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
64
64
  end
65
65
 
66
66
  end
@@ -17,7 +17,7 @@ module FortyFacets
17
17
  return search if empty?
18
18
  new_params = search_instance.params || {}
19
19
  new_params.delete(filter_definition.request_param)
20
- search_instance.class.new_unwrapped(new_params)
20
+ search_instance.class.new_unwrapped(new_params, search_instance.root)
21
21
  end
22
22
  end
23
23
 
@@ -9,7 +9,7 @@ module FortyFacets
9
9
  def by
10
10
  new_params = search.params || {}
11
11
  new_params[:order] = definition.request_value
12
- search.class.new_unwrapped(new_params)
12
+ search.class.new_unwrapped(new_params, search.root)
13
13
  end
14
14
  end
15
15
  end
@@ -1,3 +1,3 @@
1
1
  module FortyFacets
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/test/fixtures.rb CHANGED
@@ -3,7 +3,8 @@ require 'active_record'
3
3
  ActiveRecord::Migration.verbose = false
4
4
  ActiveRecord::Base.logger = Logger.new(nil)
5
5
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
6
- ActiveRecord::Base.connection.instance_eval do
6
+
7
+ ActiveRecord::Schema.define do
7
8
 
8
9
  create_table :studios do |t|
9
10
  t.string :name
data/test/smoke_test.rb CHANGED
@@ -3,7 +3,7 @@ Coveralls.wear!
3
3
 
4
4
  require "minitest/autorun"
5
5
  require 'logger'
6
- require 'byebug'
6
+ #require 'byebug'# travis doenst like byebug
7
7
  require_relative '../lib/forty_facets'
8
8
 
9
9
  #silence_warnings do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forty_facets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Axel Tetzlaff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-14 00:00:00.000000000 Z
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,30 +84,16 @@ dependencies:
84
84
  name: activerecord
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: '4.0'
89
+ version: 4.1.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '4.0'
97
- - !ruby/object:Gem::Dependency
98
- name: byebug
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
94
+ - - '='
102
95
  - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
96
+ version: 4.1.0
111
97
  description: FortyFacets lets you easily build explorative search interfaces based
112
98
  on fields of your active_record models.
113
99
  email:
@@ -118,6 +104,8 @@ extra_rdoc_files: []
118
104
  files:
119
105
  - ".coveralls.yml"
120
106
  - ".gitignore"
107
+ - ".ruby-gemset"
108
+ - ".ruby-version"
121
109
  - ".travis.yml"
122
110
  - Gemfile
123
111
  - LICENSE.txt
@@ -159,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
159
147
  version: '0'
160
148
  requirements: []
161
149
  rubyforge_project:
162
- rubygems_version: 2.2.0
150
+ rubygems_version: 2.2.2
163
151
  signing_key:
164
152
  specification_version: 4
165
153
  summary: Library for building facet searches for active_record models