constrainable 0.3.0 → 0.3.1
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.
- data/README.markdown +23 -0
- data/lib/bsm/constrainable/filter_set.rb +3 -3
- data/lib/bsm/constrainable/model.rb +1 -1
- metadata +5 -7
data/README.markdown
CHANGED
@@ -70,3 +70,26 @@ What about associations?
|
|
70
70
|
Post.constrain(params[:where])
|
71
71
|
# => SELECT posts.* FROM posts LEFT OUTER JOIN authors ON authors.id = posts.author_id WHERE authors.name LIKE '%tom%'
|
72
72
|
|
73
|
+
Integration with controllers, views & filter forms:
|
74
|
+
|
75
|
+
# In app/models/post.rb
|
76
|
+
class Post < ActiveRecord::Base
|
77
|
+
constrainable do
|
78
|
+
fields :author_id
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# In app/controllers/posts_controller.rb
|
83
|
+
class PostsController < ApplicationController
|
84
|
+
respond_to :html
|
85
|
+
|
86
|
+
def index
|
87
|
+
@filters = Post.constrainable.fliter(params[:where])
|
88
|
+
@posts = Post.constrain(@filters)
|
89
|
+
respond_with @posts
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# In app/views/posts/index.html.haml
|
94
|
+
= form_for @filters, :as => :where do
|
95
|
+
= f.collection_select :"author_id[eq]", Author.order('name'), :id, :name
|
@@ -11,13 +11,13 @@ class Bsm::Constrainable::FilterSet < Hash
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def merge(
|
14
|
+
def merge(scoped)
|
15
15
|
each do |name, part|
|
16
16
|
schema[name].each do |field|
|
17
|
-
|
17
|
+
scoped = field.merge(scoped, part)
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
20
|
+
scoped
|
21
21
|
end
|
22
22
|
|
23
23
|
def respond_to?(sym, *)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constrainable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dimitrij Denissenko
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-07-22 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: abstract
|
@@ -91,7 +90,6 @@ files:
|
|
91
90
|
- lib/bsm/constrainable/operation/collection.rb
|
92
91
|
- lib/bsm/constrainable/operation/not_in.rb
|
93
92
|
- lib/bsm/constrainable.rb
|
94
|
-
has_rdoc: true
|
95
93
|
homepage: https://github.com/bsm/constrainable
|
96
94
|
licenses: []
|
97
95
|
|
@@ -125,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
123
|
requirements: []
|
126
124
|
|
127
125
|
rubyforge_project:
|
128
|
-
rubygems_version: 1.
|
126
|
+
rubygems_version: 1.8.5
|
129
127
|
signing_key:
|
130
128
|
specification_version: 3
|
131
129
|
summary: Simple filtering for ActiveRecord
|