taxonomy_rails 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2bea2dc4e0ced3d3f71714290d87103064049550
4
+ data.tar.gz: 1e1620ddb9018f80e007fa30e1c8adcbe8568c76
5
+ SHA512:
6
+ metadata.gz: 5b9309e6e78ba467fa101fa29de622d8e5e11ec8459b14660e4c32f4d53f67a6cfa2e7716cc2ae51fb8632bd044d1a9e9ebaf6e7e4c095d2e3f7f0a3cd2fda2d
7
+ data.tar.gz: 339753c45aeaf92543cac9a557c565893172b992e988d22f6d85bd05eb6cc20a8a48d7c352709aeb7b012bdebaefa6b364189e3be588c66b89bbcf3d6384a241
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Orgânica Digital
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,9 @@
1
+ # taxonomy_rails
2
+
3
+ ## Introduction
4
+
5
+ A simple taxonomy hierarchy for use in Rails projects.
6
+
7
+ ## License
8
+
9
+ MIT License. Copyright 2015 Orgânica Digital.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ APP_RAKEFILE = File.expand_path("../spec/test_app/Rakefile", __FILE__)
8
+
9
+ load 'rails/tasks/engine.rake'
10
+ load 'rails/tasks/statistics.rake'
11
+
12
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,10 @@
1
+ class Classification < ActiveRecord::Base
2
+
3
+ belongs_to :taxon, inverse_of: :classifications
4
+ belongs_to :classifiable, polymorphic: true, inverse_of: :classification
5
+
6
+ validates :taxon_id, presence: true
7
+ validates :classifiable_id, presence: true
8
+ validates :classifiable_type, presence: true
9
+
10
+ end
@@ -0,0 +1,18 @@
1
+ require 'ancestry'
2
+ require 'friendly_id'
3
+
4
+ class Taxon < ActiveRecord::Base
5
+
6
+ extend FriendlyId
7
+
8
+ belongs_to :taxonomy, inverse_of: :taxons, touch: true
9
+ has_many :classifications, inverse_of: :taxonomy, dependent: :destroy
10
+
11
+ validates :name, presence: true
12
+ validates :taxonomy_id, presence: true
13
+
14
+ has_ancestry touch: true
15
+
16
+ friendly_id :name, use: :slugged
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ class Taxonomy < ActiveRecord::Base
2
+
3
+ has_many :taxons, inverse_of: :taxonomy, dependent: :destroy
4
+
5
+ validates :name, presence: true
6
+
7
+ end
@@ -0,0 +1,9 @@
1
+ class CreateTaxonomies < ActiveRecord::Migration
2
+ def change
3
+ create_table :taxonomies do |t|
4
+ t.string :name
5
+
6
+ t.timestamps null: false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateTaxons < ActiveRecord::Migration
2
+ def change
3
+ create_table :taxons do |t|
4
+ t.references :taxonomy, index: true
5
+ t.string :name, null: false
6
+
7
+ t.timestamps null: false
8
+ end
9
+ add_foreign_key :taxons, :taxonomies
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class AddAncestryToTaxon < ActiveRecord::Migration
2
+ def change
3
+ add_column :taxons, :ancestry, :string
4
+ add_index :taxons, :ancestry
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ class ChangeTaxonTaxonomyIdColumn < ActiveRecord::Migration
2
+ def up
3
+ change_column :taxons, :taxonomy_id, :integer, null: false
4
+ end
5
+
6
+ def down
7
+ change_column :taxons, :taxonomy_id, :integer, null: true
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ class CreateClassifications < ActiveRecord::Migration
2
+ def change
3
+ create_table :classifications do |t|
4
+ t.references :taxon, index: true, null: false
5
+ t.references :classifiable, polymorphic: true, index: true, null: false
6
+
7
+ t.timestamps null: false
8
+ end
9
+ add_foreign_key :classifications, :taxons
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ class AddSlugToTaxon < ActiveRecord::Migration
2
+ def up
3
+ transaction do
4
+ add_column :taxons, :slug, :string
5
+
6
+ Taxon.all.each do |taxon|
7
+ taxon.save!
8
+ end
9
+
10
+ change_column :taxons, :slug, :string, null: false
11
+ add_index :taxons, :slug, unique: true
12
+ end
13
+ end
14
+
15
+ def down
16
+ remove_index :taxons, :slug
17
+ remove_column :taxons, :slug
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ class TaxonomyRailsGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../../templates', __FILE__)
3
+
4
+ namespace 'taxonomy_rails'
5
+
6
+ def install
7
+ rake 'taxonomy_rails:install:migrations'
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module TaxonomyRails
2
+ class Engine < ::Rails::Engine
3
+ engine_name :taxonomy_rails
4
+
5
+ config.generators do |g|
6
+ g.test_framework false
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module TaxonomyRails
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'taxonomy_rails/engine'
2
+
3
+ module TaxonomyRails
4
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taxonomy_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Orgânica Digital
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.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.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: ancestry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
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.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: friendly_id
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 5.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 5.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.3.17
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.3.17
69
+ description: A simple taxonomy hierarchy for use in Rails projects.
70
+ email:
71
+ - contato@organicadigital.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.md
78
+ - Rakefile
79
+ - app/models/classification.rb
80
+ - app/models/taxon.rb
81
+ - app/models/taxonomy.rb
82
+ - db/migrate/20150205120330_create_taxonomies.rb
83
+ - db/migrate/20150205123059_create_taxons.rb
84
+ - db/migrate/20150205134223_add_ancestry_to_taxon.rb
85
+ - db/migrate/20150205160048_change_taxon_taxonomy_id_column.rb
86
+ - db/migrate/20150205160750_create_classifications.rb
87
+ - db/migrate/20150205164502_add_slug_to_taxon.rb
88
+ - lib/generators/taxonomy_rails/taxonomy_rails_generator.rb
89
+ - lib/taxonomy_rails.rb
90
+ - lib/taxonomy_rails/engine.rb
91
+ - lib/taxonomy_rails/version.rb
92
+ homepage: https://github.com/organicadigital/taxonomy_rails
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.5
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A simple taxonomy hierarchy for use in Rails projects.
116
+ test_files: []