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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5839249966297fbc355e39fdfdf569f75d9dfc0e
4
- data.tar.gz: 7f7985804ac779b6ec357e43059fbbb2566c70bc
3
+ metadata.gz: '0529ed61553454c5740cad93d4fe367c55bafff4'
4
+ data.tar.gz: 3ff4ab1445c74118f8cc20dfb3d4b5e45565892b
5
5
  SHA512:
6
- metadata.gz: f4d9731facc4a4043b5ead01fa9be46f6872bfbb8e973510a26696a8d3850e808f02fe35318a82405764c1feef451c183ab23b78a59b703f0e9523fac5964431
7
- data.tar.gz: 3b72fa88f29b8bacc37bc3d63ca7df6752c9991d0e9be476bfe1b4ba4476790b1f4493ca285268e62dc3e0b13e3b8ae89db022bf0b901594a0b498c398a7c434
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 dynamo side you can use:
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
@@ -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 = '2018-03-16'
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}
@@ -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
- attr_accessor name.to_sym
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
- attr_accessor name.to_sym
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
@@ -1,3 +1,3 @@
1
1
  module Dynamord
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -20,4 +20,11 @@ module Dynamord
20
20
  end
21
21
  end
22
22
  end
23
+
24
+ module Document
25
+ def delete_all
26
+ self.delete_table
27
+ self.create_table
28
+ end
29
+ end
23
30
  end
@@ -1,5 +1,6 @@
1
1
  require './app/models/concerns/dynamord_chain'
2
2
  Dynamoid::Criteria::Chain.include Dynamord::Chain
3
+ Dynamoid::Document::ClassMethods.include Dynamord::Document
3
4
 
4
5
  module ActiveRecord::ConnectionAdapters
5
6
  class TableDefinition
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - vibhanshu