dynamord 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +17 -1
- data/dynamord.gemspec +1 -1
- data/lib/dynamord.rb +15 -5
- data/lib/dynamord/version.rb +1 -1
- data/lib/generators/templates/dynamord_chain.rb +7 -0
- data/lib/generators/templates/gem_initializer.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0529ed61553454c5740cad93d4fe367c55bafff4'
|
4
|
+
data.tar.gz: 3ff4ab1445c74118f8cc20dfb3d4b5e45565892b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b0e04212dd05fb91f1fe73d5c89f570dc5a52d4fbdd2d89f3042dfea8dc4af1bafc2a74c586b916f460cba80637b4393da2d9411a7afb05120042104c3cb787
|
7
|
+
data.tar.gz: f34fc4132f7e89f8fc2c4196e757953f8041fb238dc349720f563ac5a6a42077cc93eaa0d0c0f1a5a6395aad57e801f357770f2fdd0e109b5b4ab7fec44049e0
|
data/README.md
CHANGED
@@ -17,6 +17,9 @@ Or install it yourself as:
|
|
17
17
|
$ gem install dynamord
|
18
18
|
|
19
19
|
## Usage
|
20
|
+
Install the intializer configuration files
|
21
|
+
|
22
|
+
$ rails g dynamord:install
|
20
23
|
|
21
24
|
Add Dynamord to your models (both Active record and dynamoid)
|
22
25
|
|
@@ -32,7 +35,7 @@ Or install it yourself as:
|
|
32
35
|
include Dynamord
|
33
36
|
end
|
34
37
|
|
35
|
-
on the
|
38
|
+
on the dynamoid side you can use:
|
36
39
|
* to_active_record_belongs_to
|
37
40
|
* to_active_record_has_many
|
38
41
|
* to_active_record_has_one
|
@@ -58,6 +61,19 @@ you'll need to specify the association class and sometimes the foreign key (in `
|
|
58
61
|
from_active_record_has_many :pictures, :class => Picture, :foreign_key => "user_id"
|
59
62
|
end
|
60
63
|
|
64
|
+
Also add the association in your ActiveRecord migration file
|
65
|
+
|
66
|
+
class CreateOrganisations < ActiveRecord::Migration[5.1]
|
67
|
+
def change
|
68
|
+
create_table :organisations do |t|
|
69
|
+
t.string :name
|
70
|
+
t.string :url
|
71
|
+
t.from_active_record_belongs_to :industry
|
72
|
+
t.timestamps
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
61
77
|
## Contributing
|
62
78
|
|
63
79
|
1. Fork it
|
data/dynamord.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'dynamord/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "dynamord"
|
8
8
|
spec.version = Dynamord::VERSION
|
9
|
-
spec.date
|
9
|
+
spec.date = '2018-03-16'
|
10
10
|
spec.authors = ["vibhanshu"]
|
11
11
|
spec.email = ["vibhanshu909@gmail.com"]
|
12
12
|
spec.description = %q{A dynamoid to active_record and vice versa association manager}
|
data/lib/dynamord.rb
CHANGED
@@ -10,7 +10,6 @@ module Dynamord
|
|
10
10
|
##################################################################################
|
11
11
|
# Connection methods from dynamoid to active_record
|
12
12
|
def to_active_record_belongs_to(name, options = {})
|
13
|
-
# field "#{name}_id", :string
|
14
13
|
field "#{name}_id".to_sym, :integer
|
15
14
|
validates "#{name}_id".to_sym, presence: true
|
16
15
|
object_class = options[:class] || name.to_s.titleize.delete(' ').constantize
|
@@ -26,10 +25,10 @@ module Dynamord
|
|
26
25
|
|
27
26
|
self.instance_variable_get("@#{name}")
|
28
27
|
end
|
29
|
-
|
30
|
-
define_method("#{name}=(new_instance)") do
|
28
|
+
define_method("#{name}=") do |new_instance|
|
31
29
|
self.send("#{name}_id=", new_instance.id)
|
32
30
|
self.instance_variable_set("@#{name}", nil)
|
31
|
+
self.save
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -38,6 +37,17 @@ module Dynamord
|
|
38
37
|
plural_name = name.to_s.pluralize
|
39
38
|
foreign_key = options[:foreign_key] || "#{self.name.underscore}_id"
|
40
39
|
object_class = options[:class] || name.to_s.singularize.titleize.delete(' ').constantize
|
40
|
+
if options[:dependent]
|
41
|
+
case options[:dependent]
|
42
|
+
when :destroy
|
43
|
+
after_destroy { |record| record.send(name).delete_all }
|
44
|
+
when :delete_all
|
45
|
+
when :nullify
|
46
|
+
when :restrict_with_exception
|
47
|
+
when :restrict_with_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
after_destroy { |record| record.send(name).delete }
|
41
51
|
self.instance_eval do
|
42
52
|
define_method(plural_name) do |reload = false|
|
43
53
|
if reload
|
@@ -88,10 +98,10 @@ module Dynamord
|
|
88
98
|
|
89
99
|
self.instance_variable_get("@#{name}")
|
90
100
|
end
|
91
|
-
|
92
|
-
define_method("#{name}=(new_instance)") do
|
101
|
+
define_method("#{name}=") do |new_instance|
|
93
102
|
self.send("#{name}_id=", new_instance.id)
|
94
103
|
self.instance_variable_set("@#{name}", nil)
|
104
|
+
self.save
|
95
105
|
end
|
96
106
|
end
|
97
107
|
end
|
data/lib/dynamord/version.rb
CHANGED