sortable-model 0.0.1 → 0.0.2
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/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +14 -17
- data/README.rdoc +17 -0
- data/Rakefile +41 -12
- data/VERSION +1 -1
- data/{sortable_model.rb → lib/sortable-model.rb} +0 -0
- data/spec/sortable-model_spec.rb +51 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +17 -0
- metadata +29 -14
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
CHANGED
@@ -1,23 +1,20 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2009 EdgeCase LLC
|
2
2
|
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
conditions:
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
11
10
|
|
12
11
|
The above copyright notice and this permission notice shall be
|
13
12
|
included in all copies or substantial portions of the Software.
|
14
13
|
|
15
14
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
-
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
-
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= sortable-model
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Jon Distad. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,20 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
1
4
|
begin
|
2
5
|
require 'jeweler'
|
3
|
-
Jeweler::Tasks.new do |
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Sortable-model
|
8
|
-
|
9
|
-
|
10
|
-
without the risk of arbitrary code execution.
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "sortable-model"
|
8
|
+
gem.summary = "DSL for generating ordering named-scopes for ActiveRecord models"
|
9
|
+
gem.description = <<EOS
|
10
|
+
Sortable-model provides a DSL for creating named scopes that order the object in question based
|
11
|
+
on its own attributes or those of its associations. It also provides a method for calling those
|
12
|
+
scopes that allows the values to come directly from params without the risk of arbitrary code execution.
|
11
13
|
EOS
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
gem.email = "github@edgecase.com"
|
15
|
+
gem.homepage = "http://github.com/edgecase/sortable-model"
|
16
|
+
gem.authors = ["EdgeCase LLC"]
|
17
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
19
|
end
|
16
20
|
Jeweler::GemcutterTasks.new
|
17
21
|
rescue LoadError
|
18
|
-
puts "Jeweler not available. Install it with: gem install jeweler"
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'spec/rake/spectask'
|
26
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
+
end
|
30
|
+
|
31
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
32
|
+
spec.libs << 'lib' << 'spec'
|
33
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
34
|
+
spec.rcov = true
|
19
35
|
end
|
20
36
|
|
37
|
+
task :spec => :check_dependencies
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rake/rdoctask'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "sortable-model #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe SortableModel do
|
4
|
+
before do
|
5
|
+
@model_class = Class.new(ActiveRecord::Base).sortable_model
|
6
|
+
@model_class.stub! :reflect_on_association => mock('assoc', :quoted_table_name => '`assoc_table`'),
|
7
|
+
:quoted_table_name => '`model_classes`'
|
8
|
+
end
|
9
|
+
|
10
|
+
def define_scope
|
11
|
+
@model_class.instance_eval do
|
12
|
+
can_sort_by :name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#sorted_by" do
|
17
|
+
it "calls the named scope if it exists" do
|
18
|
+
define_scope
|
19
|
+
@model_class.should_receive("_sorted_by_name")
|
20
|
+
@model_class.sorted_by(:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "blows up if the sort is not defined" do
|
24
|
+
lambda {
|
25
|
+
@model_class.sorted_by(:name)
|
26
|
+
}.should raise_error(NoMethodError, "Sort condition is not defined: name")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#can_sort_by" do
|
31
|
+
it "delegates to #named_scope" do
|
32
|
+
@model_class.should_receive(:named_scope)
|
33
|
+
define_scope
|
34
|
+
end
|
35
|
+
|
36
|
+
it "works with a simple hash" do
|
37
|
+
@model_class.should_receive(:named_scope)
|
38
|
+
@model_class.instance_eval do
|
39
|
+
can_sort_by :something => :else
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "can work like a default named_scope" do
|
44
|
+
scope = lambda { |x| {:order => x} }
|
45
|
+
@model_class.should_receive(:named_scope).with("_sorted_by_foo", scope)
|
46
|
+
@model_class.instance_eval do
|
47
|
+
can_sort_by :foo, scope
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
unless Object.const_defined?(:ActiveRecord)
|
2
|
+
module ActiveRecord
|
3
|
+
class Base
|
4
|
+
def self.named_scope(*args) end
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
11
|
+
require 'sortable-model'
|
12
|
+
require 'spec'
|
13
|
+
require 'spec/autorun'
|
14
|
+
|
15
|
+
Spec::Runner.configure do |config|
|
16
|
+
|
17
|
+
end
|
metadata
CHANGED
@@ -1,24 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortable-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
- Ehren Murdick
|
7
|
+
- EdgeCase LLC
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
11
|
|
13
12
|
date: 2010-02-03 00:00:00 -05:00
|
14
13
|
default_executable:
|
15
|
-
dependencies:
|
16
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
17
25
|
description: |
|
18
|
-
Sortable-model
|
19
|
-
|
20
|
-
|
21
|
-
without the risk of arbitrary code execution.
|
26
|
+
Sortable-model provides a DSL for creating named scopes that order the object in question based
|
27
|
+
on its own attributes or those of its associations. It also provides a method for calling those
|
28
|
+
scopes that allows the values to come directly from params without the risk of arbitrary code execution.
|
22
29
|
|
23
30
|
email: github@edgecase.com
|
24
31
|
executables: []
|
@@ -27,13 +34,20 @@ extensions: []
|
|
27
34
|
|
28
35
|
extra_rdoc_files:
|
29
36
|
- LICENSE
|
37
|
+
- README.rdoc
|
30
38
|
files:
|
39
|
+
- .document
|
40
|
+
- .gitignore
|
31
41
|
- LICENSE
|
42
|
+
- README.rdoc
|
32
43
|
- Rakefile
|
33
44
|
- VERSION
|
34
|
-
-
|
45
|
+
- lib/sortable-model.rb
|
46
|
+
- spec/sortable-model_spec.rb
|
47
|
+
- spec/spec.opts
|
48
|
+
- spec/spec_helper.rb
|
35
49
|
has_rdoc: true
|
36
|
-
homepage: http://github.com/edgecase/
|
50
|
+
homepage: http://github.com/edgecase/sortable-model
|
37
51
|
licenses: []
|
38
52
|
|
39
53
|
post_install_message:
|
@@ -59,6 +73,7 @@ rubyforge_project:
|
|
59
73
|
rubygems_version: 1.3.5
|
60
74
|
signing_key:
|
61
75
|
specification_version: 3
|
62
|
-
summary:
|
63
|
-
test_files:
|
64
|
-
|
76
|
+
summary: DSL for generating ordering named-scopes for ActiveRecord models
|
77
|
+
test_files:
|
78
|
+
- spec/sortable-model_spec.rb
|
79
|
+
- spec/spec_helper.rb
|