dread 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/dread/graph.rb +37 -24
- data/lib/dread/version.rb +1 -1
- data/test/dread_test.rb +2 -2
- data/test/dummy/app/models/comment.rb +1 -0
- data/test/dummy/app/models/picture.rb +3 -0
- data/test/dummy/app/models/tweet.rb +1 -0
- data/test/dummy/app/models/user.rb +4 -3
- data/test/dummy/db/migrate/20140915161852_create_pictures.rb +11 -0
- data/test/dummy/db/schema.rb +9 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34cd6aee3f85a657ebabe35bc350cbf3ccc2f95d
|
4
|
+
data.tar.gz: e72c6897aeec2fb15e4209c322ab0778151a9778
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2f0d84dfc7d199d42cadc2e1f028f8c3afacc6d4ae5c1d7b0fc0ee3c3ca04af8a444cc4ec5263b9b5c442b1cbe5e75b0c5cbe947523ef8e84dc1ceb943b51a6
|
7
|
+
data.tar.gz: c498def53e5c72d80f86873b3dde2b033d4c00c08771bf8e8a4dc35123a496bfe917c997217ca35b6e102f55439e744cf8607e8ca7e8ae5f10bc098241c2bd7a
|
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
# Dread
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/DamirSvrtan/dread.svg?branch=master)](https://travis-ci.org/DamirSvrtan/dread)
|
3
|
+
[![Build Status](https://travis-ci.org/DamirSvrtan/dread.svg?branch=master)](https://travis-ci.org/DamirSvrtan/dread)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/DamirSvrtan/dread/badges/gpa.svg)](https://codeclimate.com/github/DamirSvrtan/dread)
|
data/lib/dread/graph.rb
CHANGED
@@ -6,23 +6,15 @@ module Dread
|
|
6
6
|
attr_reader :clazz, :dependable_collection
|
7
7
|
|
8
8
|
def initialize(clazz_data, pluralized=false)
|
9
|
-
|
9
|
+
set_and_verify_clazz_and_relation(clazz_data)
|
10
10
|
@pluralized = pluralized
|
11
|
+
@@tracker ||= []
|
11
12
|
end
|
12
13
|
|
13
|
-
# { user: { tweets: { comments: {} }, comments: {},
|
14
|
+
# { user: { tweets: { comments: {} }, comments: {}, setting: {} } }
|
14
15
|
def dependable_collection
|
15
|
-
@dependable_collection ||=
|
16
|
-
|
17
|
-
if assoc_data.options[:dependent] == :delete
|
18
|
-
relation_hash[assoc_name] = {}
|
19
|
-
elsif assoc_data.options[:dependent] == :destroy
|
20
|
-
relation_hash.merge!(
|
21
|
-
Graph.new(assoc_data, assoc_data.macro == :has_many).dependable_collection)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
}
|
16
|
+
@dependable_collection ||=
|
17
|
+
{ @relation.to_sym => collect_dependables }
|
26
18
|
end
|
27
19
|
|
28
20
|
def draw(output='console_output')
|
@@ -34,31 +26,52 @@ module Dread
|
|
34
26
|
|
35
27
|
private
|
36
28
|
|
37
|
-
def
|
38
|
-
|
29
|
+
def track!(reflection)
|
30
|
+
@@tracker << reflection
|
31
|
+
end
|
32
|
+
|
33
|
+
def tracked?(reflection)
|
34
|
+
@@tracker.include? reflection
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_and_verify_clazz_and_relation(clazz_data)
|
39
38
|
begin
|
40
|
-
|
39
|
+
set_clazz_and_relation(clazz_data)
|
41
40
|
rescue NameError => e
|
42
|
-
raise Error.new("Unable to find class called #{
|
41
|
+
raise Error.new("Unable to find class called #{clazz_data.classify}")
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
def
|
45
|
+
def set_clazz_and_relation(clazz_data)
|
47
46
|
case clazz_data
|
48
47
|
when ActiveRecord::Reflection::AssociationReflection
|
49
|
-
clazz_data.class_name || clazz_data.table_name
|
48
|
+
@clazz = (clazz_data.class_name || clazz_data.table_name).constantize
|
49
|
+
@relation = clazz_data.name
|
50
50
|
when String
|
51
|
-
clazz_data.classify
|
51
|
+
@clazz = (clazz_data.classify).constantize
|
52
|
+
@relation = clazz_data
|
52
53
|
when NilClass
|
53
|
-
raise Error.new('Please pass a env var called class to proceed.')
|
54
|
+
raise Error.new('Please pass a env var called class to proceed. E.g: rake dread class=user')
|
54
55
|
else
|
55
56
|
raise Error.new("Unable to proceed with #{clazz_data.class}")
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
60
|
+
def collect_dependables
|
61
|
+
Hash.new.tap do |relation_hash|
|
62
|
+
@clazz.reflections.each do |assoc_name, assoc_data|
|
63
|
+
case assoc_data.options[:dependent]
|
64
|
+
when :delete
|
65
|
+
relation_hash[assoc_name] = {}
|
66
|
+
when :destroy
|
67
|
+
# unless tracked?(assoc_data)
|
68
|
+
# track!(assoc_data)
|
69
|
+
relation_hash.merge!(
|
70
|
+
Graph.new(assoc_data, assoc_data.macro == :has_many).dependable_collection)
|
71
|
+
# end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
62
75
|
end
|
63
76
|
|
64
77
|
end
|
data/lib/dread/version.rb
CHANGED
data/test/dread_test.rb
CHANGED
@@ -32,8 +32,8 @@ class DreadTest < ActiveSupport::TestCase
|
|
32
32
|
dread_graph = Dread::Graph.new('user')
|
33
33
|
dependable_collection = dread_graph.dependable_collection
|
34
34
|
dependable_collection.assert_valid_keys(:user)
|
35
|
-
dependable_collection[:user].assert_valid_keys(:tweets, :comments, :setting)
|
36
|
-
dependable_collection[:user][:tweets].assert_valid_keys(:comments)
|
35
|
+
dependable_collection[:user].assert_valid_keys(:tweets, :comments, :setting, :avatar)
|
36
|
+
dependable_collection[:user][:tweets].assert_valid_keys(:comments, :pictures)
|
37
37
|
end
|
38
38
|
|
39
39
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class User < ActiveRecord::Base
|
2
|
-
has_many :tweets,
|
3
|
-
has_many :comments,
|
4
|
-
has_one :
|
2
|
+
has_many :tweets, dependent: :destroy
|
3
|
+
has_many :comments, dependent: :destroy
|
4
|
+
has_one :avatar, dependent: :destroy, class_name: 'Picture', as: :imageable
|
5
|
+
has_one :setting, dependent: :destroy, class_name: 'AccountSetting'
|
5
6
|
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20140915161852) do
|
15
15
|
|
16
16
|
create_table "account_settings", force: true do |t|
|
17
17
|
t.string "time_zone"
|
@@ -34,6 +34,14 @@ ActiveRecord::Schema.define(version: 20140914191415) do
|
|
34
34
|
t.datetime "updated_at"
|
35
35
|
end
|
36
36
|
|
37
|
+
create_table "pictures", force: true do |t|
|
38
|
+
t.string "url"
|
39
|
+
t.integer "imageable_id"
|
40
|
+
t.string "imageable_type"
|
41
|
+
t.datetime "created_at"
|
42
|
+
t.datetime "updated_at"
|
43
|
+
end
|
44
|
+
|
37
45
|
create_table "tweets", force: true do |t|
|
38
46
|
t.integer "user_id"
|
39
47
|
t.string "content"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dread
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damir Svrtan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- test/dummy/app/models/account_setting.rb
|
93
93
|
- test/dummy/app/models/comment.rb
|
94
94
|
- test/dummy/app/models/country.rb
|
95
|
+
- test/dummy/app/models/picture.rb
|
95
96
|
- test/dummy/app/models/tweet.rb
|
96
97
|
- test/dummy/app/models/user.rb
|
97
98
|
- test/dummy/bin/bundle
|
@@ -121,6 +122,7 @@ files:
|
|
121
122
|
- test/dummy/db/migrate/20140913143724_create_comments.rb
|
122
123
|
- test/dummy/db/migrate/20140914191313_create_countries.rb
|
123
124
|
- test/dummy/db/migrate/20140914191415_create_account_settings.rb
|
125
|
+
- test/dummy/db/migrate/20140915161852_create_pictures.rb
|
124
126
|
- test/dummy/db/schema.rb
|
125
127
|
- test/dummy/lib/assets/.keep
|
126
128
|
- test/dummy/log/.keep
|
@@ -160,6 +162,7 @@ test_files:
|
|
160
162
|
- test/dummy/app/models/account_setting.rb
|
161
163
|
- test/dummy/app/models/comment.rb
|
162
164
|
- test/dummy/app/models/country.rb
|
165
|
+
- test/dummy/app/models/picture.rb
|
163
166
|
- test/dummy/app/models/tweet.rb
|
164
167
|
- test/dummy/app/models/user.rb
|
165
168
|
- test/dummy/bin/bundle
|
@@ -189,6 +192,7 @@ test_files:
|
|
189
192
|
- test/dummy/db/migrate/20140913143724_create_comments.rb
|
190
193
|
- test/dummy/db/migrate/20140914191313_create_countries.rb
|
191
194
|
- test/dummy/db/migrate/20140914191415_create_account_settings.rb
|
195
|
+
- test/dummy/db/migrate/20140915161852_create_pictures.rb
|
192
196
|
- test/dummy/db/schema.rb
|
193
197
|
- test/dummy/lib/assets/.keep
|
194
198
|
- test/dummy/log/.keep
|