has-many-with-set 1.1.0 → 1.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b1ed22920558c4bdd4b9254c7da6f730939d2ce
4
+ data.tar.gz: 08e49dffaca90769eaaab09aba831b7916ccd76e
5
+ SHA512:
6
+ metadata.gz: fa351c04866a417c8404b3fa87e894953398c8ad3795f14e14b1c646c7f19a3cfad2bc6e7fb380f2c30e5e2f2ba1e2dc3e3a51fe1fef994fa6d2431dccd760f0
7
+ data.tar.gz: d7c752071400ce7920552af6e971ea9344a7a99b309cf9095917bea826bd4aae72c682d84223acbf39744b0d76c7b470fed716f2941f0e159f6d11d76ce5b2f2
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ has-many-with-set 1.2.0
2
+
3
+ - Updated gemspec so the gem works with Rails 4.*.
4
+ - The README examples don't use attr_accessible.
5
+ - The README example now includes the code to create Article and Tag. No assumptions made.
6
+ - Fixed the tests so they run on Rails 4.0.
7
+
1
8
  has-many-with-set 1.1.0
2
9
 
3
10
  - Children can now see their parents.
@@ -4,6 +4,8 @@ h3. A smarter way of doing many-to-many relationships in Ruby On Rails.
4
4
 
5
5
  h2. Introduction
6
6
 
7
+ *Update: Now works with Rails 4*
8
+
7
9
  Rails has two ways to model many-to-many relationships: *_has_and_belongs_to_many_* and *_has_many :through_*, this gem introduces a third one: *_has_many_with_set_*.
8
10
 
9
11
  *_has_many_with_set_* is equivalent to *_has_and_belongs_to_many_* in functionality. It works only when you do not want information about a relationship but the relationship itself, behind the curtains though, they do not work anything alike, *_has_many_with_set_* is far more efficient in terms of data size as it reduces the redundancy that occurs in a normal many-to-many relationship when the cardinality is low, that is, the same combination occurs many times. For example, in a blog application, when many posts share the same tags.
@@ -74,12 +76,14 @@ h2. Example
74
76
 
75
77
  Using our previous example:
76
78
 
79
+ bc. rails g model Article title:string body:text
80
+
81
+ bc. rails g model Tag name:string
82
+
77
83
  bc. rails g has_many_with_set:migration Article Tag
78
84
  create db/migrate/20121106063326_create_articles_tags_set.rb
79
85
 
80
86
  bc.. class Article < ActiveRecord::Base
81
- attr_accessible :body, :title
82
-
83
87
  has_many_with_set :tags # <--- key part!
84
88
  end
85
89
 
@@ -116,7 +120,7 @@ Article.last.tags
116
120
  Tag.first.articles.size
117
121
  => 503
118
122
 
119
- Tag.first.article.first
123
+ Tag.first.articles.first
120
124
  => #<Article id: 2, title: "Buzzword about buzzwords!", ..>
121
125
 
122
126
  p. Same example as before, just now using *_has_many_with_set_*. We get the impressive number of 80 rows to represent the same information that we had before with thousands of rows (roughly the same, since we use random combinations is not _exactly_ the same article/tag layout).
@@ -1,3 +1,3 @@
1
1
  module HasManyWithSet
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -18,12 +18,17 @@ class MigrationGeneratorTest < Rails::Generators::TestCase
18
18
  end
19
19
  end
20
20
 
21
- # Migration test has to run first, I do not like that but is the only way to actually
22
- # test the whole thing.
23
- PrepareActiveRecord.prepare_default_schema
24
- PrepareActiveRecord.run_migration(MIGRATION_FILE, MIGRATION_PATH)
25
-
26
21
  class HasManyWithSetTest < ActiveSupport::TestCase
22
+ def setup
23
+ unless @initialized
24
+ # Migration test has to run first, I do not like that but is the only way to actually
25
+ # test the whole thing.
26
+ PrepareActiveRecord.prepare_default_schema
27
+ PrepareActiveRecord.run_migration(MIGRATION_FILE, MIGRATION_PATH)
28
+ @initialized = true
29
+ end
30
+ end
31
+
27
32
  test "parent class has the getter" do
28
33
  assert_respond_to ModelOne.new, "model_twos"
29
34
  end
@@ -2,6 +2,5 @@ class ModelTwo < ActiveRecord::Base
2
2
  end
3
3
 
4
4
  class ModelOne < ActiveRecord::Base
5
- attr_accessible :num
6
5
  has_many_with_set :model_two
7
6
  end
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has-many-with-set
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Francisco Soto
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-11-24 00:00:00.000000000 Z
11
+ date: 2013-08-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
- version: 3.2.8
19
+ version: '4.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
- version: 3.2.8
26
+ version: '4.0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: sqlite3
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: A smarter way of doing many-to-many relationships in Rails.
@@ -67,40 +62,33 @@ files:
67
62
  - test/support/models.rb
68
63
  - test/support/prepare_activerecord.rb
69
64
  - test/test_helper.rb
70
- - test/tmp/db/migrate/20121124222345_create_model_ones_model_twos_set.rb
65
+ - test/tmp/db/migrate/20130804213649_create_model_ones_model_twos_set.rb
71
66
  homepage: https://github.com/ebobby/has-many-with-set
72
67
  licenses: []
68
+ metadata: {}
73
69
  post_install_message:
74
70
  rdoc_options: []
75
71
  require_paths:
76
72
  - lib
77
73
  required_ruby_version: !ruby/object:Gem::Requirement
78
- none: false
79
74
  requirements:
80
- - - ! '>='
75
+ - - '>='
81
76
  - !ruby/object:Gem::Version
82
77
  version: '0'
83
- segments:
84
- - 0
85
- hash: 3966952451817173381
86
78
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
79
  requirements:
89
- - - ! '>='
80
+ - - '>='
90
81
  - !ruby/object:Gem::Version
91
82
  version: '0'
92
- segments:
93
- - 0
94
- hash: 3966952451817173381
95
83
  requirements: []
96
84
  rubyforge_project:
97
- rubygems_version: 1.8.24
85
+ rubygems_version: 2.0.2
98
86
  signing_key:
99
- specification_version: 3
87
+ specification_version: 4
100
88
  summary: A smarter way of doing many-to-many relationships in Rails.
101
89
  test_files:
102
90
  - test/has-many-with-set_test.rb
103
91
  - test/support/models.rb
104
92
  - test/support/prepare_activerecord.rb
105
93
  - test/test_helper.rb
106
- - test/tmp/db/migrate/20121124222345_create_model_ones_model_twos_set.rb
94
+ - test/tmp/db/migrate/20130804213649_create_model_ones_model_twos_set.rb