data_miner 3.0.0.beta → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/lib/data_miner/attribute.rb +12 -8
- data/lib/data_miner/step/test.rb +3 -2
- data/lib/data_miner/version.rb +1 -1
- data/test/support/pet.rb +2 -0
- data/test/test_data_miner.rb +4 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/data_miner/attribute.rb
CHANGED
@@ -134,16 +134,18 @@ class DataMiner
|
|
134
134
|
@hstore_key = name.split('.', 2)[1]
|
135
135
|
end
|
136
136
|
|
137
|
-
# Where to find the data in the row.
|
138
|
-
# @return [String]
|
137
|
+
# Where to find the data in the row. If more than one field name, values are joined with a space.
|
138
|
+
# @return [Array<String>]
|
139
139
|
def field_name
|
140
140
|
return @field_name if defined?(@field_name)
|
141
|
-
@field_name = if @field_name_settings
|
142
|
-
@field_name_settings.to_s
|
141
|
+
@field_name = if @field_name_settings.is_a?(::Array)
|
142
|
+
@field_name_settings.map(&:to_s)
|
143
|
+
elsif @field_name_settings.is_a?(::String) or @field_name_settings.is_a?(::Symbol)
|
144
|
+
[ @field_name_settings.to_s ]
|
143
145
|
elsif hstore?
|
144
|
-
hstore_key
|
146
|
+
[ hstore_key ]
|
145
147
|
else
|
146
|
-
name
|
148
|
+
[ name ]
|
147
149
|
end
|
148
150
|
end
|
149
151
|
|
@@ -168,6 +170,8 @@ class DataMiner
|
|
168
170
|
end
|
169
171
|
|
170
172
|
# @private
|
173
|
+
ROW_HASH_FIELD_NAME = ['row_hash']
|
174
|
+
SINGLE_SPACE = ' '
|
171
175
|
def read(row)
|
172
176
|
if not column_exists?
|
173
177
|
raise RuntimeError, "[data_miner] Table #{model.table_name} does not have column #{(hstore? ? hstore_column : name).inspect}"
|
@@ -182,10 +186,10 @@ class DataMiner
|
|
182
186
|
else
|
183
187
|
row[field_number]
|
184
188
|
end
|
185
|
-
elsif field_name ==
|
189
|
+
elsif field_name == ROW_HASH_FIELD_NAME
|
186
190
|
row.row_hash
|
187
191
|
elsif row.is_a?(::Hash) or row.is_a?(::ActiveSupport::OrderedHash)
|
188
|
-
|
192
|
+
field_name.length > 1 ? row.values_at(*field_name).join(SINGLE_SPACE) : row[field_name[0]]
|
189
193
|
end
|
190
194
|
if value.nil?
|
191
195
|
return
|
data/lib/data_miner/step/test.rb
CHANGED
@@ -32,11 +32,12 @@ class DataMiner
|
|
32
32
|
|
33
33
|
# @private
|
34
34
|
def initialize(script, description, settings, &blk)
|
35
|
+
settings = settings.stringify_keys
|
35
36
|
@script = script
|
36
37
|
@description = description
|
37
38
|
@blk = blk
|
38
|
-
@after = settings[
|
39
|
-
@every = settings[
|
39
|
+
@after = settings['after']
|
40
|
+
@every = settings['every']
|
40
41
|
raise "can't do both after and every" if after and every
|
41
42
|
end
|
42
43
|
|
data/lib/data_miner/version.rb
CHANGED
data/test/support/pet.rb
CHANGED
@@ -14,6 +14,7 @@ class Pet < ActiveRecord::Base
|
|
14
14
|
col :favorite_food
|
15
15
|
col :command_phrase
|
16
16
|
col :emphatic_command_phrase
|
17
|
+
col :age_weight
|
17
18
|
belongs_to :breed
|
18
19
|
|
19
20
|
|
@@ -36,6 +37,7 @@ class Pet < ActiveRecord::Base
|
|
36
37
|
store :emphatic_command_phrase do |row|
|
37
38
|
(row['command_phrase'] + "!!!!!") if row['command_phrase']
|
38
39
|
end
|
40
|
+
store :age_weight, field_name: [:age, :weight]
|
39
41
|
end
|
40
42
|
|
41
43
|
end
|
data/test/test_data_miner.rb
CHANGED
@@ -47,6 +47,10 @@ describe DataMiner do
|
|
47
47
|
FileUtils.mv "#{PETS}.bak", PETS
|
48
48
|
end
|
49
49
|
end
|
50
|
+
it "combines fields with a space if array passed to :field_name" do
|
51
|
+
Pet.run_data_miner!
|
52
|
+
Pet.find('Jerry').age_weight.must_equal '5 10'
|
53
|
+
end
|
50
54
|
it "provides :run_data_miner_on_parent_associations!" do
|
51
55
|
Pet.run_data_miner!
|
52
56
|
Pet.find('Jerry').breed.must_equal Breed.find('Beagle')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_miner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.rc1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-
|
16
|
+
date: 2013-08-08 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: activerecord
|