defoker 0.0.6 → 0.0.7

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: 34c984f9722b99072fdbb1315c5d155e581d0deb
4
- data.tar.gz: 988dd38c8690bd0381f215b5c795f006a395b7a4
3
+ metadata.gz: 7a5f9afbcf61ccde102b125beaac16433ce3c251
4
+ data.tar.gz: 889fa48fe18e9c56fb152120dce25fd30c7254e0
5
5
  SHA512:
6
- metadata.gz: d67be9576e0ea9f93a1dde73fa5b85b85c7639760b49d4e507c5c6ea71a8c829c6b15e8d998adde2e495d218ca34c2c58e17093e5a1c58b5073117057dbb29ef
7
- data.tar.gz: 0332c256d22c4f09b79a1579451a914b065d0b5ec21eab62d3f4dc01f0874c9d796bbcaf908ea7327b004f2787855285018b66e13816733fff20ab5305895851
6
+ metadata.gz: 64da091ba8e210d74c2a063728f8d021b887ac7e2cb05c7930b3944bfb020496b6088dc63cf15eb430d944ff75d598b7d0001cf846301201a79954772182fccf
7
+ data.tar.gz: d01a268dc1a16947af3a0f777828213e2e345c7d0bf35ac082422f30dfb19ef3da091d3e6cba4ae88b95b2b734012061c9ec8b714fa1341b5bf853d8d92d9833
data/README.md CHANGED
@@ -373,7 +373,89 @@ $ tree
373
373
  ┗ template.txt
374
374
  ~~~
375
375
 
376
+ ### mv_month
377
+ move daily folders to monthly folder.
378
+
379
+ * Before move
380
+
381
+ ~~~bash
382
+ $ tree
383
+ ┣ 20141006_hige
384
+ ┣ 20141007_hoge
385
+ ┣ 20141106_hige
386
+ ┣ 20141107_hoge
387
+ ┣ 20141206_hige
388
+ ┣ 20141207_hoge
389
+ ┣ 20150106_hige
390
+ ┣ 20150107_hoge
391
+ ┗ invalid_folder
392
+ ~~~
393
+
394
+ * Excute mv_month
395
+
396
+ ~~~bash
397
+ $ defoker mv_month
398
+ $ tree
399
+ ┣ 201410
400
+ ┃ ┣ 06_hige
401
+ ┃ ┗ 07_hoge
402
+ ┣ 201411
403
+ ┃ ┣ 06_hige
404
+ ┃ ┗ 07_hoge
405
+ ┣ 201412
406
+ ┃ ┣ 06_hige
407
+ ┃ ┗ 07_hoge
408
+ ┣ 201501
409
+ ┃ ┣ 06_hige
410
+ ┃ ┗ 07_hoge
411
+ ┗ invalid_folder
412
+ ~~~
413
+
414
+ ### mv_year
415
+ move monthly folders to yearly folder.
416
+
417
+ * Before move
418
+
419
+ ~~~bash
420
+ $ tree
421
+ ┣ 201410
422
+ ┃ ┣ 06_hige
423
+ ┃ ┗ 07_hoge
424
+ ┣ 201411
425
+ ┃ ┣ 06_hige
426
+ ┃ ┗ 07_hoge
427
+ ┣ 201412
428
+ ┃ ┣ 06_hige
429
+ ┃ ┗ 07_hoge
430
+ ┣ 201501
431
+ ┃ ┣ 06_hige
432
+ ┃ ┗ 07_hoge
433
+ ┗ invalid_folder
434
+ ~~~
435
+
436
+ * Excute mv_month
437
+
438
+ ~~~bash
439
+ $ defoker mv_year
440
+ ┣ 2014
441
+ ┃ ┣ 10
442
+ ┃ ┃ ┣ 06_hige
443
+ ┃ ┃ ┗ 07_hoge
444
+ ┃ ┣ 11
445
+ ┃ ┃ ┣ 06_hige
446
+ ┃ ┃ ┗ 07_hoge
447
+ ┃ ┗ 12
448
+ ┃   ┣ 06_hige
449
+ ┃   ┗ 07_hoge
450
+ ┣ 2015
451
+ ┃ ┗ 01
452
+ ┃ ┣ 06_hige
453
+ ┃ ┗ 07_hoge
454
+ ┗ invalid_folder
455
+ ~~~
456
+
376
457
  ## History
458
+ * version 0.0.7 : Add mv_month, mv_year commands.
377
459
  * version 0.0.6 : Add callback in Defokerfile.
378
460
  * version 0.0.5 : Fix typo in Defokerfile Template.
379
461
  * version 0.0.4 : Add init/rule command for rule-output.
data/bin/defoker CHANGED
@@ -109,12 +109,31 @@ module Defoker
109
109
  exit(false)
110
110
  end
111
111
 
112
+ desc 'mv_month', 'move daily folders to monthly folder'
113
+ def mv_month
114
+ Defoker::Core.mv_month
115
+ exit(true)
116
+ rescue => e
117
+ STDERR.puts(e.backtrace)
118
+ exit(false)
119
+ end
120
+
121
+ desc 'mv_year', 'move monthly folders to yearly folder'
122
+ def mv_year
123
+ Defoker::Core.mv_year
124
+ exit(true)
125
+ rescue => e
126
+ STDERR.puts(e.backtrace)
127
+ exit(false)
128
+ end
129
+
112
130
  desc 'version', 'version'
113
131
  def version
114
132
  p Defoker::VERSION
115
133
  end
116
134
 
117
135
  private
136
+
118
137
  def defoker_core_single_caller(method_name)
119
138
  additional = options[:additional] ? options[:additional] : ''
120
139
  dir = Defoker::Core.send(method_name, additional: additional)
@@ -1,3 +1,3 @@
1
1
  module Defoker
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/defoker_core.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'date_base_name'
3
3
  require 'date'
4
+ require 'pathname'
4
5
  require 'defoker_dsl'
5
6
  require 'defoker_dsl_model'
6
7
 
@@ -26,9 +27,9 @@ base ''
26
27
  # comment out following lines and edit your logic.
27
28
 
28
29
  # callback ->(dir) {
29
- # p dir
30
- # # create File in your dir
31
- # File.open("\#{dir}/some_template_file.txt", "w:utf-8") { |e|e.puts 'some template'}
30
+ # p dir
31
+ # # create File in your dir
32
+ # File.open("\#{dir}/some_template_file.txt", "w:utf-8") { |e|e.puts 'some template'}
32
33
  # }
33
34
  EOS
34
35
 
@@ -154,6 +155,30 @@ base ''
154
155
  [dir, callback]
155
156
  end
156
157
 
158
+ # Move YYYYMMDD_somename format folder to YYYYMM folder.
159
+ #
160
+ def self.mv_month
161
+ Dir.glob('*/').each do |dir|
162
+ next unless dir =~ %r(^[0-9]{8}(_.*)*/$)
163
+ month_dir = dir[0, 6]
164
+ FileUtils.mkdir_p(month_dir) unless Dir.exist?(month_dir)
165
+ day_dir = dir[6..-1]
166
+ FileUtils.mv(dir, File.join(month_dir, day_dir))
167
+ end
168
+ end
169
+
170
+ # Move YYYYMM_somename format folder to YYYY folder.
171
+ #
172
+ def self.mv_year
173
+ Dir.glob('*/').each do |dir|
174
+ next unless dir =~ %r(^[0-9]{6}(_.*)*/$)
175
+ year_dir = dir[0, 4]
176
+ FileUtils.mkdir_p(year_dir) unless Dir.exist?(year_dir)
177
+ month_dir = dir[4..-1]
178
+ FileUtils.mv(dir, File.join(year_dir, month_dir))
179
+ end
180
+ end
181
+
157
182
  def self.read_dsl
158
183
  dsl = Defoker::Dsl.new
159
184
  unless File.exist?(DEFOKERFILE_PATH)
@@ -737,4 +737,126 @@ base "hoge"
737
737
  end
738
738
  end
739
739
  end
740
+
741
+ context :mv_month do
742
+ DEFOKER_MV_MONTH_TMP_DIR = 'tmp_mv_month'
743
+
744
+ cases = [
745
+ {
746
+ case_no: 1,
747
+ case_title: 'valid case',
748
+ setup_dirs: %w(20141006_hige 20141007_hoge 20141106_hige 20141107_hoge 20141206_hige 20141207_hoge 20150106_hige 20150107_hoge invalid_folder),
749
+ expected: [
750
+ '201410/06_hige',
751
+ '201410/07_hoge',
752
+ '201411/06_hige',
753
+ '201411/07_hoge',
754
+ '201412/06_hige',
755
+ '201412/07_hoge',
756
+ '201501/06_hige',
757
+ '201501/07_hoge',
758
+ 'invalid_folder'
759
+ ]
760
+ }
761
+ ]
762
+
763
+ cases.each do |c|
764
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
765
+ begin
766
+ case_before c
767
+
768
+ # -- given --
769
+ # nothing
770
+
771
+ # -- when --
772
+ Defoker::Core.mv_month
773
+
774
+ # -- then --
775
+ c[:expected].each do |dir|
776
+ existence = Dir.exist?(dir)
777
+ expect(existence).to be_true
778
+ end
779
+ ensure
780
+ case_after c
781
+ end
782
+ end
783
+
784
+ def case_before(c)
785
+ Dir.mkdir(DEFOKER_MV_MONTH_TMP_DIR) unless Dir.exist? DEFOKER_MV_MONTH_TMP_DIR
786
+ Dir.chdir(DEFOKER_MV_MONTH_TMP_DIR)
787
+ FileUtils.mkdir_p(c[:setup_dirs])
788
+ end
789
+
790
+ def case_after(c) # rubocop:disable UnusedMethodArgument
791
+ Dir.chdir('../')
792
+ FileUtils.rm_rf(DEFOKER_MV_MONTH_TMP_DIR) if Dir.exist? DEFOKER_MV_MONTH_TMP_DIR
793
+ end
794
+ end
795
+ end
796
+
797
+ context :mv_year do
798
+ DEFOKER_MV_YEAR_TMP_DIR = 'tmp_mv_year'
799
+
800
+ cases = [
801
+ {
802
+ case_no: 1,
803
+ case_title: 'valid case',
804
+ setup_dirs: %w(
805
+ 201410/06_hige
806
+ 201410/07_hoge
807
+ 201411/06_hige
808
+ 201411/07_hoge
809
+ 201412/06_hige
810
+ 201412/07_hoge
811
+ 201501/06_hige
812
+ 201501/07_hoge
813
+ invalid_folde
814
+ ),
815
+ expected: %w(
816
+ 2014/10/06_hige
817
+ 2014/10/07_hoge
818
+ 2014/11/06_hige
819
+ 2014/11/07_hoge
820
+ 2014/12/06_hige
821
+ 2014/12/07_hoge
822
+ 2015/01/06_hige
823
+ 2015/01/07_hoge
824
+ invalid_folde
825
+ )
826
+ }
827
+ ]
828
+
829
+ cases.each do |c|
830
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
831
+ begin
832
+ case_before c
833
+
834
+ # -- given --
835
+ # nothing
836
+
837
+ # -- when --
838
+ Defoker::Core.mv_year
839
+
840
+ # -- then --
841
+ c[:expected].each do |dir|
842
+ existence = Dir.exist?(dir)
843
+ expect(existence).to be_true
844
+ end
845
+ ensure
846
+ case_after c
847
+ end
848
+ end
849
+
850
+ def case_before(c)
851
+ Dir.mkdir(DEFOKER_MV_YEAR_TMP_DIR) unless Dir.exist? DEFOKER_MV_YEAR_TMP_DIR
852
+ Dir.chdir(DEFOKER_MV_YEAR_TMP_DIR)
853
+ FileUtils.mkdir_p(c[:setup_dirs])
854
+ end
855
+
856
+ def case_after(c) # rubocop:disable UnusedMethodArgument
857
+ Dir.chdir('../')
858
+ FileUtils.rm_rf(DEFOKER_MV_YEAR_TMP_DIR) if Dir.exist? DEFOKER_MV_YEAR_TMP_DIR
859
+ end
860
+ end
861
+ end
740
862
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defoker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - tbpgr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler