mappd 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -1
- data/lib/mappd/mappd.rb +1 -1
- data/lib/mappd/version.rb +1 -1
- data/spec/mappd_spec.rb +5 -0
- data/spec/models.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 311e0d6f33577daccff7700c6dfe76d5916d4e097a5ec75a96702470a9343796
|
4
|
+
data.tar.gz: 7be0bacb4267d823ae1a8849459ac549f1fc5e7ccf2cfc564663af53fb31f4bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0be5ee80c7200f3f30547dd1da1bcca24a801f6f720788be476ace98224c68fea00b40edf7a02b4b63fe252b076b3f264d03b9a60d31b2f8b7d1fad25e96b703
|
7
|
+
data.tar.gz: 94b10fcd3e7c8a059d756372179c9350bb0f14e4d0c16f19395f9e5807424c6e2902e465e809a92b89e8f908d558762f4742ffddc7ef4fb2e0285016ab2ed7a8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# README
|
2
2
|
|
3
|
-
Mappd is a replacement gem for [mini_record](https://github.com/DAddYE/mini_record). Mini record is great and I have been using it for a number of years. Unfortunately the mini_record
|
3
|
+
Mappd is a replacement gem for [mini_record](https://github.com/DAddYE/mini_record). Mini record is great and I have been using it for a number of years. Unfortunately the mini_record repo has not been updated in some time. With recent rails upgrades mini_record is not working well.
|
4
4
|
|
5
5
|
Mappd is designed to work with ActiveRecord 5.2 >.
|
6
6
|
|
@@ -21,6 +21,8 @@ class Person < ActiveRecord::Base
|
|
21
21
|
# Hooks into belongs_to and creates a country_id column
|
22
22
|
# with an index
|
23
23
|
belongs_to :country
|
24
|
+
|
25
|
+
has_many :pictures, as: :imageable
|
24
26
|
|
25
27
|
# Creates a join table people_roles
|
26
28
|
has_and_belongs_to_many :roles
|
@@ -32,8 +34,14 @@ class Person < ActiveRecord::Base
|
|
32
34
|
timestamps
|
33
35
|
end
|
34
36
|
|
37
|
+
class Picture < ActiveRecord::Base
|
38
|
+
# Creates a imageable_id and imageable_type
|
39
|
+
belongs_to :imageable, polymorphic: true
|
40
|
+
end
|
41
|
+
|
35
42
|
class Country < ActiveRecord::Base
|
36
43
|
field :name, :string
|
44
|
+
has_many :pictures, as: :imageable
|
37
45
|
end
|
38
46
|
|
39
47
|
class Role < ActiveRecord::Base
|
data/lib/mappd/mappd.rb
CHANGED
@@ -24,7 +24,7 @@ module Mappd
|
|
24
24
|
reflect_on_all_associations.each do |association|
|
25
25
|
case association.macro
|
26
26
|
when :belongs_to
|
27
|
-
commands << [:add_reference, [table_name, association.name,
|
27
|
+
commands << [:add_reference, [table_name, association.name, association.options]]
|
28
28
|
when :has_and_belongs_to_many
|
29
29
|
commands << [:create_join_table,
|
30
30
|
[table_name.to_sym, association.name]]
|
data/lib/mappd/version.rb
CHANGED
data/spec/mappd_spec.rb
CHANGED
@@ -37,3 +37,8 @@ RSpec.describe Person, type: :model do
|
|
37
37
|
it { should have_db_column(:age).of_type(:string) }
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
RSpec.describe Picture, type: :model do
|
42
|
+
it { should have_db_column(:imageable_id).of_type(:integer) }
|
43
|
+
it { should have_db_column(:imageable_type).of_type(:string) }
|
44
|
+
end
|
data/spec/models.rb
CHANGED
@@ -10,6 +10,7 @@ class Person < ActiveRecord::Base
|
|
10
10
|
field :e_id, :string, length: 10
|
11
11
|
|
12
12
|
belongs_to :country
|
13
|
+
has_many :pictures, as: :imageable
|
13
14
|
has_and_belongs_to_many :roles
|
14
15
|
|
15
16
|
index :e_id
|
@@ -17,8 +18,13 @@ class Person < ActiveRecord::Base
|
|
17
18
|
timestamps
|
18
19
|
end
|
19
20
|
|
21
|
+
class Picture < ActiveRecord::Base
|
22
|
+
belongs_to :imageable, polymorphic: true
|
23
|
+
end
|
24
|
+
|
20
25
|
class Country < ActiveRecord::Base
|
21
26
|
field :name, :string
|
27
|
+
has_many :pictures, as: :imageable
|
22
28
|
end
|
23
29
|
|
24
30
|
class Role < ActiveRecord::Base
|
@@ -29,3 +35,4 @@ end
|
|
29
35
|
Person.migrate!
|
30
36
|
Country.migrate!
|
31
37
|
Role.migrate!
|
38
|
+
Picture.migrate!
|