Checked 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,98 +1,104 @@
1
1
 
2
2
  module Checked
3
- class Clean
4
- module Mods
5
- module Strings
6
-
7
- def self.apply? d
8
- d.target.is_a?(String) ||
9
- d.target.is_a?(StringIO)
10
- end
11
-
12
- def self.on_apply d
13
- case d.target
14
- when StringIO
15
- d.target.rewind
16
- d.target= d.target.readlines
17
- else
18
- # Do nothing.
19
- end
20
- end
21
-
22
- def file_names matcher
23
- strip.split.select { |word| word[matcher] }
24
- end
25
-
26
- def file_names_by_ext ext
27
- names = file_names(ext)
28
- bases = names.map { |s|
29
- s.sub(%r!#{ext}$!, '')
30
- }
31
-
32
- names.zip bases
33
- end
34
-
35
- def shell
36
- target
37
- .strip
38
- .split("\n")
39
- .map(&:strip)
40
- .reject { |line| line.empty? }
41
- .join(' && ')
42
- end
43
-
44
- def chop_ext
45
- target.sub /\.[^\.]+$/, ''
46
- end
47
-
48
- def ruby_name
49
- c = ::Checked::Clean.new( File.basename( target ) )
50
- c.< :chop_rb
51
- c.target
52
- end
53
-
54
- def chop_rb
55
- target.sub %r!\.rb$!, ''
56
- end
57
-
58
- def chop_slash_r
59
- target.gsub "\r", ''
60
- end
61
-
62
- def os_stardard
63
- chop_slash_r.strip
64
- end
65
-
66
- def file_names matcher
67
- strip.split.select { |word| word[matcher] }
68
- end
69
-
70
- def file_names_by_ext ext
71
- names = file_names(ext)
72
- bases = names.map { |s|
73
- s.sub(%r!#{ext}$!, '')
74
- }
75
-
76
- names.zip bases
77
- end
78
-
79
- def to_single
80
- target.gsub( /s\Z/, '' )
81
- end
82
-
83
- def to_plural
84
- target.to_single + 's'
85
- end
86
-
87
- def to_class_name
88
- target.split('_').map(&:capitalize).join('_')
89
- end
90
-
91
- def to_camel_case
92
- target.split('_').map(&:capitalize).join
93
- end
94
-
95
- end # === module Strings
96
- end # === module Mods
97
- end # === class Clean
3
+ class Clean
4
+ module Mods
5
+ module Strings
6
+
7
+ def self.apply? d
8
+ d.target.is_a?(String) ||
9
+ d.target.is_a?(StringIO)
10
+ end
11
+
12
+ def self.on_apply d
13
+ case d.target
14
+ when StringIO
15
+ d.target.rewind
16
+ d.target= d.target.readlines
17
+ else
18
+ # Do nothing.
19
+ end
20
+ end
21
+
22
+ def untar
23
+ target
24
+ .sub(/\.tar\.gz$/, '')
25
+ .sub(/\.tar/, '')
26
+ end
27
+
28
+ def file_names matcher
29
+ target.strip.split.select { |word| word[matcher] }
30
+ end
31
+
32
+ def file_names_by_ext ext
33
+ names = file_names(ext)
34
+ bases = names.map { |s|
35
+ s.sub(%r!#{ext}$!, '')
36
+ }
37
+
38
+ names.zip bases
39
+ end
40
+
41
+ def shell
42
+ target
43
+ .strip
44
+ .split("\n")
45
+ .map(&:strip)
46
+ .reject { |line| line.empty? }
47
+ .join(' && ')
48
+ end
49
+
50
+ def chop_ext
51
+ target.sub /\.[^\.]+$/, ''
52
+ end
53
+
54
+ def ruby_name
55
+ c = ::Checked::Clean.new( File.basename( target ) )
56
+ c.< :chop_rb
57
+ c.target
58
+ end
59
+
60
+ def chop_rb
61
+ target.sub %r!\.rb$!, ''
62
+ end
63
+
64
+ def chop_slash_r
65
+ target.gsub "\r", ''
66
+ end
67
+
68
+ def os_stardard
69
+ chop_slash_r.strip
70
+ end
71
+
72
+ def file_names matcher
73
+ strip.split.select { |word| word[matcher] }
74
+ end
75
+
76
+ def file_names_by_ext ext
77
+ names = file_names(ext)
78
+ bases = names.map { |s|
79
+ s.sub(%r!#{ext}$!, '')
80
+ }
81
+
82
+ names.zip bases
83
+ end
84
+
85
+ def to_single
86
+ target.gsub( /s\Z/, '' )
87
+ end
88
+
89
+ def to_plural
90
+ target.to_single + 's'
91
+ end
92
+
93
+ def to_class_name
94
+ target.split('_').map(&:capitalize).join('_')
95
+ end
96
+
97
+ def to_camel_case
98
+ target.split('_').map(&:capitalize).join
99
+ end
100
+
101
+ end # === module Strings
102
+ end # === module Mods
103
+ end # === class Clean
98
104
  end # === module Checked
@@ -38,6 +38,9 @@ module File_Addresses
38
38
  self.target= target.strip
39
39
  string!
40
40
  not_empty!
41
+ if target[%r!([^a-zA-Z0-9\.\_\-\/~]+)!]
42
+ fail! "...has invalid characters: #{$1.inspect}"
43
+ end
41
44
  end
42
45
 
43
46
  def file_read!
@@ -1,3 +1,3 @@
1
1
  module Checked
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,3 +1,15 @@
1
+ describe "Demand file_address!" do
2
+
3
+ it 'must fail if string has control characters' do
4
+ lambda {
5
+ d = Checked::Demand.new(File.expand_path "~/\tbashee")
6
+ d.<< :file_address!
7
+ }.should.raise(Checked::Demand::Failed)
8
+ .message.should.match %r!has invalid characters: !
9
+ end
10
+
11
+ end # === describe Demand file_address!
12
+
1
13
 
2
14
  describe "Demand not_dir!" do
3
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Checked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-13 00:00:00.000000000Z
12
+ date: 2011-10-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &17606640 !ruby/object:Gem::Requirement
16
+ requirement: &9627280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *17606640
24
+ version_requirements: *9627280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bacon
27
- requirement: &17606040 !ruby/object:Gem::Requirement
27
+ requirement: &9605340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *17606040
35
+ version_requirements: *9605340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: Bacon_Colored
38
- requirement: &17605440 !ruby/object:Gem::Requirement
38
+ requirement: &9601420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *17605440
46
+ version_requirements: *9601420
47
47
  description: ! "\n Various DSLs to clean, question (Ask), and validate (Demand)
48
48
  your objects,\n their classes (data types), and their properties.\n "
49
49
  email: