gutentag-multitenancy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 189f617a953d1d1ceaacd4bc7de82b3e8d54cd71
4
- data.tar.gz: b51023d31ed942fdc6c611e35be263ce5fcb50e0
3
+ metadata.gz: 4a7eea8660402646a7d4b0f18eb09e905e53be2d
4
+ data.tar.gz: 3280af671b3436e8a0da4aa2ac32f15265343ba4
5
5
  SHA512:
6
- metadata.gz: e0f8260ef48289d684a9411f20efd0e9d80a82cdd50264e745de80f4b481f390f0736768d93b41baf64f732a82537614b441ff9ad83c893583b7e701464b306a
7
- data.tar.gz: 84fa5812352a81daf6b877e7c0c760682eebb845907349d5f9629200e1bc70f9348fe5708c87900b23667c364f930f2461df7f2c4fa0fd9f4082a028a7d6263a
6
+ metadata.gz: bce357c5d2ab86e9057c1ff75557728bafa323e8fd838959ac38888871423e9e47b9a628506a7ae02695edea136aadd422588cfa1f300f1b2c396bb1b549d714
7
+ data.tar.gz: a314d7fa1b73ffdd14a5d8796d65e6ba0758ea35acce263b0d79d75d9e4e8f7e8f106ca794a273e295c287f22bb9f1b9c0b883395d913d2fae67688f14241140
data/README.md CHANGED
@@ -13,28 +13,18 @@ If you haven't installed Gutentag yet, [install](https://github.com/pat/gutentag
13
13
  gem 'gutentag', github: 'pat/gutentag', ref: '51bd8f2f37f21dc4ef84a87889db4f28aa3573e2'
14
14
  ```
15
15
 
16
- Now run the following migration (TODO: make a generator for this!):
17
-
18
- ```ruby
19
- add_column :gutentag_tags, :tenant_id, :integer, null: false
20
-
21
- remove_index :gutentag_tags, :name
22
- add_index :gutentag_tags, [:name, :tenant_id], unique: true
23
- ```
24
-
25
- Add this line to your application's Gemfile:
16
+ Add `gutentag_multitenancy` to your Gemfile, and `bundle install`:
26
17
 
27
18
  ```ruby
28
19
  gem 'gutentag-multitenancy'
29
20
  ```
30
21
 
31
- And then execute:
32
-
33
- $ bundle
22
+ Now import and run the migration:
34
23
 
35
- Or install it yourself as:
36
-
37
- $ gem install gutentag-multitenancy
24
+ ```
25
+ rake gutentag_multitenancy:install:migrations
26
+ rake db:migrate
27
+ ```
38
28
 
39
29
 
40
30
  ## Usage
@@ -59,6 +49,10 @@ To retrieve all the tags for a tenant, use the `by_tenant_id` scope:
59
49
  Gutentag::Tag.by_tenant_id 42
60
50
  ```
61
51
 
52
+ ## To Do
53
+
54
+ - Tests.
55
+
62
56
 
63
57
  ## License
64
58
 
@@ -0,0 +1,15 @@
1
+ class AlterTags < ActiveRecord::Migration
2
+ def up
3
+ add_column :gutentag_tags, :tenant_id, :integer, null: false
4
+
5
+ remove_index :gutentag_tags, :name
6
+ add_index :gutentag_tags, [:name, :tenant_id], unique: true
7
+ end
8
+
9
+ def down
10
+ remove_index :gutentag_tags, [:name, :tenant_id]
11
+ add_index :gutentag_tags, :name, unique: true
12
+
13
+ remove_column :gutentag_tags, :tenant_id
14
+ end
15
+ end
@@ -8,4 +8,8 @@ require "gutentag/multitenancy/version"
8
8
  require "gutentag/multitenancy/tenant_tagger"
9
9
  require "gutentag/multitenancy/taggable"
10
10
  require "gutentag/multitenancy/engine"
11
+ require "gutentag/multitenancy/tag_extensions"
12
+ require "#{Gutentag::Engine.root}/app/models/gutentag/tag.rb"
13
+
14
+ Gutentag::Tag.send :include, Gutentag::Multitenancy::TagExtensions
11
15
 
@@ -1,5 +1,3 @@
1
- require "#{Gutentag::Engine.root}/app/models/gutentag/tag.rb"
2
-
3
1
  module Gutentag
4
2
  module Multitenancy
5
3
 
@@ -7,20 +5,6 @@ module Gutentag
7
5
  engine_name :gutentag_multitenancy
8
6
 
9
7
  ActiveSupport.on_load :active_record do
10
- Gutentag::Tag.class_eval do
11
- attr_accessible :tenant_id if ::ActiveRecord::VERSION::MAJOR == 3
12
-
13
- scope :by_tenant_id, ->(tenant_id) { where tenant_id: tenant_id }
14
-
15
- def self.find_by_name_and_tenant_id(name, tenant_id)
16
- where(tenant_id: tenant_id).find_by_name(name)
17
- end
18
-
19
- def self.find_or_create_by_name_and_tenant_id(name, tenant_id)
20
- find_by_name_and_tenant_id(name, tenant_id) || create(name: name, tenant_id: tenant_id)
21
- end
22
- end
23
-
24
8
  include Taggable
25
9
  end
26
10
  end
@@ -0,0 +1,26 @@
1
+ module Gutentag
2
+ module Multitenancy
3
+ module TagExtensions
4
+
5
+ def self.included(base)
6
+ base.attr_accessible :tenant_id if ::ActiveRecord::VERSION::MAJOR == 3
7
+
8
+ base.class_eval do
9
+ scope :by_tenant_id, ->(tenant_id) { where tenant_id: tenant_id }
10
+ end
11
+
12
+ base.extend ClassMethods
13
+ end
14
+
15
+ module ClassMethods
16
+ def find_by_name_and_tenant_id(name, tenant_id)
17
+ where(tenant_id: tenant_id).find_by_name(name)
18
+ end
19
+
20
+ def find_or_create_by_name_and_tenant_id(name, tenant_id)
21
+ find_by_name_and_tenant_id(name, tenant_id) || create(name: name, tenant_id: tenant_id)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  module Gutentag
2
2
  module Multitenancy
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gutentag-multitenancy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Stewart
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,9 +78,11 @@ files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
+ - db/migrate/1_alter_tags.rb
81
82
  - gutentag-multitenancy.gemspec
82
83
  - lib/gutentag/multitenancy.rb
83
84
  - lib/gutentag/multitenancy/engine.rb
85
+ - lib/gutentag/multitenancy/tag_extensions.rb
84
86
  - lib/gutentag/multitenancy/taggable.rb
85
87
  - lib/gutentag/multitenancy/tenant_tagger.rb
86
88
  - lib/gutentag/multitenancy/version.rb