sugar-high 0.1.8 → 0.2.0
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/VERSION +1 -1
- data/lib/sugar-high/alias.rb +1 -1
- data/lib/sugar-high/file.rb +1 -26
- data/lib/sugar-high/includes.rb +24 -7
- data/lib/sugar-high/path.rb +37 -0
- data/lib/sugar-high/regexp.rb +7 -0
- data/spec/sugar-high/file/file_spec.rb +1 -28
- data/spec/sugar-high/path_spec.rb +53 -0
- data/spec/sugar-high/regexp_spec.rb +8 -0
- data/sugar-high.gemspec +5 -2
- metadata +7 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/sugar-high/alias.rb
CHANGED
@@ -27,7 +27,7 @@ class Module
|
|
27
27
|
options = args[1]
|
28
28
|
end
|
29
29
|
|
30
|
-
raise ArgumentError, "Name of method pattern to alias not specified. Please pass name as either first argument or as :
|
30
|
+
raise ArgumentError, "Name of method pattern to alias not specified. Please pass name as either first argument or as :_before_ or :_after_ option" if !name
|
31
31
|
|
32
32
|
options.delete(:_after_)
|
33
33
|
options.delete(:_before_)
|
data/lib/sugar-high/file.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'sugar-high/blank'
|
2
2
|
require 'sugar-high/arguments'
|
3
|
+
require 'sugar-high/path'
|
3
4
|
|
4
5
|
class File
|
5
6
|
def self.delete! name
|
@@ -150,29 +151,3 @@ class Array
|
|
150
151
|
self.map{|a| a.gsub( /(.*)\//, '').gsub(/\.#{Regexp.escape(ext)}/, '')}
|
151
152
|
end
|
152
153
|
end
|
153
|
-
|
154
|
-
class String
|
155
|
-
def path
|
156
|
-
self.extend PathString
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
module PathString
|
161
|
-
def exists?
|
162
|
-
File.exist? self
|
163
|
-
end
|
164
|
-
|
165
|
-
def up lv
|
166
|
-
('../' * lv) + self
|
167
|
-
end
|
168
|
-
|
169
|
-
def down lv
|
170
|
-
up_dir = Regexp.escape('../')
|
171
|
-
orig = self.clone
|
172
|
-
lv.times do
|
173
|
-
self.gsub! /^#{up_dir}/, ''
|
174
|
-
return self if self == orig
|
175
|
-
end
|
176
|
-
self
|
177
|
-
end
|
178
|
-
end
|
data/lib/sugar-high/includes.rb
CHANGED
@@ -1,9 +1,26 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
class Module
|
4
|
+
def includes *module_names
|
5
|
+
module_names.flatten.each do |name|
|
6
|
+
class_eval %{
|
7
|
+
include #{name.to_s.camelize}
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def extends *module_names
|
13
|
+
module_names.flatten.each do |name|
|
14
|
+
class_eval %{
|
15
|
+
extend #{name.to_s.camelize}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def includes_and_extends *module_names
|
21
|
+
includes module_names
|
22
|
+
extends module_names
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :extends_and_includes, :includes_and_extends
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class String
|
2
|
+
def path
|
3
|
+
self.extend PathString
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
module PathString
|
8
|
+
def exists?
|
9
|
+
File.exist? self
|
10
|
+
end
|
11
|
+
|
12
|
+
def file?
|
13
|
+
File.file? self
|
14
|
+
end
|
15
|
+
|
16
|
+
def dir?
|
17
|
+
File.directory? self
|
18
|
+
end
|
19
|
+
|
20
|
+
def symlink?
|
21
|
+
File.symlink? self
|
22
|
+
end
|
23
|
+
|
24
|
+
def up lv
|
25
|
+
('../' * lv) + self
|
26
|
+
end
|
27
|
+
|
28
|
+
def down lv
|
29
|
+
up_dir = Regexp.escape('../')
|
30
|
+
orig = self.clone
|
31
|
+
lv.times do
|
32
|
+
self.gsub! /^#{up_dir}/, ''
|
33
|
+
return self if self == orig
|
34
|
+
end
|
35
|
+
self
|
36
|
+
end
|
37
|
+
end
|
data/lib/sugar-high/regexp.rb
CHANGED
@@ -43,33 +43,6 @@ describe "SugarHigh" do
|
|
43
43
|
expr = fixtures_dir + '/*.txt'
|
44
44
|
Dir.glob(expr).file_names('txt').should == ['empty', 'non-empty']
|
45
45
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'String path ext' do
|
49
|
-
describe '#path' do
|
50
|
-
it "should return a String extended with PathString" do
|
51
|
-
path_str = "a/b/c".path
|
52
|
-
path_str.kind_of?(PathString).should be_true
|
53
|
-
path_str.respond_to?(:up).should be_true
|
54
|
-
path_str.respond_to?(:down).should be_true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe 'PathString' do
|
60
|
-
describe '#up' do
|
61
|
-
it "should go up two folder levels" do
|
62
|
-
up_path = "a/b/c".path.up(2)
|
63
|
-
up_path.should == "../../a/b/c"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe '#down' do
|
68
|
-
it "should go down two folder levels" do
|
69
|
-
dwn_path = "../../a/b/c".path.down(2)
|
70
|
-
dwn_path.should == "a/b/c"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
46
|
+
end
|
74
47
|
end
|
75
48
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/path'
|
3
|
+
|
4
|
+
describe 'String path ext' do
|
5
|
+
describe '#path' do
|
6
|
+
it "should return a String extended with PathString" do
|
7
|
+
path_str = "a/b/c".path
|
8
|
+
path_str.kind_of?(PathString).should be_true
|
9
|
+
path_str.respond_to?(:up).should be_true
|
10
|
+
path_str.respond_to?(:down).should be_true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'PathString' do
|
16
|
+
describe '#up' do
|
17
|
+
it "should go up two folder levels" do
|
18
|
+
up_path = "a/b/c".path.up(2)
|
19
|
+
up_path.should == "../../a/b/c"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#down' do
|
24
|
+
it "should go down two folder levels" do
|
25
|
+
dwn_path = "../../a/b/c".path.down(2)
|
26
|
+
dwn_path.should == "a/b/c"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#exists?' do
|
31
|
+
it "should be true that this spec file exist" do
|
32
|
+
"#{__FILE__}".path.exists?.should be_true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#file?' do
|
37
|
+
it "should be true that this spec file exist" do
|
38
|
+
"#{__FILE__}".path.file?.should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#dir?' do
|
43
|
+
it "should be false that this spec file is a directory" do
|
44
|
+
"#{__FILE__}".path.dir?.should be_false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#symlink?' do
|
49
|
+
it "should be false that this spec file is a symlink" do
|
50
|
+
"#{__FILE__}".path.symlink?.should be_false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -15,5 +15,13 @@ describe "SugarHigh" do
|
|
15
15
|
/hello/.to_regexp.should be_a_kind_of Regexp
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
describe 'Array#grep_it' do
|
20
|
+
it "should grep using a regexp" do
|
21
|
+
['hello', 'hello you', 'not you'].grep_it(/hello/).size.should == 2
|
22
|
+
['hello', 'hello you', 'not you'].grep_it('hello').size.should == 2
|
23
|
+
['hello', 'hello you', 'not you'].grep_it(nil).size.should == 3
|
24
|
+
end
|
25
|
+
end
|
18
26
|
end
|
19
27
|
end
|
data/sugar-high.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{sugar-high}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-04}
|
13
13
|
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
|
14
14
|
s.email = %q{kmandrup@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/sugar-high/methods.rb",
|
38
38
|
"lib/sugar-high/module.rb",
|
39
39
|
"lib/sugar-high/not.rb",
|
40
|
+
"lib/sugar-high/path.rb",
|
40
41
|
"lib/sugar-high/regexp.rb",
|
41
42
|
"lib/sugar-high/rspec/configure.rb",
|
42
43
|
"lib/sugar-high/rspec/matchers/have_aliases.rb",
|
@@ -53,6 +54,7 @@ Gem::Specification.new do |s|
|
|
53
54
|
"spec/sugar-high/kind_of_spec.rb",
|
54
55
|
"spec/sugar-high/methods_spec.rb",
|
55
56
|
"spec/sugar-high/module_spec.rb",
|
57
|
+
"spec/sugar-high/path_spec.rb",
|
56
58
|
"spec/sugar-high/regexp_spec.rb",
|
57
59
|
"sugar-high.gemspec"
|
58
60
|
]
|
@@ -73,6 +75,7 @@ Gem::Specification.new do |s|
|
|
73
75
|
"spec/sugar-high/kind_of_spec.rb",
|
74
76
|
"spec/sugar-high/methods_spec.rb",
|
75
77
|
"spec/sugar-high/module_spec.rb",
|
78
|
+
"spec/sugar-high/path_spec.rb",
|
76
79
|
"spec/sugar-high/regexp_spec.rb"
|
77
80
|
]
|
78
81
|
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Kristian Mandrup
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-04 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/sugar-high/methods.rb
|
78
78
|
- lib/sugar-high/module.rb
|
79
79
|
- lib/sugar-high/not.rb
|
80
|
+
- lib/sugar-high/path.rb
|
80
81
|
- lib/sugar-high/regexp.rb
|
81
82
|
- lib/sugar-high/rspec/configure.rb
|
82
83
|
- lib/sugar-high/rspec/matchers/have_aliases.rb
|
@@ -93,6 +94,7 @@ files:
|
|
93
94
|
- spec/sugar-high/kind_of_spec.rb
|
94
95
|
- spec/sugar-high/methods_spec.rb
|
95
96
|
- spec/sugar-high/module_spec.rb
|
97
|
+
- spec/sugar-high/path_spec.rb
|
96
98
|
- spec/sugar-high/regexp_spec.rb
|
97
99
|
- sugar-high.gemspec
|
98
100
|
has_rdoc: true
|
@@ -139,4 +141,5 @@ test_files:
|
|
139
141
|
- spec/sugar-high/kind_of_spec.rb
|
140
142
|
- spec/sugar-high/methods_spec.rb
|
141
143
|
- spec/sugar-high/module_spec.rb
|
144
|
+
- spec/sugar-high/path_spec.rb
|
142
145
|
- spec/sugar-high/regexp_spec.rb
|