dir_model 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +4 -0
- data/README.md +4 -2
- data/UPGRADE.md +45 -0
- data/dir_model.gemspec +1 -1
- data/lib/dir_model/export/aggregate_dir.rb +5 -8
- data/lib/dir_model/import.rb +3 -5
- data/lib/dir_model/model/files.rb +1 -2
- data/lib/dir_model/model/relations.rb +2 -2
- data/lib/dir_model/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 488a7e3ac0284d3de0d578ff43fe0293132b4a03
|
4
|
+
data.tar.gz: 61b2bf17b362a211bddda139effe0cbcf628d594
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a91b3e607bdc5e8baa616cd1c4541edb45a733307d69128366bac0f0f9cf423a192e5af3dc8630194538fcc9371c023b778df7d4cef163060c97b0b415486457
|
7
|
+
data.tar.gz: e2477c238e7c641cff600fa2fb0db60b7c613438d73aa3ef3a2c4b0936aa36970ad25eaa7e51f60e7c45f965c7e240278d01fb3b7131707422b93f9006d85742
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -160,10 +160,12 @@ fixture_models = [
|
|
160
160
|
})
|
161
161
|
]
|
162
162
|
|
163
|
-
exporter = DirModel::Export::AggregateDir.new
|
163
|
+
exporter = DirModel::Export::AggregateDir.new
|
164
164
|
|
165
165
|
exporter.generate do |dir|
|
166
|
-
models.each
|
166
|
+
models.each do |model|
|
167
|
+
dir.append_model(BasicExportDirModel, model)
|
168
|
+
end
|
167
169
|
end
|
168
170
|
|
169
171
|
exporter.dir_path # => path of generated dir .../Sectors
|
data/UPGRADE.md
CHANGED
@@ -1,5 +1,50 @@
|
|
1
1
|
# Upgrading
|
2
2
|
|
3
|
+
# Upgrading from 0.6.2 to 0.7.0
|
4
|
+
|
5
|
+
* Change the manner of call AggregateDir like
|
6
|
+
|
7
|
+
From
|
8
|
+
|
9
|
+
```
|
10
|
+
exporter = DirModel::Export::AggregateDir.new(BasicExportDirModel)
|
11
|
+
|
12
|
+
exporter.generate do |dir|
|
13
|
+
models.each do |model|
|
14
|
+
dir << model
|
15
|
+
end
|
16
|
+
end
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
To
|
21
|
+
|
22
|
+
```
|
23
|
+
exporter = DirModel::Export::AggregateDir.new
|
24
|
+
|
25
|
+
exporter.generate do |dir|
|
26
|
+
models.each do |model|
|
27
|
+
dir.append_model(BasicExportDirModel, model)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Now you can compose like
|
33
|
+
|
34
|
+
```
|
35
|
+
exporter = DirModel::Export::AggregateDir.new
|
36
|
+
|
37
|
+
exporter.generate do |dir|
|
38
|
+
models.each do |model|
|
39
|
+
dir.append_model(SectorExportDirModel, model)
|
40
|
+
end
|
41
|
+
end.generate do |dir|
|
42
|
+
models.each do |model|
|
43
|
+
dir.append_model(ZoneExportDirModel, model)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
3
48
|
# Upgrading from 0.5.1 to 0.6.0
|
4
49
|
|
5
50
|
* relation need to have a foreign_key and dir_model related need to have a regex with the foreign_key in params
|
data/dir_model.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_dependency 'activesupport', '~> 4.2'
|
22
|
-
spec.add_dependency 'inherited_class_var', '
|
22
|
+
spec.add_dependency 'inherited_class_var', '1.0.0.beta1'
|
23
23
|
spec.add_dependency 'fastimage', '~> 1.8'
|
24
24
|
end
|
@@ -5,23 +5,21 @@ module DirModel
|
|
5
5
|
class AggregateDir
|
6
6
|
include Utils
|
7
7
|
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :context, :dir_path
|
9
9
|
|
10
10
|
# @param [Export] export_model export model class
|
11
|
-
def initialize(
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@dir_path = Dir.mktmpdir
|
11
|
+
def initialize(context={})
|
12
|
+
@context = context.to_h.symbolize_keys
|
13
|
+
@dir_path = Dir.mktmpdir
|
15
14
|
end
|
16
15
|
|
17
16
|
# Add a row_model to the
|
18
17
|
# @param [] source_model the source model of the export file model
|
19
18
|
# @param [Hash] context the extra context given to the instance of the file model
|
20
|
-
def append_model(source_model, context={})
|
19
|
+
def append_model(export_dir_model_class, source_model, context={})
|
21
20
|
source_path = export_dir_model_class.new(source_model, context.reverse_merge(self.context)).path
|
22
21
|
FileUtils.cp_r Dir.glob("#{source_path}/*"), dir_path
|
23
22
|
end
|
24
|
-
alias_method :<<, :append_model
|
25
23
|
|
26
24
|
def generate
|
27
25
|
yield self
|
@@ -31,7 +29,6 @@ module DirModel
|
|
31
29
|
def files
|
32
30
|
Dir["#{@dir_path}/**/*"].select { |f| File.file?(f) }
|
33
31
|
end
|
34
|
-
|
35
32
|
end
|
36
33
|
end
|
37
34
|
end
|
data/lib/dir_model/import.rb
CHANGED
@@ -90,11 +90,9 @@ module DirModel
|
|
90
90
|
end
|
91
91
|
|
92
92
|
def get_regexp
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
self.class.options[:regex].call
|
97
|
-
end
|
93
|
+
args = []
|
94
|
+
args << foreign_value if foreign_value
|
95
|
+
instance_exec(*args, &self.class.options[:regex])
|
98
96
|
end
|
99
97
|
end
|
100
98
|
end
|
@@ -29,10 +29,9 @@ module DirModel
|
|
29
29
|
protected
|
30
30
|
|
31
31
|
def file(file_name, options={})
|
32
|
-
|
32
|
+
files_object.merge(file_name.to_sym => options)
|
33
33
|
raise ArgumentError.new("You cannot define more of one file: but you can add relations, see README") if files.keys.size > 1
|
34
34
|
end
|
35
|
-
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
@@ -81,7 +81,7 @@ module DirModel
|
|
81
81
|
def has_one(relation_name, dir_model_class, options)
|
82
82
|
relation_name = relation_name.to_sym
|
83
83
|
|
84
|
-
|
84
|
+
has_one_relationship_object.merge(relation_name => { dir_model_class: dir_model_class }.merge(options))
|
85
85
|
|
86
86
|
define_method(:has_one?) do
|
87
87
|
true
|
@@ -113,7 +113,7 @@ module DirModel
|
|
113
113
|
raise "for now, DirModel's has_many may only be called once" if @_has_many_relationship.present?
|
114
114
|
relation_name = relation_name.to_sym
|
115
115
|
|
116
|
-
|
116
|
+
has_many_relationship_object.merge(relation_name => { dir_model_class: dir_model_class }.merge(options))
|
117
117
|
|
118
118
|
define_method(:has_many?) do
|
119
119
|
true
|
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.7.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:
|
11
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: inherited_class_var
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '='
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.0.0.beta1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '='
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.0.0.beta1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: fastimage
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|