hikari 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +36 -0
- data/Rakefile +5 -0
- data/VERSION +1 -0
- data/hikari.gemspec +36 -0
- data/lib/hikari.rb +9 -0
- data/lib/hikari/active_record.rb +32 -0
- data/lib/hikari/parser.rb +60 -0
- data/lib/hikari/railtie.rb +19 -0
- data/lib/hikari/version.rb +3 -0
- data/lib/hikari/view_helpers/action_view.rb +74 -0
- data/spec/lib/action_view_spec.rb +32 -0
- data/spec/lib/parser_spec.rb +28 -0
- data/spec/lib/post_spec.rb +57 -0
- data/spec/schema.rb +53 -0
- data/spec/spec_helper.rb +14 -0
- data/tasks/spec.rake +34 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eccc48c31fadc36442a5b34c330d54e5186601e3
|
4
|
+
data.tar.gz: f03c7c63eaf90399c37f5da6bea85e46dbf6d16a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12763e4935029434aca9f678c4ca0ac39c6a42c0fb52612b1e1cb748f57684b7dceeb1e37998f0aa1b7a35e4303b0ecd31673e31b734bd50beb9ae242da66182
|
7
|
+
data.tar.gz: 655f4adcb2bdfc18b2255073fac552e41386ed9e8ec760c5ce8bc4fed9a87bb00c2c48374293bd421ac6a02d4b56d77bca700b30b01ee2384a9178f905e441a3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Seth Faxon
|
2
|
+
|
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:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
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,36 @@
|
|
1
|
+
Hikari helps create sorting links for Ruby on Rails applications. It also
|
2
|
+
allows sorting on associated models via scopes and default orders to be
|
3
|
+
provided in the view. It pairs nicely with Kaminari, but only works with
|
4
|
+
ActiveRecord at the moment.
|
5
|
+
|
6
|
+
Simple example
|
7
|
+
|
8
|
+
class Post < ActiveRecord::Base
|
9
|
+
belongs_to :author, class_name: 'User'
|
10
|
+
|
11
|
+
scope :by_author_last_name, -> {
|
12
|
+
joins(:author).order("users.last_name")
|
13
|
+
}
|
14
|
+
end
|
15
|
+
class User < ActiveRecord::Base
|
16
|
+
has_many :posts
|
17
|
+
end
|
18
|
+
|
19
|
+
app/controllers/posts_controller.rb
|
20
|
+
|
21
|
+
def index
|
22
|
+
@posts = Post.sort(params[:sort], 'title ASC')
|
23
|
+
end
|
24
|
+
|
25
|
+
app/views/posts/index.html.erb
|
26
|
+
|
27
|
+
<%= link_to_sorted 'Title', :title %>
|
28
|
+
|
29
|
+
<a href="/posts?sort=title_asc" class="sortable">Title</a>
|
30
|
+
|
31
|
+
If a field matching the sort parameter is not found Hikari will attempt
|
32
|
+
to apply an ActiveRecord scope that is defined on the model. To sort Posts by
|
33
|
+
Author:
|
34
|
+
|
35
|
+
<%= link_to_sorted 'By Author', :by_author_last_name %>
|
36
|
+
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/hikari.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "hikari/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "hikari"
|
7
|
+
s.version = Hikari::VERSION
|
8
|
+
s.authors = ["Seth Faxon"]
|
9
|
+
s.email = ["seth.faxon@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/sfaxon/hikari"
|
11
|
+
s.summary = %q{Hikari is a field and scope based sorting helper for Rails.}
|
12
|
+
s.description = %q{Hikari allows sorting in Rails projects based on fields or scopes.
|
13
|
+
Sorting can be done across models via scopes.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "hikari"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.extra_rdoc_files = [
|
23
|
+
"MIT-LICENSE",
|
24
|
+
"README.rdoc"
|
25
|
+
]
|
26
|
+
|
27
|
+
# specify any dependencies here; for example:
|
28
|
+
s.add_dependency "activerecord", ">= 4.0.0"
|
29
|
+
s.add_dependency "actionpack", ">= 4.0.0"
|
30
|
+
|
31
|
+
s.add_development_dependency "rspec", "~> 3.1.0"
|
32
|
+
s.add_development_dependency "sqlite3", "~> 1.3"
|
33
|
+
s.add_development_dependency "rake", ">= 0"
|
34
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
35
|
+
|
36
|
+
end
|
data/lib/hikari.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'hikari'
|
2
|
+
require 'active_support/concern'
|
3
|
+
|
4
|
+
|
5
|
+
module Hikari
|
6
|
+
module ActiveRecord
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
def self.sort(sort_param, default_order = nil)
|
11
|
+
parser = ::Hikari::Parser.new(sort_param, default_order)
|
12
|
+
if self.column_names.include?(parser.field)
|
13
|
+
if parser.asc?
|
14
|
+
order( parser.field )
|
15
|
+
else
|
16
|
+
order( parser.field ).reverse_order
|
17
|
+
end
|
18
|
+
elsif self.respond_to?(parser.field)
|
19
|
+
if parser.asc?
|
20
|
+
self.send(parser.field)
|
21
|
+
else
|
22
|
+
self.send(parser.field).reverse_order
|
23
|
+
end
|
24
|
+
else
|
25
|
+
# do nothing, log error
|
26
|
+
all
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hikari
|
2
|
+
class Parser
|
3
|
+
attr_reader :field, :order
|
4
|
+
ASC = 'ASC'.freeze
|
5
|
+
DESC = 'DESC'.freeze
|
6
|
+
|
7
|
+
# Regex for safety
|
8
|
+
PARAMS_REGEX = /([a-zA-Z0-9._]+)_(asc|desc)$/
|
9
|
+
|
10
|
+
def initialize(sort_param, default = nil)
|
11
|
+
if sort_param.is_a?(Hash) || sort_param.is_a?(Array)
|
12
|
+
self.field = sort_param.flatten.first.to_s
|
13
|
+
self.order = sort_param.flatten.last
|
14
|
+
else
|
15
|
+
sort_param ||= ''
|
16
|
+
match = sort_param.match(PARAMS_REGEX)
|
17
|
+
if match
|
18
|
+
self.field = match[1]
|
19
|
+
self.order = match[2]
|
20
|
+
elsif default.present?
|
21
|
+
default = default.split(' ')
|
22
|
+
self.order = default.pop
|
23
|
+
self.field = default.join('')
|
24
|
+
else
|
25
|
+
self.field = sort_param
|
26
|
+
self.order = ASC
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def field=(f)
|
32
|
+
@field = f.to_s.downcase
|
33
|
+
end
|
34
|
+
|
35
|
+
def order=(o)
|
36
|
+
if :desc == o.downcase.to_sym
|
37
|
+
@order = DESC
|
38
|
+
else
|
39
|
+
@order = ASC
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def asc?
|
44
|
+
ASC == @order
|
45
|
+
end
|
46
|
+
|
47
|
+
def desc?
|
48
|
+
DESC == @order
|
49
|
+
end
|
50
|
+
|
51
|
+
def swap_order!
|
52
|
+
asc? ? @order = DESC : @order = ASC
|
53
|
+
self
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
"#{@field}_#{@order}".downcase
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'hikari'
|
2
|
+
|
3
|
+
module Hikari
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "hikari.configure" do |app|
|
6
|
+
if defined? ::ActiveRecord
|
7
|
+
ActiveSupport.on_load :active_record do
|
8
|
+
require 'hikari/active_record'
|
9
|
+
include Hikari::ActiveRecord
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActiveSupport.on_load :action_view do
|
14
|
+
require 'hikari/view_helpers/action_view'
|
15
|
+
include Hikari::ViewHelpers::ActionView
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
require 'hikari'
|
3
|
+
|
4
|
+
module Hikari
|
5
|
+
module ViewHelpers
|
6
|
+
module ActionView
|
7
|
+
class HikariViewHelper
|
8
|
+
attr_reader :params
|
9
|
+
|
10
|
+
def initialize(field, params = {})
|
11
|
+
sort = params[:sort]
|
12
|
+
@params = params
|
13
|
+
@field_parse = ::Hikari::Parser.new(field)
|
14
|
+
if sort
|
15
|
+
@sort_param_parser = ::Hikari::Parser.new(sort)
|
16
|
+
|
17
|
+
if @field_parse.field == @sort_param_parser.field
|
18
|
+
@params[:sort] = @sort_param_parser.swap_order!.to_s
|
19
|
+
else
|
20
|
+
@params[:sort] = @field_parse.to_s
|
21
|
+
end
|
22
|
+
else
|
23
|
+
@params[:sort] = @field_parse.to_s
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def css(current_field)
|
28
|
+
if current_field.is_a?(Hash) || current_field.is_a?(Array)
|
29
|
+
current_field = current_field.flatten.first
|
30
|
+
end
|
31
|
+
if @sort_param_parser.try(:field) == current_field.to_s
|
32
|
+
"sorted-#{@field_parse.order.downcase}"
|
33
|
+
else
|
34
|
+
"sortable"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Public: Create a sorted link
|
40
|
+
#
|
41
|
+
# args - link_to style arguments accepted
|
42
|
+
#
|
43
|
+
# Examples
|
44
|
+
#
|
45
|
+
# link_to_sorted "Title", :title
|
46
|
+
# # => <a href="/posts?sort=title_asc" class="sortable">Title</a>
|
47
|
+
#
|
48
|
+
# link_to_sorted :title do
|
49
|
+
# <strong>Title</strong>
|
50
|
+
# end
|
51
|
+
# # => <a href="/posts?sort=title_asc" class="sortable"><strong>Title</strong></a>
|
52
|
+
#
|
53
|
+
# link_to_sorted "Created At", {created_at: :desc}
|
54
|
+
# # => <a href="/posts?sort=created_at_desc" class="sortable">Created At</a>
|
55
|
+
#
|
56
|
+
def link_to_sorted(*args, &block)
|
57
|
+
if block_given?
|
58
|
+
field = args[0]
|
59
|
+
options = args[1] || {}
|
60
|
+
html_options = args[2] || {}
|
61
|
+
else
|
62
|
+
block = proc { args[0].to_s }
|
63
|
+
field = args[1]
|
64
|
+
options = args[2] || {}
|
65
|
+
html_options = args[3] || {}
|
66
|
+
end
|
67
|
+
|
68
|
+
sorter = HikariViewHelper.new(field, ((request.try(:get?) && !params.nil?) ? params.dup : {}))
|
69
|
+
options[:class] = [options[:class], sorter.css(field)].join(' ').strip
|
70
|
+
link_to(url_for(sorter.params), options, html_options, &block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_controller'
|
3
|
+
|
4
|
+
RSpec.describe Hikari::ViewHelpers::ActionView do
|
5
|
+
it 'should be loaded into ActionView' do
|
6
|
+
ActionView::Base.send(:include, Hikari::ViewHelpers::ActionView)
|
7
|
+
av = ActionView::Base.new
|
8
|
+
expect(av).to respond_to(:link_to_sorted)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
RSpec.describe Hikari::ViewHelpers::ActionView::HikariViewHelper do
|
13
|
+
it 'should default to asc' do
|
14
|
+
field = :title
|
15
|
+
view_helper = Hikari::ViewHelpers::ActionView::HikariViewHelper.new field, {}
|
16
|
+
expect(view_helper.params).to eq({sort: 'title_asc'})
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set desc when given' do
|
20
|
+
field = {title: :desc}
|
21
|
+
view_helper = Hikari::ViewHelpers::ActionView::HikariViewHelper.new field, {}
|
22
|
+
expect(view_helper.params).to eq({sort: 'title_desc'})
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should add swap sort order' do
|
26
|
+
field = :title
|
27
|
+
params = ActionController::Parameters.new(sort: "title_asc")
|
28
|
+
view_helper = Hikari::ViewHelpers::ActionView::HikariViewHelper.new field, params
|
29
|
+
expect(view_helper.params).to eq({'sort' => 'title_desc'})
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_controller'
|
3
|
+
|
4
|
+
RSpec.describe Hikari::Parser do
|
5
|
+
it 'should split the given sort string' do
|
6
|
+
g = Hikari::Parser.new('first_name_asc')
|
7
|
+
expect(g.field).to eq('first_name')
|
8
|
+
expect(g.order).to eq('ASC')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should split the default order' do
|
12
|
+
g = Hikari::Parser.new(nil, 'last_name ASC')
|
13
|
+
expect(g.field).to eq('last_name')
|
14
|
+
expect(g.order).to eq('ASC')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should work without sort' do
|
18
|
+
g = Hikari::Parser.new('first_name')
|
19
|
+
expect(g.field).to eq('first_name')
|
20
|
+
expect(g.order).to eq('ASC')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should take a hash' do
|
24
|
+
g = Hikari::Parser.new({last_name: :desc})
|
25
|
+
expect(g.field).to eq('last_name')
|
26
|
+
expect(g.order).to eq('DESC')
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_controller'
|
3
|
+
|
4
|
+
RSpec.describe Post, :type => :model do
|
5
|
+
before(:example) do
|
6
|
+
User.delete_all
|
7
|
+
Post.delete_all
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'field sorting' do
|
11
|
+
it 'should prefer params sort' do
|
12
|
+
p1 = Post.create(:title => "aaaa")
|
13
|
+
p2 = Post.create(:title => "bbbb")
|
14
|
+
params = ActionController::Parameters.new(sort: "title_asc")
|
15
|
+
|
16
|
+
result = Post.sort(params[:sort], 'title DESC')
|
17
|
+
expect(result.first).to eq(p1)
|
18
|
+
expect(result.last).to eq(p2)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should sort descending' do
|
22
|
+
p1 = Post.create(:title => "ccc")
|
23
|
+
p2 = Post.create(:title => "ddd")
|
24
|
+
params = ActionController::Parameters.new(sort: "title_desc")
|
25
|
+
|
26
|
+
result = Post.sort(params[:sort], 'title ASC')
|
27
|
+
expect(result.last).to eq(p1)
|
28
|
+
expect(result.first).to eq(p2)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'scope sorting' do
|
33
|
+
it 'should set default scope asc' do
|
34
|
+
a1 = User.create(last_name: 'aaa')
|
35
|
+
a2 = User.create(last_name: 'zzz')
|
36
|
+
p1 = Post.create(author: a1)
|
37
|
+
p2 = Post.create(author: a2)
|
38
|
+
|
39
|
+
result = Post.sort('', 'by_author_last_name ASC')
|
40
|
+
expect(result.count).to eq(2)
|
41
|
+
expect(result.first.author).to eq(a1)
|
42
|
+
expect(result.last.author).to eq(a2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set default scope desc' do
|
46
|
+
a1 = User.create(last_name: 'aaa')
|
47
|
+
a2 = User.create(last_name: 'zzz')
|
48
|
+
p1 = Post.create(author: a1)
|
49
|
+
p2 = Post.create(author: a2)
|
50
|
+
|
51
|
+
result = Post.sort('', 'by_author_last_name DESC')
|
52
|
+
expect(result.count).to eq(2)
|
53
|
+
expect(result.first.author).to eq(a2)
|
54
|
+
expect(result.last.author).to eq(a1)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/spec/schema.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'sqlite3'
|
3
|
+
|
4
|
+
ActiveRecord::Base.establish_connection(
|
5
|
+
:adapter => defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby' ? 'jdbcsqlite3' : 'sqlite3',
|
6
|
+
:database => File.join(File.dirname(__FILE__), 'test.db')
|
7
|
+
)
|
8
|
+
|
9
|
+
class CreateSchema < ActiveRecord::Migration
|
10
|
+
def self.up
|
11
|
+
create_table :posts, :force => true do |t|
|
12
|
+
t.integer :author_id
|
13
|
+
t.string :title
|
14
|
+
t.text :body
|
15
|
+
t.timestamps
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :users, :force => true do |t|
|
19
|
+
t.string :first_name
|
20
|
+
t.string :last_name
|
21
|
+
t.timestamps
|
22
|
+
end
|
23
|
+
|
24
|
+
create_table :comments, :force => true do |t|
|
25
|
+
t.integer :author_id
|
26
|
+
t.integer :post_id
|
27
|
+
t.text :body
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
CreateSchema.suppress_messages do
|
33
|
+
CreateSchema.migrate(:up)
|
34
|
+
end
|
35
|
+
|
36
|
+
class Post < ActiveRecord::Base
|
37
|
+
belongs_to :author, class_name: 'User'
|
38
|
+
has_many :comments
|
39
|
+
|
40
|
+
scope :by_author_last_name, -> {
|
41
|
+
joins(:author).order("users.last_name")
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
class User < ActiveRecord::Base
|
46
|
+
has_many :posts
|
47
|
+
has_many :comments
|
48
|
+
end
|
49
|
+
|
50
|
+
class Comment < ActiveRecord::Base
|
51
|
+
belongs_to :author, class_name: 'User'
|
52
|
+
belongs_to :post
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler.require
|
6
|
+
|
7
|
+
require 'hikari'
|
8
|
+
require 'hikari/active_record'
|
9
|
+
require 'hikari/view_helpers/action_view'
|
10
|
+
require 'rspec'
|
11
|
+
|
12
|
+
require 'schema'
|
13
|
+
|
14
|
+
ActiveRecord::Base.send(:include, Hikari::ActiveRecord)
|
data/tasks/spec.rake
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
ENV['BUNDLE_GEMFILE'] = File.dirname(__FILE__) + '/../Gemfile'
|
2
|
+
|
3
|
+
require 'rake'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rspec'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
|
8
|
+
desc "Run the test suite"
|
9
|
+
task :spec => ['spec:setup', 'spec:hikari_lib', 'spec:cleanup']
|
10
|
+
|
11
|
+
namespace :spec do
|
12
|
+
desc "Setup the test environment"
|
13
|
+
task :setup do
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Cleanup the test environment"
|
17
|
+
task :cleanup do
|
18
|
+
File.delete(File.expand_path(File.dirname(__FILE__) + '/../spec/test.db'))
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Test hikari"
|
22
|
+
RSpec::Core::RakeTask.new(:hikari_lib) do |task|
|
23
|
+
hikari_root = File.expand_path(File.dirname(__FILE__) + '/..')
|
24
|
+
task.pattern = hikari_root + '/spec/lib/**/*_spec.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Run the coverage report"
|
28
|
+
RSpec::Core::RakeTask.new(:rcov) do |task|
|
29
|
+
hikari_root = File.expand_path(File.dirname(__FILE__) + '/..')
|
30
|
+
task.pattern = hikari_root + '/spec/lib/**/*_spec.rb'
|
31
|
+
task.rcov=true
|
32
|
+
task.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/}
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hikari
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seth Faxon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 4.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.0
|
97
|
+
description: |-
|
98
|
+
Hikari allows sorting in Rails projects based on fields or scopes.
|
99
|
+
Sorting can be done across models via scopes.
|
100
|
+
email:
|
101
|
+
- seth.faxon@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files:
|
105
|
+
- MIT-LICENSE
|
106
|
+
- README.rdoc
|
107
|
+
files:
|
108
|
+
- ".gitignore"
|
109
|
+
- Gemfile
|
110
|
+
- MIT-LICENSE
|
111
|
+
- README.rdoc
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- hikari.gemspec
|
115
|
+
- lib/hikari.rb
|
116
|
+
- lib/hikari/active_record.rb
|
117
|
+
- lib/hikari/parser.rb
|
118
|
+
- lib/hikari/railtie.rb
|
119
|
+
- lib/hikari/version.rb
|
120
|
+
- lib/hikari/view_helpers/action_view.rb
|
121
|
+
- spec/lib/action_view_spec.rb
|
122
|
+
- spec/lib/parser_spec.rb
|
123
|
+
- spec/lib/post_spec.rb
|
124
|
+
- spec/schema.rb
|
125
|
+
- spec/spec_helper.rb
|
126
|
+
- tasks/spec.rake
|
127
|
+
homepage: https://github.com/sfaxon/hikari
|
128
|
+
licenses: []
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project: hikari
|
146
|
+
rubygems_version: 2.2.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Hikari is a field and scope based sorting helper for Rails.
|
150
|
+
test_files:
|
151
|
+
- spec/lib/action_view_spec.rb
|
152
|
+
- spec/lib/parser_spec.rb
|
153
|
+
- spec/lib/post_spec.rb
|
154
|
+
- spec/schema.rb
|
155
|
+
- spec/spec_helper.rb
|