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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9351d53d58975968b6a9c7c4625246502821fe12
4
- data.tar.gz: b46d5083fc72a7980e15c62777cb0c41ccf1add3
3
+ metadata.gz: e9907296322411ab264d5463c48bd55edfc83d5a
4
+ data.tar.gz: a7a487a862999ce8e6b35db4a32dec3b0fcf55ce
5
5
  SHA512:
6
- metadata.gz: 47660950a66d668feb8c4a04041b97a08c10196abb6f4528319edd1dd6c35e7058fb66b073ddc00f3c77f95d614ad22bedcf93c2b857c1a90e20c75f82c3ac49
7
- data.tar.gz: 967cb6e497fb73b2606cf9b7dbab994f82b2180aa1ef25e978e121918250cf935233af514474df4b8003992f537f65adc9e1d1af0fa3c1ee893392be1ea4d103
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
- # Your code goes here...
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 'pry'
3
+ require 'colonization/configuration'
4
4
 
5
5
  class Colonization::Colonizer
6
6
 
7
- DEFAULT_MODEL_INSTANCES_NUMBER = 2
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 + custom_excepted_fields
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(field))
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(reflection))
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[:type] == :fixed ? belongs_to_relations : has_many_relations
88
+ strategy == :fixed ? belongs_to_relations : has_many_relations
99
89
  end
100
90
 
101
91
  def model_instances_number
102
- #TODO config[model][:model_instances_number] || DEFAULT_MODEL_INSTANCES_NUMBER
103
- DEFAULT_MODEL_INSTANCES_NUMBER - model.count
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(field = nil)
111
- #TODO config[model][field]
112
- { type: :default }
103
+ def strategy
104
+ Colonization.configuration.seed_type
113
105
  end
114
106
 
115
107
  def clear_table?
116
- true #TODO config[model][:clear_table] || config[:clear_table] || true
117
- end
118
-
119
- def config
120
- raise #TODO
108
+ Colonization.configuration.clear_table
121
109
  end
122
110
 
123
111
  end
@@ -0,0 +1,12 @@
1
+ class Colonization::Configuration
2
+
3
+ attr_accessor :seed_type, :count_of_instances_to_seed, :seed_index, :clear_table
4
+
5
+ def initialize
6
+ @seed_type = :default
7
+ @seed_index = 3
8
+ @count_of_instances_to_seed = 100
9
+ @clear_table = true
10
+ end
11
+
12
+ end
@@ -4,19 +4,11 @@ require 'colonization/colonizer'
4
4
 
5
5
  class Colonization::ModelRelation < Colonization::ModelEntity
6
6
 
7
- DEAFULT_SEED_INDEX = 3
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[:type] == :fixed
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
- seed_index = strategy[:seed_index] || DEAFULT_SEED_INDEX
46
-
47
- found_instances = Colonization::ModelInstancesRepository.new.get_instance_without_relation(model: reflection_class, relation: reflection_owner, limit: seed_index)
48
- result_instances = Colonization::Colonizer.new(reflection_class).colonize(seed_index - (found_instances ? found_instances.count : 0))
49
- result_instances
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
@@ -1,3 +1,3 @@
1
1
  module Colonization
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3"
3
3
  end
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.2.2
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