slacker 0.0.10 → 0.0.11

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.
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slacker (0.0.10)
4
+ slacker (0.0.11)
5
5
  bundler (~> 1.0.15)
6
- rspec (= 2.5.0)
6
+ rspec (~> 2.5.0)
7
7
  ruby-odbc (= 0.99994)
8
8
 
9
9
  GEM
data/bin/slacker CHANGED
File without changes
data/bin/slacker_new CHANGED
File without changes
data/lib/slacker.rb CHANGED
@@ -135,5 +135,31 @@ module Slacker
135
135
  end
136
136
  query_script(example, sql, log_name) unless sql.nil?
137
137
  end
138
+
139
+ def touch_csv(csv_file_or_object, fields, field_generators = {})
140
+ csv_obj = csv_file_or_object.kind_of?(String) ? get_csv(csv_file_or_object) : csv_file_or_object
141
+ fields = fields.is_a?(Array) ? fields : [fields]
142
+
143
+ # Adjust the csv if we are providing more records than there are in the csv
144
+ csv_row_count = csv_obj.to_a.count - 1
145
+
146
+ (fields.count - csv_row_count).times do |index|
147
+ csv_obj << csv_obj[index % csv_row_count].fields
148
+ end
149
+
150
+ # Add the field generators to the hard-coded fields
151
+ field_generators.each do |key, value|
152
+ fields.each_with_index do |record, index|
153
+ record[key] = value.to_s + index.to_s
154
+ end
155
+ end
156
+
157
+ fields.each_with_index do |record, index|
158
+ record.each do |key, value|
159
+ csv_obj[index][key.to_sym.downcase] = value
160
+ end
161
+ end
162
+ csv_obj
163
+ end
138
164
  end
139
165
  end
@@ -9,37 +9,13 @@ module Slacker
9
9
  sql = Slacker.sql_from_query_string(query_string, options)
10
10
  @results = Slacker.query_script(example, sql, log_name)
11
11
  if block_given?
12
- yield
12
+ yield @results
13
13
  end
14
14
  @results
15
15
  end
16
16
 
17
- def results
18
- @results
19
- end
20
-
21
- def result(index = 1, options = {})
22
- # Flatten the result in case we're getting a multi-result-set response
23
- res = case !@results.empty? && @results[0].kind_of?(Array)
24
- when true
25
- raise "The query result contains only #{@results.count} result set(s)" unless @results.count >= index
26
- @results[index - 1]
27
- else
28
- raise "The query result contains a single result set" unless index == 1
29
- @results
30
- end
31
-
32
- #Optionally extract the record and or the field
33
- if options[:record] != nil
34
- raise "The result set contains only #{res.count} record(s)" unless res.count >= options[:record]
35
- res = res[options[:record] - 1]
36
- if options[:field] != nil
37
- raise "The result set does not contain field \"#{options[:field]}\"" unless res[options[:field]] != nil
38
- res = res[options[:field]]
39
- end
40
- end
41
-
42
- res
17
+ def sql
18
+ Slacker.sql(self)
43
19
  end
44
20
 
45
21
  # Get a matcher which will compare the query results to a golden master
@@ -47,6 +23,14 @@ module Slacker
47
23
  QueryResultMatcher.new(Slacker.filter_golden_master(golden_master))
48
24
  end
49
25
 
26
+ def csv(csv_file)
27
+ Slacker.get_csv(csv_file)
28
+ end
29
+
30
+ def touch_csv(csv_file_or_object, fields, field_generators = {})
31
+ Slacker.touch_csv(csv_file_or_object, fields, field_generators)
32
+ end
33
+
50
34
  def load_csv(csv_file_or_object, table_name, log_name = nil)
51
35
  log_name ||= "load_csv '#{csv_file_or_object.kind_of?(CSV::Table) ? 'CSV Object' : csv_file_or_object }', 'table_name'"
52
36
  csv_object = case csv_file_or_object
@@ -58,14 +42,6 @@ module Slacker
58
42
  Slacker.load_csv(example, csv_object, table_name, log_name)
59
43
  end
60
44
 
61
- def csv(csv_file)
62
- Slacker.get_csv(csv_file)
63
- end
64
-
65
- def sql
66
- Slacker.sql(self)
67
- end
68
-
69
45
  def yes?(val)
70
46
  val != nil && val.downcase == 'yes'
71
47
  end
@@ -1,3 +1,3 @@
1
1
  module Slacker
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -51,7 +51,7 @@ describe 'My database' do
51
51
  # Note that this time we're calling the template with a block.
52
52
  # When called with a block, a template is executed and its results are accessible
53
53
  # from within the block through the "results" object.
54
- sql.sample_1.play_with_numbers(:x => 2, :y => 12) do
54
+ sql.sample_1.play_with_numbers(:x => 2, :y => 12) do |results|
55
55
  # The results object contains an array of all the resultsets generated by the query script.
56
56
  first_resultset = results[0]
57
57
 
@@ -79,7 +79,7 @@ describe 'My database' do
79
79
  # The results of a query can also be compared against the contents
80
80
  # of a CSV file located in the data folder - see file data/sample_1/numbers_expected_output.csv
81
81
  it 'can play with numbers (take two)' do
82
- sql.sample_1.play_with_numbers(:x => 10, :y => 34) do
82
+ sql.sample_1.play_with_numbers(:x => 10, :y => 34) do |results|
83
83
  results[2].should match('sample_1/numbers_expected_output.csv')
84
84
  end
85
85
  end
data/slacker.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.required_ruby_version = '>= 1.9.2'
22
22
 
23
- s.add_dependency 'bundler', '~>1.0.15'
24
- s.add_dependency 'ruby-odbc', '=0.99994'
25
- s.add_dependency 'rspec', '=2.5.0'
23
+ s.add_dependency 'bundler', '~> 1.0.15'
24
+ s.add_dependency 'ruby-odbc', '= 0.99994'
25
+ s.add_dependency 'rspec', '~> 2.5.0'
26
26
  end
@@ -35,12 +35,8 @@ describe Slacker::RSpecExt do
35
35
  @instance.should respond_to(:load_csv)
36
36
  end
37
37
 
38
- it 'responds to result' do
39
- @instance.should respond_to(:result)
40
- end
41
-
42
- it 'responds to results' do
43
- @instance.should respond_to(:results)
38
+ it 'responds to load_csv' do
39
+ @instance.should respond_to(:touch_csv)
44
40
  end
45
41
 
46
42
  it 'responds to sql' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slacker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.10
5
+ version: 0.0.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Vassil Kovatchev
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-25 00:00:00 Z
13
+ date: 2011-06-27 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - "="
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: 2.5.0
46
46
  type: :runtime