dir_model 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +7 -3
- data/UPGRADE.md +4 -0
- data/lib/dir_model/import.rb +12 -14
- data/lib/dir_model/model/relations.rb +20 -4
- data/lib/dir_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bd12bf7d01c2bad2a2523951ab4ab1c568e0e02
|
4
|
+
data.tar.gz: fc427c58ec981822cb6cbb2094133d565ca11d89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16742b98db89c722a6781663280852b7c37a5fb957c9d8ce586b88b0ee910463919c6c487ce3fa32fd2a8913b248b3fb57487df2696352a6edc8781b840b2894
|
7
|
+
data.tar.gz: 4404f164ed161c2629abc6ebf18e51ca3790c02f85732a379161bb23b09ec0e7e211935a4a0364f6131a6d723f3282b3736a38e281600aab5cb977bb017c42cd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -60,13 +60,17 @@ A dir_model can have a relation like `has_one` basically is
|
|
60
60
|
class ChildImportDirModel
|
61
61
|
include DirModel::Model
|
62
62
|
include DirModel::Import
|
63
|
-
file :metadata, regex: -> {
|
63
|
+
file :metadata, regex: ->(foreign_value) { "Zones\/(?<sector_name>#{foreign_value})\/Zone_(?<zone_id>.*)\.(?<extension>json)" }
|
64
64
|
end
|
65
65
|
```
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
class ParentImportDirModel < BasicImportDirModel
|
69
|
-
has_one :dependency, ChildImportDirModel
|
69
|
+
has_one :dependency, ChildImportDirModel, foreign_key: :sector_name
|
70
|
+
|
71
|
+
def sector_name
|
72
|
+
"sector_#{sector_id}"
|
73
|
+
end
|
70
74
|
end
|
71
75
|
```
|
72
76
|
|
@@ -85,7 +89,7 @@ NOTE regex on child pass explicitly the value
|
|
85
89
|
class ZoneDirModel
|
86
90
|
include DirModel::Model
|
87
91
|
include DirModel::Import
|
88
|
-
file :image, regex: ->(foreign_value) { "Zones
|
92
|
+
file :image, regex: ->(foreign_value) { "Zones\/(?<sector_name>#{foreign_value})\/Zone_(?<zone_id>.*)\.(?<extension>png|jpg)" }
|
89
93
|
end
|
90
94
|
```
|
91
95
|
|
data/UPGRADE.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Upgrading
|
2
2
|
|
3
|
+
# Upgrading from 0.5.1 to 0.6.0
|
4
|
+
|
5
|
+
* relation need to have a foreign_key and dir_model related need to have a regex with the foreign_key in params
|
6
|
+
|
3
7
|
# Upgrading from 0.4.0 to 0.5.0
|
4
8
|
|
5
9
|
* Ensure you have only one definition of `file:` by dir_model
|
data/lib/dir_model/import.rb
CHANGED
@@ -30,7 +30,7 @@ module DirModel
|
|
30
30
|
|
31
31
|
path.read_path
|
32
32
|
dir_model = new(path.current_path, index: path.index, context: context, previous: previous)
|
33
|
-
find_relations(dir_model, path, context)
|
33
|
+
find_relations(dir_model, path, context) unless dir_model.skip?
|
34
34
|
|
35
35
|
dir_model
|
36
36
|
end
|
@@ -38,20 +38,18 @@ module DirModel
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def find_relations(dir_model, path, context)
|
41
|
-
|
42
|
-
if dir_model.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
dir_model.append_dir_models(_path.current_path, index: _path.index, context: _context)
|
52
|
-
end
|
53
|
-
children.each { |_child| find_relations(_child, path, context) }
|
41
|
+
if dir_model.has_relations?
|
42
|
+
if dir_model.has_one?
|
43
|
+
child = search(path, context) do |_path, _context|
|
44
|
+
dir_model.append_dir_model(_path.current_path, index: _path.index, context: _context)
|
45
|
+
end.first
|
46
|
+
find_relations(child, path, context) if child
|
47
|
+
end
|
48
|
+
if dir_model.has_many?
|
49
|
+
children = search(path, context) do |_path, _context|
|
50
|
+
dir_model.append_dir_models(_path.current_path, index: _path.index, context: _context)
|
54
51
|
end
|
52
|
+
children.each { |_child| find_relations(_child, path, context) }
|
55
53
|
end
|
56
54
|
end
|
57
55
|
end
|
@@ -21,9 +21,13 @@ module DirModel
|
|
21
21
|
# @return [Model] return the child if it is valid, otherwise returns nil
|
22
22
|
def append_dir_model(source_path, options={})
|
23
23
|
relation_name = self.class.has_one_relationship.keys.first
|
24
|
-
|
24
|
+
_options = self.class.has_one_relationship.values.first
|
25
|
+
related_class = _options[:dir_model_class]
|
26
|
+
foreign_key = _options[:foreign_key]
|
27
|
+
foreign_value = self.send(foreign_key)
|
25
28
|
|
26
|
-
related_dir_model = related_class.new(source_path,
|
29
|
+
related_dir_model = related_class.new(source_path,
|
30
|
+
options.reverse_merge(parent: self, foreign_value: foreign_value))
|
27
31
|
|
28
32
|
return unless related_dir_model
|
29
33
|
|
@@ -74,12 +78,12 @@ module DirModel
|
|
74
78
|
#
|
75
79
|
# @param [Symbol] relation_name the name of the relation
|
76
80
|
# @param [DirModel::Import] dir_model_class class of the relation
|
77
|
-
def has_one(relation_name, dir_model_class)
|
81
|
+
def has_one(relation_name, dir_model_class, options)
|
78
82
|
raise "for now, DirModel's has_one may only be called once" if @_has_one_relationship.present?
|
79
83
|
|
80
84
|
relation_name = relation_name.to_sym
|
81
85
|
|
82
|
-
merge_has_one_relationship(relation_name => dir_model_class)
|
86
|
+
merge_has_one_relationship(relation_name => { dir_model_class: dir_model_class }.merge(options))
|
83
87
|
|
84
88
|
define_method(:has_one?) do
|
85
89
|
true
|
@@ -94,6 +98,10 @@ module DirModel
|
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
101
|
+
def has_one?
|
102
|
+
!!@_has_one_relationship
|
103
|
+
end
|
104
|
+
|
97
105
|
# Defines a relationship between a dir model
|
98
106
|
#
|
99
107
|
# @param [Symbol] relation_name the name of the relation
|
@@ -118,6 +126,14 @@ module DirModel
|
|
118
126
|
instance_variable_get(variable_name) || instance_variable_set(variable_name, [])
|
119
127
|
end
|
120
128
|
end
|
129
|
+
|
130
|
+
def has_many?
|
131
|
+
!!@_has_many_relationship
|
132
|
+
end
|
133
|
+
|
134
|
+
def has_relations?
|
135
|
+
has_one? || has_many?
|
136
|
+
end
|
121
137
|
end
|
122
138
|
end
|
123
139
|
end
|
data/lib/dir_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dir_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Chung
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|