colonization 0.2.2 → 0.3
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/lib/colonization.rb +12 -1
- data/lib/colonization/colonizer.rb +14 -26
- data/lib/colonization/configuration.rb +12 -0
- data/lib/colonization/model_relation.rb +10 -16
- data/lib/colonization/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9907296322411ab264d5463c48bd55edfc83d5a
|
4
|
+
data.tar.gz: a7a487a862999ce8e6b35db4a32dec3b0fcf55ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad86fc64496fac7815bab8ff3953c3611d78e866dd6cbefdd212db619e56113d0597884ee7b1a9c99544b4a3d1dd25f423623a78aaf6421125f8c1d161e3b06b
|
7
|
+
data.tar.gz: 78e4eaa67eaab63afaff5da1053b0984b937581c01f6ff7684bdaab3187b0d73c34b4bf258a69ce32196b461a774b447aa5797ca624c5de546cf947ae36dc11c
|
data/lib/colonization.rb
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
require "colonization/version"
|
2
2
|
require "colonization/ship"
|
3
|
+
require "colonization/configuration"
|
3
4
|
|
4
5
|
module Colonization
|
5
|
-
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def configure(&block)
|
9
|
+
yield(configuration)
|
10
|
+
end
|
11
|
+
|
12
|
+
def configuration
|
13
|
+
@configuration ||= Colonization::Configuration.new
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
6
17
|
end
|
@@ -1,30 +1,24 @@
|
|
1
1
|
require 'colonization/model_field'
|
2
2
|
require 'colonization/model_relation'
|
3
|
-
require '
|
3
|
+
require 'colonization/configuration'
|
4
4
|
|
5
5
|
class Colonization::Colonizer
|
6
6
|
|
7
|
-
|
7
|
+
attr_accessor :model
|
8
8
|
|
9
9
|
def initialize(model)
|
10
10
|
@model = model
|
11
11
|
end
|
12
12
|
|
13
|
-
def model
|
14
|
-
@model
|
15
|
-
end
|
16
|
-
|
17
13
|
def print_action
|
18
14
|
puts "colonize #{model}"
|
19
15
|
end
|
20
16
|
|
21
17
|
def colonize(times = nil)
|
22
18
|
res = []
|
23
|
-
|
24
19
|
(times || model_instances_number).times do
|
25
20
|
res << model.create!(params_with_values)
|
26
21
|
end
|
27
|
-
|
28
22
|
res
|
29
23
|
end
|
30
24
|
|
@@ -71,17 +65,13 @@ class Colonization::Colonizer
|
|
71
65
|
end
|
72
66
|
|
73
67
|
def unnecessary_fields
|
74
|
-
["created_at", "updated_at", "id"] + model_relations_strings
|
75
|
-
end
|
76
|
-
|
77
|
-
def custom_excepted_fields
|
78
|
-
[] #TODO
|
68
|
+
["created_at", "updated_at", "id"] + model_relations_strings
|
79
69
|
end
|
80
70
|
|
81
71
|
def model_fields_objects
|
82
72
|
res = []
|
83
73
|
model_fields.each do |field|
|
84
|
-
res << Colonization::ModelField.new(model, field, values_generator, strategy
|
74
|
+
res << Colonization::ModelField.new(model, field, values_generator, strategy)
|
85
75
|
end
|
86
76
|
res
|
87
77
|
end
|
@@ -89,35 +79,33 @@ class Colonization::Colonizer
|
|
89
79
|
def model_relation_objects
|
90
80
|
res = []
|
91
81
|
needed_relations.each do |reflection|
|
92
|
-
res << Colonization::ModelRelation.new(reflection, strategy
|
82
|
+
res << Colonization::ModelRelation.new(reflection, strategy)
|
93
83
|
end
|
94
84
|
res
|
95
85
|
end
|
96
86
|
|
97
87
|
def needed_relations
|
98
|
-
strategy
|
88
|
+
strategy == :fixed ? belongs_to_relations : has_many_relations
|
99
89
|
end
|
100
90
|
|
101
91
|
def model_instances_number
|
102
|
-
|
103
|
-
|
92
|
+
if clear_table?
|
93
|
+
Colonization.configuration.count_of_instances_to_seed - model.count
|
94
|
+
else
|
95
|
+
Colonization.configuration.count_of_instances_to_seed
|
96
|
+
end
|
104
97
|
end
|
105
98
|
|
106
99
|
def values_generator
|
107
100
|
nil #TODO config[model][values_generator] || cofig[values_generator]
|
108
101
|
end
|
109
102
|
|
110
|
-
def strategy
|
111
|
-
|
112
|
-
{ type: :default }
|
103
|
+
def strategy
|
104
|
+
Colonization.configuration.seed_type
|
113
105
|
end
|
114
106
|
|
115
107
|
def clear_table?
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
def config
|
120
|
-
raise #TODO
|
108
|
+
Colonization.configuration.clear_table
|
121
109
|
end
|
122
110
|
|
123
111
|
end
|
@@ -4,19 +4,11 @@ require 'colonization/colonizer'
|
|
4
4
|
|
5
5
|
class Colonization::ModelRelation < Colonization::ModelEntity
|
6
6
|
|
7
|
-
|
7
|
+
attr_accessor :reflection, :strategy
|
8
8
|
|
9
9
|
def initialize(reflection, strategy)
|
10
10
|
@reflection = reflection
|
11
|
-
@strategy = strategy
|
12
|
-
end
|
13
|
-
|
14
|
-
def reflection
|
15
|
-
@reflection
|
16
|
-
end
|
17
|
-
|
18
|
-
def strategy
|
19
|
-
@strategy || {}
|
11
|
+
@strategy = strategy || {}
|
20
12
|
end
|
21
13
|
|
22
14
|
def name
|
@@ -24,7 +16,7 @@ class Colonization::ModelRelation < Colonization::ModelEntity
|
|
24
16
|
end
|
25
17
|
|
26
18
|
def value
|
27
|
-
if strategy
|
19
|
+
if strategy == :fixed #TODO: refactor this shit
|
28
20
|
generate_relation_value_with_fixed_strategy
|
29
21
|
else
|
30
22
|
generate_relation_value_with_default_strategy
|
@@ -42,11 +34,13 @@ class Colonization::ModelRelation < Colonization::ModelEntity
|
|
42
34
|
end
|
43
35
|
|
44
36
|
def generate_relation_value_with_default_strategy
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
found_instances = Colonization::ModelInstancesRepository.new.get_instance_without_relation(
|
38
|
+
model: reflection_class,
|
39
|
+
relation: reflection_owner,
|
40
|
+
limit: Colonization.configuration.seed_index
|
41
|
+
)
|
42
|
+
count_to_colonize = Colonization.configuration.seed_index - (found_instances ? found_instances.count : 0)
|
43
|
+
Colonization::Colonizer.new(reflection_class).colonize(count_to_colonize)
|
50
44
|
end
|
51
45
|
|
52
46
|
def reflection_class
|
data/lib/colonization/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colonization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denys Dvoriashyn
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- colonization.gemspec
|
83
83
|
- lib/colonization.rb
|
84
84
|
- lib/colonization/colonizer.rb
|
85
|
+
- lib/colonization/configuration.rb
|
85
86
|
- lib/colonization/investigator.rb
|
86
87
|
- lib/colonization/model_entity.rb
|
87
88
|
- lib/colonization/model_field.rb
|