filename 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a1de0199d6e088c7d3d5f25ccec790fe5d6a183
4
+ data.tar.gz: 9ca727622fa431fbe294459fc8d2b717e0b94c77
5
+ SHA512:
6
+ metadata.gz: 7e4b09f62796ac810a689861558e89b71e7dc97a2b9a91e4101dd4c50093eab8823e686ec957f455dd93be4852564935a3f65bf8672290a6ed74a8cc2e2a88b6
7
+ data.tar.gz: ae6b3e89a1e4de2bc179437a579a1b1850d1792d9216f7179d9fa631b1a1d291d71241d98c994a7dde4cbb1aca30b75012556a0e728262163894a75ca785e639
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile CHANGED
@@ -1,13 +1,4 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
1
+ source 'https://rubygems.org'
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "rspec", ">= 2.5.0"
10
- gem "bundler", "~> 1.0.0"
11
- gem "jeweler", "~> 1.5.2"
12
- gem "rcov", ">= 0"
13
- end
3
+ # Specify your gem's dependencies in filename.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -188,6 +188,19 @@ We can use the variables in proc object for an option :format.
188
188
  In the above example we prepare the instance variable "@a = 3"
189
189
  and use @a in proc object specified by an option :format.
190
190
 
191
+ ### Two filters: :before and :after
192
+
193
+ Before and after all generation processes, we can filter basename without extension.
194
+
195
+ require 'filename'
196
+ FileName.create("name.txt",
197
+ :filter => {
198
+ :before => lambda { |basename| "before_" + basename },
199
+ :after => lambda { |basename| basename + "_after" }
200
+ },
201
+ :add => :prohibit, :path => :relative)
202
+ # => "before_name_after.txt"
203
+
191
204
  ### Options of FileName#new, FileName#create, and FileName.create
192
205
 
193
206
  If we set options of FileName#create to FileName#new,
data/Rakefile CHANGED
@@ -1,50 +1,11 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'rake'
11
-
12
- require 'jeweler'
13
- Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
- gem.name = "filename"
16
- gem.homepage = "http://github.com/ytaka/filename"
17
- gem.license = "GPLv3"
18
- gem.summary = "Filename generator"
19
- gem.description = "Create filename with sequential number or time string that is not duplicated."
20
- gem.email = "d@ytak.info"
21
- gem.authors = ["Takayuki YAMAGUCHI"]
22
- # Include your dependencies below. Runtime dependencies are required when using your gem,
23
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
- # gem.add_development_dependency 'rspec', '> 1.2.3'
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
1
+ require "bundler/gem_tasks"
28
2
 
29
- require 'rspec/core'
30
- require 'rspec/core/rake_task'
31
- RSpec::Core::RakeTask.new(:spec) do |spec|
32
- spec.pattern = FileList['spec/**/*_spec.rb']
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.pattern = 'spec/**/*_spec.rb'
33
6
  end
34
7
 
35
- RSpec::Core::RakeTask.new(:rcov) do |spec|
36
- spec.pattern = 'spec/**/*_spec.rb'
37
- spec.rcov = true
38
- end
39
-
40
- task :default => :spec
41
-
42
- require 'rake/rdoctask'
43
- Rake::RDocTask.new do |rdoc|
44
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
-
46
- rdoc.rdoc_dir = 'rdoc'
47
- rdoc.title = "filename #{version}"
48
- rdoc.rdoc_files.include('README*')
49
- rdoc.rdoc_files.include('lib/**/*.rb')
8
+ require "yard"
9
+ YARD::Rake::YardocTask.new do |t|
10
+ t.files = ["lib/**/*.rb", "lib/**/ext/**/*.c"]
50
11
  end
@@ -1,70 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'filename/version'
5
5
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{filename}
8
- s.version = "0.1.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "filename"
8
+ spec.version = FileName::VERSION
9
+ spec.authors = ["Takayuki YAMAGUCHI"]
10
+ spec.email = ["d@ytak.info"]
11
+ spec.description = "File name generator with sequential number or time string"
12
+ spec.summary = "Create filename with sequential number or time string that is not duplicated."
13
+ spec.homepage = ""
14
+ spec.license = "GPLv3"
9
15
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Takayuki YAMAGUCHI"]
12
- s.date = %q{2011-04-15}
13
- s.description = %q{Create filename with sequential number or time string that is not duplicated.}
14
- s.email = %q{d@ytak.info}
15
- s.executables = ["filename-create"]
16
- s.extra_rdoc_files = [
17
- "LICENSE.txt",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".document",
22
- ".rspec",
23
- "Gemfile",
24
- "Gemfile.lock",
25
- "LICENSE.txt",
26
- "README.md",
27
- "Rakefile",
28
- "VERSION",
29
- "bin/filename-create",
30
- "filename.gemspec",
31
- "lib/filename.rb",
32
- "spec/cache_spec.rb",
33
- "spec/configuration_spec.rb",
34
- "spec/filename_spec.rb",
35
- "spec/spec_helper.rb"
36
- ]
37
- s.homepage = %q{http://github.com/ytaka/filename}
38
- s.licenses = ["GPLv3"]
39
- s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.7.2}
41
- s.summary = %q{Filename generator}
42
- s.test_files = [
43
- "spec/cache_spec.rb",
44
- "spec/configuration_spec.rb",
45
- "spec/filename_spec.rb",
46
- "spec/spec_helper.rb"
47
- ]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
48
20
 
49
- if s.respond_to? :specification_version then
50
- s.specification_version = 3
51
-
52
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_development_dependency(%q<rspec>, [">= 2.5.0"])
54
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
55
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
56
- s.add_development_dependency(%q<rcov>, [">= 0"])
57
- else
58
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
62
- end
63
- else
64
- s.add_dependency(%q<rspec>, [">= 2.5.0"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
67
- s.add_dependency(%q<rcov>, [">= 0"])
68
- end
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "yard"
69
25
  end
70
-
@@ -1,3 +1,4 @@
1
+ require "filename/version"
1
2
  autoload :FileUtils, 'fileutils'
2
3
 
3
4
  #
@@ -46,6 +47,9 @@ class FileName
46
47
  # which is set by an option :format.
47
48
  # If we set { :a => 1, :b => 2 } for :data option,
48
49
  # we can use @a and @b in proc object set by :format option.
50
+ #
51
+ # [:filter]
52
+ # We specify filters :before and after for basename without suffix, which is got by File.basename(path, ".*")
49
53
  #
50
54
  # [:extension]
51
55
  # Default value of the option of FileName#create.
@@ -65,7 +69,8 @@ class FileName
65
69
  opts = {}
66
70
  end
67
71
  path = File.join(basepath, *rest)
68
- if opts[:path] == :relative
72
+ @relative_path_p = (opts[:path] == :relative)
73
+ if @relative_path_p
69
74
  @basepath = path
70
75
  else
71
76
  @basepath = File.expand_path(path)
@@ -93,23 +98,28 @@ class FileName
93
98
  @data.instance_variable_set("@#{key}", val)
94
99
  end
95
100
  end
101
+ @filter = opts[:filter] || {}
96
102
  end
97
103
 
98
- def get_basepath(extension = nil)
104
+ def get_basepath(basepath, extension = nil)
99
105
  if extension
100
106
  extension = '.' + extension unless extension[0] == '.'
101
- oldext = File.extname(@basepath)
107
+ oldext = File.extname(basepath)
102
108
  if oldext.size > 0
103
- @basepath.sub(Regexp.new("\\#{oldext}$"), extension)
109
+ basepath.sub(Regexp.new("\\#{oldext}$"), extension)
104
110
  else
105
- @basepath + extension
111
+ basepath + extension
106
112
  end
107
113
  else
108
- @basepath
114
+ basepath
109
115
  end
110
116
  end
111
117
  private :get_basepath
112
118
 
119
+ def relative_path?
120
+ @relative_path_p
121
+ end
122
+
113
123
  def create_time_addition(t)
114
124
  case @format
115
125
  when String
@@ -218,9 +228,23 @@ class FileName
218
228
  end
219
229
  private :write_file
220
230
 
231
+ def filter_exec(filter, path)
232
+ dir, basename = File.split(path)
233
+ extname = File.extname(basename)
234
+ basename_new = filter.call(basename.sub(/#{extname}$/, "")) + extname
235
+ if relative_path? && dir == "."
236
+ basename_new
237
+ else
238
+ File.join(dir, basename_new)
239
+ end
240
+ end
241
+ private :filter_exec
242
+
221
243
  # The options are following:
222
244
  # [:extension (String of extension)]
223
245
  # If we want to change extension, we set the value of the option.
246
+ # Note that if we specify "txt" as :extension option, generated filesame is the format "SOME_STRING.txt";
247
+ # that is, this method adds "." + (specified extension).
224
248
  #
225
249
  # [:add (:always, :auto, or :prohibit)]
226
250
  # We specify if the additional part is used.
@@ -238,7 +262,11 @@ class FileName
238
262
  # If the value is :write and the file does not exist, we create an empty file.
239
263
  # If the value is nil, we do nothing.
240
264
  def create(opts = {})
241
- base = get_basepath(get_option_create(opts, :extension))
265
+ basepath = @basepath
266
+ if @filter[:before]
267
+ basepath = filter_exec(@filter[:before], basepath)
268
+ end
269
+ base = get_basepath(basepath, get_option_create(opts, :extension))
242
270
  opt_add = get_option_create(opts, :add)
243
271
  if addition = get_addition(opt_add, base)
244
272
  path = add_addition(base, addition)
@@ -253,6 +281,9 @@ class FileName
253
281
  else
254
282
  path = base
255
283
  end
284
+ if @filter[:after]
285
+ path = filter_exec(@filter[:after], path)
286
+ end
256
287
  create_directory(path, get_option_create(opts, :directory))
257
288
  write_file(path, get_option_create(opts, :file))
258
289
  path
@@ -0,0 +1,3 @@
1
+ class FileName
2
+ VERSION = "0.1.1"
3
+ end
@@ -180,6 +180,23 @@ describe FileName do
180
180
  FileName.create('abc', 'def', 'ghi', :path => :relative, :add => :prohibit).should == 'abc/def/ghi'
181
181
  end
182
182
 
183
+ it "should execute before filter" do
184
+ FileName.create("name.txt", :filter => { :before => lambda { |basename| basename + "_before" } }, :add => :prohibit, :path => :relative).should == "name_before.txt"
185
+ end
186
+
187
+ it "should execute after filter" do
188
+ FileName.create("name.txt", :filter => { :after => lambda { |basename| basename + "_after" } }, :add => :prohibit, :path => :relative).should == "name_after.txt"
189
+ end
190
+
191
+ it "should execute before and after filters" do
192
+ FileName.create("name.txt",
193
+ :filter => {
194
+ :before => lambda { |basename| "before_" + basename },
195
+ :after => lambda { |basename| basename + "_after" }
196
+ },
197
+ :add => :prohibit, :path => :relative).should == "before_name_after.txt"
198
+ end
199
+
183
200
  context "when we set the default options of FileName#create" do
184
201
  NUMBER_TEST_REPEAT = 3
185
202
 
metadata CHANGED
@@ -1,118 +1,119 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: filename
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Takayuki YAMAGUCHI
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-04-15 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rspec
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.5.0
23
- type: :development
24
- prerelease: false
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
27
14
  name: bundler
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
31
17
  - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 1.0.0
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
34
20
  type: :development
35
21
  prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: jeweler
39
- requirement: &id003 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
42
24
  - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 1.5.2
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
45
48
  type: :development
46
49
  prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rcov
50
- requirement: &id004 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
56
62
  type: :development
57
63
  prerelease: false
58
- version_requirements: *id004
59
- description: Create filename with sequential number or time string that is not duplicated.
60
- email: d@ytak.info
61
- executables:
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: File name generator with sequential number or time string
70
+ email:
71
+ - d@ytak.info
72
+ executables:
62
73
  - filename-create
63
74
  extensions: []
64
-
65
- extra_rdoc_files:
66
- - LICENSE.txt
67
- - README.md
68
- files:
69
- - .document
70
- - .rspec
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
71
78
  - Gemfile
72
- - Gemfile.lock
73
79
  - LICENSE.txt
74
80
  - README.md
75
81
  - Rakefile
76
- - VERSION
77
82
  - bin/filename-create
78
83
  - filename.gemspec
79
84
  - lib/filename.rb
85
+ - lib/filename/version.rb
80
86
  - spec/cache_spec.rb
81
87
  - spec/configuration_spec.rb
82
88
  - spec/filename_spec.rb
83
89
  - spec/spec_helper.rb
84
- homepage: http://github.com/ytaka/filename
85
- licenses:
90
+ homepage: ''
91
+ licenses:
86
92
  - GPLv3
93
+ metadata: {}
87
94
  post_install_message:
88
95
  rdoc_options: []
89
-
90
- require_paths:
96
+ require_paths:
91
97
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- hash: -1890861991035807209
98
- segments:
99
- - 0
100
- version: "0"
101
- required_rubygems_version: !ruby/object:Gem::Requirement
102
- none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- version: "0"
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
107
108
  requirements: []
108
-
109
109
  rubyforge_project:
110
- rubygems_version: 1.7.2
110
+ rubygems_version: 2.0.3
111
111
  signing_key:
112
- specification_version: 3
113
- summary: Filename generator
114
- test_files:
112
+ specification_version: 4
113
+ summary: Create filename with sequential number or time string that is not duplicated.
114
+ test_files:
115
115
  - spec/cache_spec.rb
116
116
  - spec/configuration_spec.rb
117
117
  - spec/filename_spec.rb
118
118
  - spec/spec_helper.rb
119
+ has_rdoc:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,28 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.5.2)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.8.7)
11
- rcov (0.9.9)
12
- rspec (2.5.0)
13
- rspec-core (~> 2.5.0)
14
- rspec-expectations (~> 2.5.0)
15
- rspec-mocks (~> 2.5.0)
16
- rspec-core (2.5.1)
17
- rspec-expectations (2.5.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.5.0)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- bundler (~> 1.0.0)
26
- jeweler (~> 1.5.2)
27
- rcov
28
- rspec (>= 2.5.0)
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0