succession 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +29 -0
- data/app/controllers/succession/entities_controller.rb +15 -0
- data/app/models/succession/entity.rb +18 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20130809120528_create_succession_entities.rb +11 -0
- data/lib/succession/engine.rb +5 -0
- data/lib/succession/url_helper.rb +47 -0
- data/lib/succession/version.rb +3 -0
- data/lib/succession.rb +47 -0
- data/lib/tasks/succession_tasks.rake +4 -0
- metadata +154 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Succession
|
2
|
+
|
3
|
+
Manage the Rails object succession easily.
|
4
|
+
|
5
|
+
|
6
|
+
You have to privide a user manage succession for a Rails object, you can simply
|
7
|
+
add this gem.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add to your Gemfile:
|
12
|
+
|
13
|
+
gem succession
|
14
|
+
|
15
|
+
and run the bundle install command.
|
16
|
+
After the installation type into your terminal:
|
17
|
+
|
18
|
+
rake succession:install:migrations
|
19
|
+
|
20
|
+
to execute the gem's migrations.
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Model
|
25
|
+
|
26
|
+
To add the succession behavior, put this code into your model.
|
27
|
+
|
28
|
+
class Post < ActiveRecord::Base
|
29
|
+
include Succession
|
30
|
+
|
31
|
+
# Your code.
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
### View
|
36
|
+
|
37
|
+
There are two ways to implement the up and down rating into your view.
|
38
|
+
|
39
|
+
#### 1. up_link_to, down_link_to
|
40
|
+
|
41
|
+
If you want to use links add this into your view files:
|
42
|
+
|
43
|
+
For up rating:
|
44
|
+
|
45
|
+
<%= up_link_to "rate up", @post%>
|
46
|
+
|
47
|
+
For down rating:
|
48
|
+
|
49
|
+
<%= down_link_to "rate up", @post%>
|
50
|
+
|
51
|
+
#### 1. up_link_to, down_link_to
|
52
|
+
|
53
|
+
If you are more the button type, use this:
|
54
|
+
|
55
|
+
For up rating:
|
56
|
+
|
57
|
+
<%= up_button_to "rate up", @post%>
|
58
|
+
|
59
|
+
For down rating:
|
60
|
+
|
61
|
+
<%= down_button_to "rate up", @post%>
|
62
|
+
|
63
|
+
## Copyright
|
64
|
+
|
65
|
+
Copyright (c) 2013 Fadendaten GmbH. See MIT-LICENSE for details.
|
66
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Succession'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Succession
|
2
|
+
class EntitiesController < ActionController::Base
|
3
|
+
def up
|
4
|
+
entity = Succession::Entity.find(params[:id])
|
5
|
+
entity.up
|
6
|
+
redirect_to :back
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
entity = Succession::Entity.find(params[:id])
|
11
|
+
entity.down
|
12
|
+
redirect_to :back
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Succession
|
2
|
+
class Entity < ActiveRecord::Base
|
3
|
+
belongs_to :parent, polymorphic: true
|
4
|
+
|
5
|
+
attr_accessible :parent_id, :parent_type, :rank
|
6
|
+
|
7
|
+
def up
|
8
|
+
self.rank += 1
|
9
|
+
self.save
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def down
|
14
|
+
self.rank -= 1
|
15
|
+
self.save
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module ActionView::Helpers::UrlHelper
|
2
|
+
|
3
|
+
def up_button_to(name = nil, options = {}, html_options = {}, &block)
|
4
|
+
if options.respond_to?(:succession_entity)
|
5
|
+
options = succession_entity_up_path(entity(options))
|
6
|
+
end
|
7
|
+
button_to(name,options,html_options,&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def down_button_to(name = nil, options = {}, html_options = {}, &block)
|
12
|
+
if options.respond_to?(:succession_entity)
|
13
|
+
options = succession_entity_down_path(entity(options))
|
14
|
+
end
|
15
|
+
button_to(name,options,html_options,&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def up_link_to(name = nil, options = {}, html_options = {}, &block)
|
19
|
+
if options.respond_to?(:succession_entity)
|
20
|
+
options = succession_entity_up_path(entity(options))
|
21
|
+
end
|
22
|
+
link_to(name,options,html_options,&block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def down_link_to(name = nil, options = {}, html_options = {}, &block)
|
26
|
+
if options.respond_to?(:succession_entity)
|
27
|
+
options = succession_entity_down_path(entity(options))
|
28
|
+
end
|
29
|
+
link_to(name,options,html_options,&block)
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def entity(options)
|
36
|
+
entity = options.succession_entity
|
37
|
+
end
|
38
|
+
|
39
|
+
def succession_entity_up_path(entity)
|
40
|
+
"succession_entity/#{entity.id}/up"
|
41
|
+
end
|
42
|
+
|
43
|
+
def succession_entity_down_path(entity)
|
44
|
+
"succession_entity/#{entity.id}/down"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/succession.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "succession/engine"
|
2
|
+
require "succession/url_helper"
|
3
|
+
|
4
|
+
|
5
|
+
module Succession
|
6
|
+
def self.included(base)
|
7
|
+
base.has_one :succession_entity,
|
8
|
+
class_name: "Succession::Entity",
|
9
|
+
as: :parent,
|
10
|
+
dependent: :destroy
|
11
|
+
base.after_create :create_succession_entity
|
12
|
+
end
|
13
|
+
|
14
|
+
def rank
|
15
|
+
Succession::Entity.where(parent_id: self.id,
|
16
|
+
parent_type: self.class.to_s).first.rank
|
17
|
+
end
|
18
|
+
|
19
|
+
def rank= rank
|
20
|
+
enity = Succession::Entity.where(parent_id: self.id,
|
21
|
+
parent_type: self.class.to_s).first
|
22
|
+
enity.rank = rank
|
23
|
+
enity.save
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create_succession_entity
|
29
|
+
Succession::Entity.create!(parent_id: self.id,
|
30
|
+
parent_type: self.class.to_s,
|
31
|
+
rank: highest_succession_rank)
|
32
|
+
end
|
33
|
+
|
34
|
+
def all_succession_entities
|
35
|
+
Succession::Entity.where(:parent_type == self.class.to_s)
|
36
|
+
end
|
37
|
+
|
38
|
+
def last_sueccession_entity
|
39
|
+
all_succession_entities.order(:rank).last
|
40
|
+
end
|
41
|
+
|
42
|
+
def highest_succession_rank
|
43
|
+
return last_sueccession_entity.rank + 1 unless last_sueccession_entity.nil?
|
44
|
+
return 0
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: succession
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Felix Langenegger
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.14
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.14
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jquery-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: sqlite3
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rspec-rails
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: simplecov
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: capybara
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 2.1.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 2.1.0
|
110
|
+
description: ! "The Succession gem provides a easy to use ActiveRecord\n extension
|
111
|
+
to manage a specific succession."
|
112
|
+
email:
|
113
|
+
- felix.langenegger@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- app/controllers/succession/entities_controller.rb
|
119
|
+
- app/models/succession/entity.rb
|
120
|
+
- config/routes.rb
|
121
|
+
- db/migrate/20130809120528_create_succession_entities.rb
|
122
|
+
- lib/succession/engine.rb
|
123
|
+
- lib/succession/url_helper.rb
|
124
|
+
- lib/succession/version.rb
|
125
|
+
- lib/succession.rb
|
126
|
+
- lib/tasks/succession_tasks.rake
|
127
|
+
- MIT-LICENSE
|
128
|
+
- Rakefile
|
129
|
+
- README.md
|
130
|
+
homepage: http://fadendaten.ch
|
131
|
+
licenses: []
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.8.25
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: Rails Plugin to provide a user managed succession.
|
154
|
+
test_files: []
|