data_pitcher 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8025404be932416fdf0b9bbd08d08f22cdf31469
4
- data.tar.gz: 29b8bc521481415d5412bd4114f316ad3fb7d718
3
+ metadata.gz: a297bdeb710a6ef6c3568c0e6c82cd1e1355acf0
4
+ data.tar.gz: 8e0c9397fa3b7d2420edeb8d1b2bd59f8a9e5be1
5
5
  SHA512:
6
- metadata.gz: 8c75433570a7a09727e2e51c9f8ee0ba535166dc108b2ba4a8a23aa098144fea6c4eceed56b74801cb8f80720a23c42bcee1e47b5f95a9ea9de6dbee2653a2ea
7
- data.tar.gz: 9ee9e905e4915689e1181d6f6867758edae4693ad9160246de1f804898b2f9160727acdddc0f308800aed12f97c70c74085b24b5df462de2fcfb7c9d037d821b
6
+ metadata.gz: 8680385889d52db50dc7790d9a97c3ea3244965c50feaca59b0a2a2bf46c38d7a613ecd28764d16e323497b1de54ac8747005fe84f528fbbf8423eaa7393932f
7
+ data.tar.gz: b8d4d33a5ec419c5e81b0bef15301d2c0bedac832b2a5d7493af62bf9d8644307cdf0dc5a045385fde084e2fa518dd6b5672fda940c9221edd940ff9d7fc9989
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- data_pitcher (0.1.2)
4
+ data_pitcher (0.1.3)
5
5
  activerecord (>= 3.2)
6
6
  google_drive
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (5.1.1)
12
- activesupport (= 5.1.1)
13
- activerecord (5.1.1)
14
- activemodel (= 5.1.1)
15
- activesupport (= 5.1.1)
11
+ activemodel (5.1.3)
12
+ activesupport (= 5.1.3)
13
+ activerecord (5.1.3)
14
+ activemodel (= 5.1.3)
15
+ activesupport (= 5.1.3)
16
16
  arel (~> 8.0)
17
- activesupport (5.1.1)
17
+ activesupport (5.1.3)
18
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
19
  i18n (~> 0.7)
20
20
  minitest (~> 5.1)
@@ -25,7 +25,7 @@ GEM
25
25
  concurrent-ruby (1.0.5)
26
26
  declarative (0.0.9)
27
27
  declarative-option (0.1.0)
28
- faraday (0.12.1)
28
+ faraday (0.12.2)
29
29
  multipart-post (>= 1.2, < 3)
30
30
  google-api-client (0.12.0)
31
31
  addressable (~> 2.5, >= 2.5.1)
@@ -47,7 +47,7 @@ GEM
47
47
  os (~> 0.9)
48
48
  signet (~> 0.7)
49
49
  httpclient (2.8.3)
50
- i18n (0.8.4)
50
+ i18n (0.8.6)
51
51
  jwt (1.5.6)
52
52
  little-plugger (1.1.4)
53
53
  logging (2.2.2)
@@ -58,7 +58,7 @@ GEM
58
58
  mime-types-data (~> 3.2015)
59
59
  mime-types-data (3.2016.0521)
60
60
  mini_portile2 (2.2.0)
61
- minitest (5.10.2)
61
+ minitest (5.10.3)
62
62
  multi_json (1.12.1)
63
63
  multipart-post (2.0.0)
64
64
  nokogiri (1.8.0)
@@ -89,4 +89,4 @@ DEPENDENCIES
89
89
  rake
90
90
 
91
91
  BUNDLED WITH
92
- 1.14.6
92
+ 1.15.3
data/README.md CHANGED
@@ -66,6 +66,7 @@ For example:
66
66
  # config/data_pitcher.yml
67
67
  data_pitcher:
68
68
  - spreadsheet_key: 1QlOBVmsEau8EupE5Kj7AqoHLQTjInoq0GpwPkW7_WdU
69
+ worksheet_title: Sheet2 # Optional. Using the first worksheet if omitted
69
70
  sql_path: <%= Rails.root.join('lib', 'sqls', 'conversion_rates.sql') %>
70
71
  ```
71
72
 
@@ -82,7 +83,8 @@ $ bundle exec rake data_pitcher:export:run
82
83
  Or, you can manually execute sending data programmatically as follows:
83
84
 
84
85
  ```ruby
85
- DataPitcher::Spreadsheet.new('<SPREADSHEET KEY>').replace_worksheet_with_query('<SQL QUERY STRING>')
86
+ DataPitcher::Spreadsheet.new('<SPREADSHEET KEY>').replace_worksheet_with_query('<SQL QUERY STRING>') # When using the first worksheet
87
+ DataPitcher::Spreadsheet.new('<SPREADSHEET KEY>', '<WORKSHEET TITLE>').replace_worksheet_with_query('<SQL QUERY STRING>')
86
88
  ```
87
89
 
88
90
  ### (Optionally) Check YAML definition
@@ -6,17 +6,23 @@ module DataPitcher
6
6
  @yaml_path = yaml_path
7
7
  end
8
8
 
9
- def commands
9
+ def command_hashes
10
10
  # TODO: 例外処理
11
11
  YAML.load(ERB.new(File.read(@yaml_path)).result)['data_pitcher']
12
12
  end
13
13
 
14
14
  def execute(dry_run: true)
15
- commands.each.with_index(1) do |command, index|
15
+ command_hashes.each.with_index(1) do |command_hash, index|
16
16
  begin
17
17
  result = false
18
18
  elapsed_time = Benchmark.realtime do
19
- result = DataPitcher::Command.new(command['spreadsheet_key'], command['sql_path'], dry_run: dry_run, index: index).execute
19
+ result = DataPitcher::Command.new(
20
+ spreadsheet_key: command_hash['spreadsheet_key'],
21
+ worksheet_title: command_hash['worksheet_title'],
22
+ sql_path: command_hash['sql_path'],
23
+ dry_run: dry_run,
24
+ index: index
25
+ ).execute
20
26
  end
21
27
  if result
22
28
  puts "##{index} command: sending completed. #{elapsed_time}s"
@@ -1,7 +1,8 @@
1
1
  module DataPitcher
2
2
  class Command
3
- def initialize(spreadsheet_key, sql_path, dry_run: true, index: 1)
3
+ def initialize(spreadsheet_key:, worksheet_title: nil, sql_path:, dry_run: true, index: 1)
4
4
  @spreadsheet_key = spreadsheet_key
5
+ @worksheet_title = worksheet_title
5
6
  @sql_path = sql_path
6
7
  @dry_run = dry_run
7
8
  @index = index
@@ -30,7 +31,7 @@ module DataPitcher
30
31
  end
31
32
 
32
33
  def spreadsheet
33
- @spreadsheet ||= DataPitcher::Spreadsheet.new(@spreadsheet_key)
34
+ @spreadsheet ||= DataPitcher::Spreadsheet.new(@spreadsheet_key, @worksheet_title)
34
35
  end
35
36
 
36
37
  def executor
@@ -45,6 +46,7 @@ module DataPitcher
45
46
  <<-EOS
46
47
  ##{@index} command
47
48
  spreadsheet_key: #{@spreadsheet_key}
49
+ worksheet_title: #{@worksheet_title || '(first worksheet)'}
48
50
  valid?: #{spreadsheet.valid?}
49
51
  sql_path: #{@sql_path}
50
52
  valid?: #{executor.valid?}
@@ -4,8 +4,9 @@ module DataPitcher
4
4
  class Spreadsheet
5
5
  BATCH_SIZE = 1000
6
6
 
7
- def initialize(spreadsheet_key)
7
+ def initialize(spreadsheet_key, worksheet_title = nil)
8
8
  @spreadsheet_key = spreadsheet_key
9
+ @worksheet_title = worksheet_title
9
10
  end
10
11
 
11
12
  def spreadsheet
@@ -13,8 +14,12 @@ module DataPitcher
13
14
  end
14
15
 
15
16
  def worksheet
16
- # NOTE: DataPitcher will access first sheet only
17
- @worksheet ||= spreadsheet.worksheets.first
17
+ @worksheet ||=
18
+ if @worksheet_title
19
+ spreadsheet.worksheet_by_title(@worksheet_title)
20
+ else
21
+ spreadsheet.worksheets.first
22
+ end
18
23
  end
19
24
 
20
25
  def clear_sheet
@@ -1,3 +1,3 @@
1
1
  module DataPitcher
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_pitcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro Nishimi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  version: '0'
99
99
  requirements: []
100
100
  rubyforge_project:
101
- rubygems_version: 2.5.2
101
+ rubygems_version: 2.6.13
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Data Pitcher throw your pesisted data to Google Spreadsheet.