sugar-high 0.4.6.4 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +106 -15
- data/VERSION +1 -1
- data/lib/sugar-high/class_ext.rb +2 -2
- data/lib/sugar-high/numeric.rb +4 -0
- data/lib/sugar-high/path.rb +10 -10
- data/spec/sugar-high/class_ext_spec.rb +29 -1
- data/sugar-high.gemspec +2 -2
- metadata +4 -4
data/README.markdown
CHANGED
@@ -89,22 +89,40 @@ File object
|
|
89
89
|
* select_only(type)
|
90
90
|
* select_only!(type)
|
91
91
|
|
92
|
-
### Hash
|
93
|
-
|
94
|
-
* hash_revert : Reverse keys and values
|
95
|
-
|
96
92
|
### File
|
97
93
|
|
98
94
|
* self.blank? and blank? : Is file empty?
|
99
95
|
* self.overwrite : overwrite file with new content (mode = 'w')
|
100
96
|
* self.append : append to existing file with content or create new (mode = 'w+')
|
101
97
|
|
102
|
-
|
103
|
-
|
98
|
+
### File Mutate
|
99
|
+
Adds all File mutation modules to the File class
|
100
|
+
|
101
|
+
### File Mutation
|
102
|
+
|
103
|
+
Various File Mutation modules that can be added to any module or class for some nice benefits. Useful for generators fx.
|
104
|
+
|
105
|
+
Mutation modules within SugarHigh::FileMutate
|
106
|
+
|
107
|
+
* AppendContent
|
108
|
+
* Delete
|
109
|
+
* InsertContent
|
110
|
+
* OverwriteContent
|
111
|
+
* RemoveContent
|
112
|
+
* ReplaceContent
|
113
|
+
|
114
|
+
To add all mutate modules to the File class, simply:
|
115
|
+
|
116
|
+
<pre>File.mutate_ext :all</pre>
|
117
|
+
|
118
|
+
Otherwise, simply specify which ones:
|
104
119
|
|
105
|
-
|
106
|
-
|
107
|
-
|
120
|
+
<pre>File.mutate_ext :append_content, overwrite_content</pre>
|
121
|
+
|
122
|
+
### Hash
|
123
|
+
|
124
|
+
* hash_revert : Reverse keys and values
|
125
|
+
* try_keys : return value of first key that is in Hash
|
108
126
|
|
109
127
|
### Includes
|
110
128
|
|
@@ -117,7 +135,7 @@ PathString:
|
|
117
135
|
|
118
136
|
### Metaclass
|
119
137
|
|
120
|
-
* metaclass : Get the metaclass
|
138
|
+
* metaclass : Get the metaclass, can be used to dynamically add class singleton methods!
|
121
139
|
|
122
140
|
### Methods
|
123
141
|
|
@@ -130,12 +148,85 @@ PathString:
|
|
130
148
|
|
131
149
|
Create empty namespaces
|
132
150
|
|
133
|
-
###
|
151
|
+
### Not
|
152
|
+
|
153
|
+
* not
|
154
|
+
|
155
|
+
Adds the _#not_ method to Object, so you can say fx: <code>if x.not.empty?</code>
|
156
|
+
|
157
|
+
### Numeric
|
158
|
+
|
159
|
+
module _NumericCheckExt_
|
160
|
+
|
161
|
+
* is_numeric?(arg) - alias numeric?
|
162
|
+
* check_numeric!(arg) - raises error if argument is not numeric
|
163
|
+
|
164
|
+
module NumberDslExt added to all numeric classes (Float and Numeric)
|
165
|
+
* thousand
|
166
|
+
* hundred
|
167
|
+
|
168
|
+
<pre>
|
169
|
+
3.thousand + 2.hundred
|
170
|
+
=> 3200
|
171
|
+
</pre>
|
172
|
+
|
173
|
+
### Path
|
174
|
+
* String#path - extends String instance with PathString
|
175
|
+
|
176
|
+
module PathString
|
177
|
+
* to_file
|
178
|
+
* to_dir
|
179
|
+
* to_symlink
|
180
|
+
|
181
|
+
<pre>
|
182
|
+
"a/b/c".to_dir
|
183
|
+
"a/b/c/d.rb".to_file
|
184
|
+
</pre>
|
185
|
+
|
186
|
+
File type existance
|
187
|
+
* exists?
|
188
|
+
* file?
|
189
|
+
* dir?
|
190
|
+
* symlink?
|
191
|
+
|
192
|
+
Navigate dirs
|
193
|
+
* up
|
194
|
+
* down
|
195
|
+
* post_up
|
196
|
+
* post_down
|
197
|
+
|
198
|
+
<pre>
|
199
|
+
"a/b/c/d".up(2).should == "a/b"
|
200
|
+
"a/b/".post_up(2).should == "a/b/../../"
|
201
|
+
"a/b/../".post_down(1).should == "a/b/"
|
202
|
+
</pre>
|
203
|
+
|
204
|
+
### Properties
|
205
|
+
|
206
|
+
<pre>
|
207
|
+
class CruiseShip
|
208
|
+
extend Properties
|
209
|
+
|
210
|
+
property :direction
|
211
|
+
property :speed, is(0..300)
|
212
|
+
end
|
213
|
+
|
214
|
+
ship = CruiseShip.new
|
215
|
+
ship.add_direction_listener(lambda {|x| puts "Oy... someone changed the direction to #{x}"})
|
216
|
+
ship.speed = 200
|
217
|
+
ship.speed = 301 # outside valid range!
|
218
|
+
</pre>
|
219
|
+
|
220
|
+
### RegExp
|
221
|
+
|
222
|
+
String, RegExp
|
223
|
+
* to_regexp
|
224
|
+
|
225
|
+
<pre>"a, b /c".to_regexp # escapes it for reg exp!</pre>
|
134
226
|
|
135
|
-
|
136
|
-
*
|
137
|
-
*
|
138
|
-
* any? : array and nil
|
227
|
+
MatchData
|
228
|
+
* offset_after
|
229
|
+
* offset_before
|
139
230
|
|
140
231
|
## RSpec 2 Matchers
|
141
232
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
data/lib/sugar-high/class_ext.rb
CHANGED
@@ -5,7 +5,7 @@ class Class
|
|
5
5
|
options[:instance_methods] ||= :InstanceMethods
|
6
6
|
options[:class_methods] ||= :ClassMethods
|
7
7
|
# Mainly include but be flexible
|
8
|
-
main_module = const_get(the_module)
|
8
|
+
main_module = const_get(the_module.to_s.to_sym)
|
9
9
|
include main_module # for an extend_and_include method, change this to extend main_module
|
10
10
|
include main_module.const_get(options[:instance_methods]) if main_module.const_defined?(options[:instance_methods])
|
11
11
|
extend main_module.const_get(options[:class_methods]) if main_module.const_defined?(options[:class_methods])
|
@@ -84,4 +84,4 @@ module ClassExt
|
|
84
84
|
raise "Not one Module for any of: #{names} is currently loaded" if modules.empty?
|
85
85
|
modules.first
|
86
86
|
end
|
87
|
-
end
|
87
|
+
end
|
data/lib/sugar-high/numeric.rb
CHANGED
data/lib/sugar-high/path.rb
CHANGED
@@ -51,25 +51,25 @@ module PathString
|
|
51
51
|
('../' * lv) + self
|
52
52
|
end
|
53
53
|
|
54
|
-
def
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def post_down lv
|
59
|
-
up_dir = Regexp.escape('/..')
|
54
|
+
def down lv
|
55
|
+
up_dir = Regexp.escape('../')
|
60
56
|
orig = self.clone
|
61
57
|
lv.times do
|
62
|
-
self.gsub!
|
58
|
+
self.gsub! /^#{up_dir}/, ''
|
63
59
|
return self if self == orig
|
64
60
|
end
|
65
61
|
self
|
66
62
|
end
|
67
63
|
|
68
|
-
def
|
69
|
-
|
64
|
+
def post_up lv
|
65
|
+
self + ('/..' * lv)
|
66
|
+
end
|
67
|
+
|
68
|
+
def post_down lv
|
69
|
+
up_dir = Regexp.escape('/..')
|
70
70
|
orig = self.clone
|
71
71
|
lv.times do
|
72
|
-
self.gsub!
|
72
|
+
self.gsub! /#{up_dir}$/, ''
|
73
73
|
return self if self == orig
|
74
74
|
end
|
75
75
|
self
|
@@ -15,11 +15,39 @@ module GoodBye
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
module First
|
19
|
+
module ClassMethods
|
20
|
+
def class_method
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module InstanceMethods
|
25
|
+
def instance_method
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Second
|
31
|
+
include_and_extend First
|
32
|
+
end
|
18
33
|
|
19
34
|
def trial
|
20
35
|
@trial ||= Trial.new
|
21
36
|
end
|
22
37
|
|
38
|
+
describe Class do
|
39
|
+
|
40
|
+
describe "#include_and_extend" do
|
41
|
+
it "should include class methods" do
|
42
|
+
Second.should respond_to(:class_method)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should include class methods" do
|
46
|
+
Second.new.should respond_to(:instance_method)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
23
51
|
describe ClassExt do
|
24
52
|
describe '#try_module' do
|
25
53
|
it "should return false if no module found" do
|
@@ -114,4 +142,4 @@ describe ClassExt do
|
|
114
142
|
lambda {trial.find_first_module('Good', 'Bye') }.should raise_error
|
115
143
|
end
|
116
144
|
end
|
117
|
-
end
|
145
|
+
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.4.
|
8
|
+
s.version = "0.4.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Kristian Mandrup}]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-23}
|
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 = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sugar-high
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
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-06-
|
12
|
+
date: 2011-06-23 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152257800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.5'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152257800
|
25
25
|
description: More Ruby sugar - inspired by the 'zuker' project
|
26
26
|
email: kmandrup@gmail.com
|
27
27
|
executables: []
|