br_tag_models 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +99 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/br_tag_models.gemspec +87 -0
- data/lib/tag_models.rb +57 -0
- data/lib/tag_models/tag.rb +111 -0
- data/lib/tag_models/tag_info.rb +28 -0
- data/railties/init.rb +12 -0
- data/spec/Rakefile +12 -0
- data/spec/config/database.yml.example +6 -0
- data/spec/db/migrate/.gitignore +0 -0
- data/spec/db/migrate/001_create_tags.rb +20 -0
- data/spec/db/migrate/002_create_tag_info.rb +13 -0
- data/spec/models/tag.rb +4 -0
- data/spec/models/tag_info.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +59 -0
- data/spec/tag_models/tag_info_spec.rb +20 -0
- data/spec/tag_models/tag_spec.rb +106 -0
- metadata +194 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77e33d6b7cf449a60dc374cc33863611c7580758
|
4
|
+
data.tar.gz: 03a05d26aa1ae5a81f6b81a73cb45cd43ba47ff5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 401dc92d727d1b6d5782d3f495289f33f8838502d0770c9c44d0d75ab51c159dc5b0f5e9308903a92c8656d19d79a164e2a58f06eee9d86600fa0dbc75a29b40
|
7
|
+
data.tar.gz: b9fcb7a76db0f0603942cd28ec32dc72d840e14409efcabb3b9ac113e3baffbc19254c2a252f06eebef11678e14c1afd32c2b6b0c82a7790cdba4bc40703bbc1
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem "active_wrapper", "~> 0.4.5"
|
7
|
+
gem "awesome_nested_set", '~> 2.1.6'
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
gem "rdoc", "~> 3.12"
|
14
|
+
gem "bundler", "~> 1.0"
|
15
|
+
gem "jeweler", "~> 1.8.7"
|
16
|
+
gem "simplecov", ">= 0"
|
17
|
+
gem "rspec"
|
18
|
+
gem "activerecord-mysql2-adapter"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
active_wrapper (0.4.6)
|
5
|
+
activerecord (~> 3.0)
|
6
|
+
activemodel (3.2.14)
|
7
|
+
activesupport (= 3.2.14)
|
8
|
+
builder (~> 3.0.0)
|
9
|
+
activerecord (3.2.14)
|
10
|
+
activemodel (= 3.2.14)
|
11
|
+
activesupport (= 3.2.14)
|
12
|
+
arel (~> 3.0.2)
|
13
|
+
tzinfo (~> 0.3.29)
|
14
|
+
activerecord-mysql2-adapter (0.0.3)
|
15
|
+
mysql2
|
16
|
+
activesupport (3.2.14)
|
17
|
+
i18n (~> 0.6, >= 0.6.4)
|
18
|
+
multi_json (~> 1.0)
|
19
|
+
addressable (2.3.5)
|
20
|
+
arel (3.0.2)
|
21
|
+
awesome_nested_set (2.1.6)
|
22
|
+
activerecord (>= 3.0.0)
|
23
|
+
builder (3.0.4)
|
24
|
+
diff-lcs (1.2.4)
|
25
|
+
faraday (0.8.8)
|
26
|
+
multipart-post (~> 1.2.0)
|
27
|
+
git (1.2.6)
|
28
|
+
github_api (0.10.1)
|
29
|
+
addressable
|
30
|
+
faraday (~> 0.8.1)
|
31
|
+
hashie (>= 1.2)
|
32
|
+
multi_json (~> 1.4)
|
33
|
+
nokogiri (~> 1.5.2)
|
34
|
+
oauth2
|
35
|
+
hashie (2.0.5)
|
36
|
+
highline (1.6.19)
|
37
|
+
httpauth (0.2.0)
|
38
|
+
i18n (0.6.5)
|
39
|
+
jeweler (1.8.8)
|
40
|
+
builder
|
41
|
+
bundler (~> 1.0)
|
42
|
+
git (>= 1.2.5)
|
43
|
+
github_api (= 0.10.1)
|
44
|
+
highline (>= 1.6.15)
|
45
|
+
nokogiri (= 1.5.10)
|
46
|
+
rake
|
47
|
+
rdoc
|
48
|
+
json (1.8.0)
|
49
|
+
jwt (0.1.8)
|
50
|
+
multi_json (>= 1.5)
|
51
|
+
multi_json (1.8.2)
|
52
|
+
multi_xml (0.5.5)
|
53
|
+
multipart-post (1.2.0)
|
54
|
+
mysql2 (0.3.13)
|
55
|
+
nokogiri (1.5.10)
|
56
|
+
oauth2 (0.9.2)
|
57
|
+
faraday (~> 0.8)
|
58
|
+
httpauth (~> 0.2)
|
59
|
+
jwt (~> 0.1.4)
|
60
|
+
multi_json (~> 1.0)
|
61
|
+
multi_xml (~> 0.5)
|
62
|
+
rack (~> 1.2)
|
63
|
+
rack (1.5.2)
|
64
|
+
rake (10.1.0)
|
65
|
+
rdoc (3.12.2)
|
66
|
+
json (~> 1.4)
|
67
|
+
rspec (2.14.1)
|
68
|
+
rspec-core (~> 2.14.0)
|
69
|
+
rspec-expectations (~> 2.14.0)
|
70
|
+
rspec-mocks (~> 2.14.0)
|
71
|
+
rspec-core (2.14.4)
|
72
|
+
rspec-expectations (2.14.0)
|
73
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
74
|
+
rspec-mocks (2.14.1)
|
75
|
+
shoulda (3.5.0)
|
76
|
+
shoulda-context (~> 1.0, >= 1.0.1)
|
77
|
+
shoulda-matchers (>= 1.4.1, < 3.0)
|
78
|
+
shoulda-context (1.1.5)
|
79
|
+
shoulda-matchers (2.4.0)
|
80
|
+
activesupport (>= 3.0.0)
|
81
|
+
simplecov (0.7.1)
|
82
|
+
multi_json (~> 1.0)
|
83
|
+
simplecov-html (~> 0.7.1)
|
84
|
+
simplecov-html (0.7.1)
|
85
|
+
tzinfo (0.3.38)
|
86
|
+
|
87
|
+
PLATFORMS
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
active_wrapper (~> 0.4.5)
|
92
|
+
activerecord-mysql2-adapter
|
93
|
+
awesome_nested_set (~> 2.1.6)
|
94
|
+
bundler (~> 1.0)
|
95
|
+
jeweler (~> 1.8.7)
|
96
|
+
rdoc (~> 3.12)
|
97
|
+
rspec
|
98
|
+
shoulda
|
99
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Aaron Wallis
|
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,19 @@
|
|
1
|
+
= br_tag_models
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to br_tag_models
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Aaron Wallis. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "br_tag_models"
|
18
|
+
gem.homepage = "http://github.com/wheels/br_tag_models"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Bleacher Report tag models extension}
|
21
|
+
gem.description = %Q{Bleacher Report tag models extension}
|
22
|
+
gem.email = "awallis@bleacherreport.com"
|
23
|
+
gem.authors = ["Aaron Wallis"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
# require 'simplecov'
|
36
|
+
# Rcov::RcovTask.new do |test|
|
37
|
+
# test.libs << 'test'
|
38
|
+
# test.pattern = 'test/**/test_*.rb'
|
39
|
+
# test.verbose = true
|
40
|
+
# test.rcov_opts << '--exclude "gems/*"'
|
41
|
+
# end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "br_tag_models #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: br_tag_models 0.1.1 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "br_tag_models"
|
9
|
+
s.version = "0.1.1"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.authors = ["Aaron Wallis"]
|
13
|
+
s.date = "2013-10-15"
|
14
|
+
s.description = "Bleacher Report tag models extension"
|
15
|
+
s.email = "awallis@bleacherreport.com"
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"br_tag_models.gemspec",
|
29
|
+
"lib/tag_models.rb",
|
30
|
+
"lib/tag_models/tag.rb",
|
31
|
+
"lib/tag_models/tag_info.rb",
|
32
|
+
"railties/init.rb",
|
33
|
+
"spec/Rakefile",
|
34
|
+
"spec/config/database.yml.example",
|
35
|
+
"spec/db/migrate/.gitignore",
|
36
|
+
"spec/db/migrate/001_create_tags.rb",
|
37
|
+
"spec/db/migrate/002_create_tag_info.rb",
|
38
|
+
"spec/models/tag.rb",
|
39
|
+
"spec/models/tag_info.rb",
|
40
|
+
"spec/spec.opts",
|
41
|
+
"spec/spec_helper.rb",
|
42
|
+
"spec/tag_models/tag_info_spec.rb",
|
43
|
+
"spec/tag_models/tag_spec.rb"
|
44
|
+
]
|
45
|
+
s.homepage = "http://github.com/wheels/br_tag_models"
|
46
|
+
s.licenses = ["MIT"]
|
47
|
+
s.require_paths = ["lib"]
|
48
|
+
s.rubygems_version = "2.1.8"
|
49
|
+
s.summary = "Bleacher Report tag models extension"
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
s.specification_version = 4
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<active_wrapper>, ["~> 0.4.5"])
|
56
|
+
s.add_runtime_dependency(%q<awesome_nested_set>, ["~> 2.1.6"])
|
57
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
59
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
61
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<activerecord-mysql2-adapter>, [">= 0"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<active_wrapper>, ["~> 0.4.5"])
|
66
|
+
s.add_dependency(%q<awesome_nested_set>, ["~> 2.1.6"])
|
67
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
71
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
72
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
73
|
+
s.add_dependency(%q<activerecord-mysql2-adapter>, [">= 0"])
|
74
|
+
end
|
75
|
+
else
|
76
|
+
s.add_dependency(%q<active_wrapper>, ["~> 0.4.5"])
|
77
|
+
s.add_dependency(%q<awesome_nested_set>, ["~> 2.1.6"])
|
78
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
79
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
80
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
81
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
82
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
83
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
84
|
+
s.add_dependency(%q<activerecord-mysql2-adapter>, [">= 0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
data/lib/tag_models.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/tag_models/tag"
|
2
|
+
require File.dirname(__FILE__) + "/tag_models/tag_info"
|
3
|
+
|
4
|
+
module TagModels
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
def tag_info_model(tag_model_name=nil)
|
13
|
+
@tag_model_name = tag_model_name
|
14
|
+
unless included_modules.include?(TagInfo::InstanceMethods)
|
15
|
+
extend TagInfo::ClassMethods
|
16
|
+
include TagInfo::InstanceMethods
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def info_accessor(klass, *attributes)
|
21
|
+
table = klass.table_name
|
22
|
+
klass = klass.to_s
|
23
|
+
unless klass == "TagInfo"
|
24
|
+
class_eval <<-end_eval
|
25
|
+
after_save do |record|
|
26
|
+
record.#{table}.save if record.#{table}
|
27
|
+
end
|
28
|
+
end_eval
|
29
|
+
end
|
30
|
+
attributes.each do |attribute|
|
31
|
+
class_eval <<-end_eval
|
32
|
+
def #{attribute}
|
33
|
+
self.#{table} ||= ::#{klass.to_s}.new
|
34
|
+
self.#{table}.#{attribute}
|
35
|
+
end
|
36
|
+
|
37
|
+
def #{attribute}?
|
38
|
+
self.#{table} ? !self.#{table}.#{attribute}.blank? : false
|
39
|
+
end
|
40
|
+
|
41
|
+
def #{attribute}=(attribute)
|
42
|
+
self.#{table} ||= ::#{klass.to_s}.new
|
43
|
+
self.#{table}.#{attribute} = attribute
|
44
|
+
end
|
45
|
+
end_eval
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def tag_model(tag_info_model_name=nil)
|
50
|
+
@tag_info_model_name = tag_info_model_name
|
51
|
+
unless included_modules.include?(TagModel::InstanceMethods)
|
52
|
+
extend TagModel::ClassMethods
|
53
|
+
include TagModel::InstanceMethods
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module TagModels
|
2
|
+
module TagModel
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def id_from_tag(tag)
|
7
|
+
tag.respond_to?(:id) ? tag.id : tag
|
8
|
+
end
|
9
|
+
|
10
|
+
def migrate_to_nested_set!
|
11
|
+
ActiveRecord::Base.connection.execute(<<-SQL)
|
12
|
+
UPDATE #{self.to_s.tableize}
|
13
|
+
SET type = NULL
|
14
|
+
WHERE type = 'Booster' OR type = 'HighSchool'
|
15
|
+
SQL
|
16
|
+
ActiveRecord::Base.connection.execute(<<-SQL)
|
17
|
+
UPDATE #{self.to_s.tableize}
|
18
|
+
SET type = 'Event'
|
19
|
+
WHERE type = ' Event'
|
20
|
+
SQL
|
21
|
+
ActiveRecord::Base.connection.execute(<<-SQL)
|
22
|
+
UPDATE #{self.to_s.tableize}
|
23
|
+
SET `default` = 1
|
24
|
+
SQL
|
25
|
+
end
|
26
|
+
|
27
|
+
def tree_to_nested_set!(last_tag=nil)
|
28
|
+
Tag.all(:conditions => 'moved = 0 AND in_tag1_id IS NOT NULL').each do |tag|
|
29
|
+
puts "Moving #{tag.name} (#{tag.id})..."
|
30
|
+
parent = Tag.find_by_id(tag.in_tag1_id)
|
31
|
+
next unless parent
|
32
|
+
puts "To child of #{parent.name} (#{parent.id})..."
|
33
|
+
tag.move_to_child_of(parent)
|
34
|
+
tag.update_attribute :moved, true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module InstanceMethods
|
40
|
+
|
41
|
+
def self.included(base)
|
42
|
+
base.class_eval do
|
43
|
+
acts_as_nested_set
|
44
|
+
after_move :after_move_propagate_active
|
45
|
+
after_save :after_save_propagate_active
|
46
|
+
after_save :after_save_propagate_defaults
|
47
|
+
before_create :make_default_if_unique
|
48
|
+
before_save :before_save_store_new_record
|
49
|
+
if @tag_info_model_name
|
50
|
+
has_one :tag_info, :class_name => @tag_info_model_name.to_s.classify, :autosave => true
|
51
|
+
end
|
52
|
+
named_scope :default, lambda {
|
53
|
+
{ :conditions => { :default => true } }
|
54
|
+
}
|
55
|
+
named_scope :similar, lambda { |name|
|
56
|
+
{ :conditions => { :name => name } }
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def similar
|
62
|
+
self.class.similar(self.name).find(:all) - [self]
|
63
|
+
end
|
64
|
+
|
65
|
+
def update_without_propagation(attribute, value)
|
66
|
+
write_attribute("do_not_propagate_#{attribute}", true)
|
67
|
+
self.update_attribute(attribute, value)
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def after_move_propagate_active
|
73
|
+
active = true
|
74
|
+
self.ancestors.each do |ancestor|
|
75
|
+
active = false unless ancestor.active?
|
76
|
+
end
|
77
|
+
self.update_attribute(:active, false) unless active
|
78
|
+
end
|
79
|
+
|
80
|
+
def after_save_propagate_active
|
81
|
+
return if read_attribute(:do_not_propagate_active)
|
82
|
+
if !self.active? && self.active_changed?
|
83
|
+
self.reload.descendants.each do |descendant|
|
84
|
+
descendant.update_without_propagation(:active, self.active)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def after_save_propagate_defaults
|
90
|
+
return if read_attribute(:do_not_propagate_default)
|
91
|
+
if self.default? && (self.default_changed? || @was_new_record)
|
92
|
+
self.similar.each do |category|
|
93
|
+
category.update_without_propagation(:default, false)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def before_save_store_new_record
|
99
|
+
@was_new_record = self.new_record?
|
100
|
+
true
|
101
|
+
end
|
102
|
+
|
103
|
+
def make_default_if_unique
|
104
|
+
if self.similar.size == 0
|
105
|
+
self.default = true
|
106
|
+
end
|
107
|
+
true
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module TagModels
|
2
|
+
module TagInfo
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module InstanceMethods
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.class_eval do
|
11
|
+
if @tag_model_name
|
12
|
+
belongs_to :tag, :class_name => @tag_model_name.to_s.classify
|
13
|
+
end
|
14
|
+
before_save :initialize_behaviors
|
15
|
+
serialize :behaviors
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def initialize_behaviors
|
22
|
+
if read_attribute(:behaviors).nil?
|
23
|
+
self.behaviors = {}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/railties/init.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$:.unshift vendor = "#{File.dirname(__FILE__)}/../vendor"
|
2
|
+
Dir["#{vendor}/*/lib"].each do |path|
|
3
|
+
$:.unshift path
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'awesome_nested_set/rails/init'
|
7
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/tag_models")
|
8
|
+
|
9
|
+
ActiveRecord::Base.send(:include, TagModels)
|
10
|
+
if defined?(RAILS_ENV) && RAILS_ENV == 'development'
|
11
|
+
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'TagModels'
|
12
|
+
end
|
data/spec/Rakefile
ADDED
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class CreateTags < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :tags do |t|
|
4
|
+
t.boolean :active, :default => true
|
5
|
+
t.string :behaviors, :limit => 2000
|
6
|
+
t.boolean :default, :default => false
|
7
|
+
t.integer :lft
|
8
|
+
t.string :name
|
9
|
+
t.integer :parent_id
|
10
|
+
t.string :permalink
|
11
|
+
t.integer :rgt
|
12
|
+
t.integer :tag_id
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :tags
|
19
|
+
end
|
20
|
+
end
|
data/spec/models/tag.rb
ADDED
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
$TESTING=true
|
2
|
+
SPEC = File.dirname(__FILE__)
|
3
|
+
|
4
|
+
$:.unshift SPEC
|
5
|
+
|
6
|
+
require 'pp'
|
7
|
+
require 'rubygems'
|
8
|
+
require 'active_wrapper'
|
9
|
+
|
10
|
+
# For use with rspec textmate bundle
|
11
|
+
def debug(object)
|
12
|
+
puts "<pre>"
|
13
|
+
puts object.pretty_inspect.gsub('<', '<').gsub('>', '>')
|
14
|
+
puts "</pre>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def fixtures
|
18
|
+
data = {
|
19
|
+
:tags => [
|
20
|
+
{ :name => 'Tags' },
|
21
|
+
{ :name => 'NFL' },
|
22
|
+
{ :name => 'Super Bowl XLIII' }
|
23
|
+
]
|
24
|
+
}
|
25
|
+
@fixtures = {}
|
26
|
+
data.each do |key, value|
|
27
|
+
@fixtures[key] = {}
|
28
|
+
value.each do |f|
|
29
|
+
klass = eval(key.to_s.classify)
|
30
|
+
name = f[:name]
|
31
|
+
@fixtures[key][name] = klass.create(f)
|
32
|
+
eval("@#{name.split[0].downcase}_#{key.to_s.singularize} = @fixtures[key][name]")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def migrate_reset
|
38
|
+
orig_stdout = $stdout
|
39
|
+
$stdout = File.new('/dev/null', 'w')
|
40
|
+
$db.migrate_reset
|
41
|
+
$stdout = orig_stdout
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup
|
45
|
+
$db, $log, $mail = ActiveWrapper.setup(
|
46
|
+
:base => File.dirname(__FILE__),
|
47
|
+
:env => 'test'
|
48
|
+
)
|
49
|
+
$db.establish_connection
|
50
|
+
|
51
|
+
require File.expand_path("#{SPEC}/../railties/init")
|
52
|
+
Dir["#{SPEC}/models/*"].each do |model|
|
53
|
+
require model
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
RSpec.configure do |config|
|
58
|
+
setup
|
59
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
describe TagModels::TagInfo do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
migrate_reset
|
7
|
+
fixtures
|
8
|
+
@tag_info = TagInfo.create(:tag_id => 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should belong to tag" do
|
12
|
+
@tag_info.tag.should == @tags_tag
|
13
|
+
end
|
14
|
+
|
15
|
+
context "before save" do
|
16
|
+
it "should initialize behaviors" do
|
17
|
+
@tag_info.behaviors.should == {}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
describe TagModels::TagModel do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
migrate_reset
|
7
|
+
fixtures
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have one tag info record" do
|
11
|
+
@tag_info = TagInfo.create(:tag_id => 1)
|
12
|
+
@tags_tag.tag_info.should == @tag_info
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should act as nested set" do
|
16
|
+
Tag.respond_to?(:acts_as_nested_set_options).should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should retrieve similar tags (tags with the same name)" do
|
20
|
+
clone = @tags_tag.clone
|
21
|
+
clone.save
|
22
|
+
clone.similar.include?(@tags_tag).should == true
|
23
|
+
clone.similar.include?(clone).should == false
|
24
|
+
clone.similar.length.should == 1
|
25
|
+
end
|
26
|
+
|
27
|
+
context "tag info attributes" do
|
28
|
+
|
29
|
+
it "should allow assigning of tag info attribute" do
|
30
|
+
@tags_tag.behaviors = { :test => true }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should save tag info attribute" do
|
34
|
+
@tags_tag.behaviors = { :test => true }
|
35
|
+
@tags_tag.save
|
36
|
+
@tags_tag.tag_info.id.should_not == nil
|
37
|
+
@tags_tag.tag_info.behaviors.should == { :test => true }
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should access tag info attribute" do
|
41
|
+
@tags_tag.behaviors = { :test => true }
|
42
|
+
@tags_tag.save
|
43
|
+
@tags_tag.reload.behaviors.should == { :test => true }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "after move" do
|
48
|
+
it "should change active to false if parent is not active" do
|
49
|
+
@tags_tag.update_attribute(:active, false)
|
50
|
+
|
51
|
+
@nfl_tag.active.should == true
|
52
|
+
@super_tag.active.should == true
|
53
|
+
|
54
|
+
@nfl_tag.move_to_child_of(@tags_tag)
|
55
|
+
@super_tag.move_to_child_of(@nfl_tag)
|
56
|
+
|
57
|
+
@nfl_tag.active.should == false
|
58
|
+
@super_tag.active.should == false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "after save" do
|
63
|
+
it "should make similar tags non-default if category changes to default" do
|
64
|
+
@tags_tag.update_attribute(:default, true)
|
65
|
+
|
66
|
+
@tags_tag2 = @tags_tag.clone
|
67
|
+
@tags_tag2.default = false
|
68
|
+
@tags_tag2.save
|
69
|
+
@tags_tag2.update_attribute(:default, true)
|
70
|
+
|
71
|
+
@tags_tag.reload.default.should == false
|
72
|
+
@tags_tag2.reload.default.should == true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should make similar tags non-default if category is cloned" do
|
76
|
+
@tags_tag.update_attribute(:default, true)
|
77
|
+
|
78
|
+
@tags_tag2 = @tags_tag.clone
|
79
|
+
@tags_tag2.save
|
80
|
+
|
81
|
+
@tags_tag.reload.default.should == false
|
82
|
+
@tags_tag2.reload.default.should == true
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should propagate the active column to all children if it is saved as false" do
|
86
|
+
@tags_tag.update_attribute(:active, true)
|
87
|
+
@nfl_tag.move_to_child_of(@tags_tag)
|
88
|
+
@super_tag.move_to_child_of(@nfl_tag)
|
89
|
+
|
90
|
+
@nfl_tag.active.should == true
|
91
|
+
@super_tag.active.should == true
|
92
|
+
|
93
|
+
@tags_tag.update_attribute(:active, false)
|
94
|
+
|
95
|
+
@nfl_tag.reload.active.should == false
|
96
|
+
@super_tag.reload.active.should == false
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "before create" do
|
101
|
+
it "should make the record default if it is unique" do
|
102
|
+
Tag.create(:name => 'Tags').default.should == false
|
103
|
+
Tag.create(:name => 'Unique').default.should == true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: br_tag_models
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Wallis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: active_wrapper
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: awesome_nested_set
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shoulda
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: jeweler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.7
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.8.7
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !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'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activerecord-mysql2-adapter
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Bleacher Report tag models extension
|
140
|
+
email: awallis@bleacherreport.com
|
141
|
+
executables: []
|
142
|
+
extensions: []
|
143
|
+
extra_rdoc_files:
|
144
|
+
- LICENSE.txt
|
145
|
+
- README.rdoc
|
146
|
+
files:
|
147
|
+
- .document
|
148
|
+
- Gemfile
|
149
|
+
- Gemfile.lock
|
150
|
+
- LICENSE.txt
|
151
|
+
- README.rdoc
|
152
|
+
- Rakefile
|
153
|
+
- VERSION
|
154
|
+
- br_tag_models.gemspec
|
155
|
+
- lib/tag_models.rb
|
156
|
+
- lib/tag_models/tag.rb
|
157
|
+
- lib/tag_models/tag_info.rb
|
158
|
+
- railties/init.rb
|
159
|
+
- spec/Rakefile
|
160
|
+
- spec/config/database.yml.example
|
161
|
+
- spec/db/migrate/.gitignore
|
162
|
+
- spec/db/migrate/001_create_tags.rb
|
163
|
+
- spec/db/migrate/002_create_tag_info.rb
|
164
|
+
- spec/models/tag.rb
|
165
|
+
- spec/models/tag_info.rb
|
166
|
+
- spec/spec.opts
|
167
|
+
- spec/spec_helper.rb
|
168
|
+
- spec/tag_models/tag_info_spec.rb
|
169
|
+
- spec/tag_models/tag_spec.rb
|
170
|
+
homepage: http://github.com/wheels/br_tag_models
|
171
|
+
licenses:
|
172
|
+
- MIT
|
173
|
+
metadata: {}
|
174
|
+
post_install_message:
|
175
|
+
rdoc_options: []
|
176
|
+
require_paths:
|
177
|
+
- lib
|
178
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ! '>='
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
requirements: []
|
189
|
+
rubyforge_project:
|
190
|
+
rubygems_version: 2.1.8
|
191
|
+
signing_key:
|
192
|
+
specification_version: 4
|
193
|
+
summary: Bleacher Report tag models extension
|
194
|
+
test_files: []
|