sugar-high 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,21 @@
1
- # Sugar high!
1
+ h1. Sugar high!
2
2
 
3
3
  Inspired by the 'zucker' project.
4
4
 
5
- ## Install
5
+ h2. Install
6
6
 
7
7
  <code>gem install sugar-high</code>
8
8
 
9
- ## Usage
9
+ h2. Usage
10
10
 
11
11
  See specs for example use
12
12
 
13
- ## Update June 22, 2011
13
+ h2. Update June 22, 2011
14
14
 
15
15
  file_mutate is now backwards compatible again in order nt to break gems such as cream et. al. that depend on auto inclusion of all File extensions into
16
16
  File object
17
17
 
18
- ## Sugar packs
18
+ h2. Sugar packs
19
19
 
20
20
  * alias
21
21
  * arguments
@@ -32,24 +32,26 @@ File object
32
32
  * metaclass
33
33
  * methods
34
34
  * module
35
- * not
35
+ * not
36
36
  * numeric
37
37
  * path
38
38
  * properties
39
39
  * reg_exp
40
-
41
- ### Alias
40
+
41
+ h3. Alias
42
42
 
43
43
  * multi_alias name, options_hash : creates multiple aliases using patterns
44
44
 
45
- ### Arguments
45
+ h3. Arguments
46
46
 
47
47
  * args (Used in generator CLI testing)
48
48
  * last_option *args : Returns last argument if hash or empty hash otherwise
49
49
  * ...
50
50
 
51
- ### Array
51
+ h3. Array
52
52
 
53
+ * pick_one! - pick one random item
54
+ * pink (n) - pick n random item
53
55
  * to_symbols
54
56
  * to_symbols_uniq
55
57
  * to_strings
@@ -57,11 +59,11 @@ File object
57
59
  * file_join
58
60
  * ...
59
61
 
60
- ### Blank
62
+ h3. Blank
61
63
 
62
64
  * blank?
63
65
 
64
- ### Class Extension
66
+ h3. Class Extension
65
67
 
66
68
  * autoload_modules (by @stanislaw)
67
69
 
@@ -77,7 +79,7 @@ Makes it easy to autoload multiple modules by standard folder-to-module mapping
77
79
  * find_first_class(*class_names)
78
80
  * find_first_module(*module_names)
79
81
 
80
- ### Enumerable
82
+ h3. Enumerable
81
83
 
82
84
  * only_kinds_of?(*modules)
83
85
  * only_labels?
@@ -93,16 +95,16 @@ Makes it easy to autoload multiple modules by standard folder-to-module mapping
93
95
  * select_only(type)
94
96
  * select_only!(type)
95
97
 
96
- ### File
98
+ h3. File
97
99
 
98
100
  * self.blank? and blank? : Is file empty?
99
101
  * self.overwrite : overwrite file with new content (mode = 'w')
100
102
  * self.append : append to existing file with content or create new (mode = 'w+')
101
103
 
102
- ### File Mutate
104
+ h3. File Mutate
103
105
  Adds all File mutation modules to the File class
104
106
 
105
- ### File Mutation
107
+ h3. File Mutation
106
108
 
107
109
  Various File Mutation modules that can be added to any module or class for some nice benefits. Useful for generators fx.
108
110
 
@@ -123,44 +125,44 @@ Otherwise, simply specify which ones:
123
125
 
124
126
  <pre>File.mutate_ext :append_content, overwrite_content</pre>
125
127
 
126
- ### Hash
128
+ h3. Hash
127
129
 
128
130
  * hash_revert : Reverse keys and values
129
131
  * try_keys : return value of first key that is in Hash
130
132
 
131
- ### Includes
133
+ h3. Includes
132
134
 
133
135
  * includes : Includes modules listed as symbols
134
136
 
135
- ### Kind of
137
+ h3. Kind of
136
138
 
137
139
  * any_kind_of? *const_list
138
140
  * kind_of_label? : Symbol or String ?
139
141
 
140
- ### Metaclass
142
+ h3. Metaclass
141
143
 
142
144
  * metaclass : Get the metaclass, can be used to dynamically add class singleton methods!
143
145
 
144
- ### Methods
146
+ h3. Methods
145
147
 
146
148
  * get_methods *types : Get collection of methods, fx :private and :protected (or :all)
147
149
 
148
- ### Module
150
+ h3. Module
149
151
 
150
152
  * modules *names
151
153
  * nested_modules *names
152
154
 
153
155
  Create empty namespaces
154
156
 
155
- ### Not
157
+ h3. Not
156
158
 
157
159
  * not
158
160
 
159
161
  Adds the _#not_ method to Object, so you can say fx: <code>if x.not.empty?</code>
160
162
 
161
- ### Numeric
163
+ h3. Numeric
162
164
 
163
- module _NumericCheckExt_
165
+ module _NumericCheckExt_
164
166
 
165
167
  * is_numeric?(arg) - alias numeric?
166
168
  * check_numeric!(arg) - raises error if argument is not numeric
@@ -169,12 +171,11 @@ module NumberDslExt added to all numeric classes (Float and Numeric)
169
171
  * thousand
170
172
  * hundred
171
173
 
172
- <pre>
173
- 3.thousand + 2.hundred
174
- => 3200
174
+ <pre>3.thousand + 2.hundred
175
+ => 3200
175
176
  </pre>
176
177
 
177
- ### Path
178
+ h3. Path
178
179
  * String#path - extends String instance with PathString
179
180
 
180
181
  module PathString
@@ -183,8 +184,8 @@ module PathString
183
184
  * to_symlink
184
185
 
185
186
  <pre>
186
- "a/b/c".to_dir
187
- "a/b/c/d.rb".to_file
187
+ "a/b/c".to_dir
188
+ "a/b/c/d.rb".to_file
188
189
  </pre>
189
190
 
190
191
  File type existance
@@ -205,7 +206,7 @@ Navigate dirs
205
206
  "a/b/../".post_down(1).should == "a/b/"
206
207
  </pre>
207
208
 
208
- ### Properties
209
+ h3. Properties
209
210
 
210
211
  <pre>
211
212
  class CruiseShip
@@ -213,15 +214,15 @@ class CruiseShip
213
214
 
214
215
  property :direction
215
216
  property :speed, is(0..300)
216
- end
217
+ end
217
218
 
218
- ship = CruiseShip.new
219
+ ship = CruiseShip.new
219
220
  ship.add_direction_listener(lambda {|x| puts "Oy... someone changed the direction to #{x}"})
220
221
  ship.speed = 200
221
222
  ship.speed = 301 # outside valid range!
222
223
  </pre>
223
224
 
224
- ### RegExp
225
+ h3. RegExp
225
226
 
226
227
  String, RegExp
227
228
  * to_regexp
@@ -232,17 +233,31 @@ MatchData
232
233
  * offset_after
233
234
  * offset_before
234
235
 
235
- ## RSpec 2 Matchers
236
+ h3. RSpec 2 Matchers
236
237
 
237
238
  * have_aliases(method, *alias_methods)
238
239
 
239
240
  <pre>
240
241
  require 'sugar-high/rspec'
241
-
242
+
242
243
  have_aliases :original, :alias_1, :alias2
243
244
  </pre>
244
245
 
245
- ## Note on Patches/Pull Requests
246
+ h3. String
247
+
248
+ Class methods
249
+ * random_letters
250
+ * letters
251
+
252
+ Instance methods
253
+ * alpha_numeric
254
+ * insert_before_last
255
+
256
+ If not already defined
257
+ * trim
258
+ * concat
259
+
260
+ h2. Note on Patches/Pull Requests
246
261
 
247
262
  * Fork the project.
248
263
  * Make your feature addition or bug fix.
@@ -252,6 +267,6 @@ MatchData
252
267
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
253
268
  * Send me a pull request. Bonus points for topic branches.
254
269
 
255
- ## Copyright
270
+ h2. Copyright
256
271
 
257
272
  Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -3,17 +3,26 @@ require 'sugar-high/enumerable'
3
3
  require 'sugar-high/path'
4
4
 
5
5
  class Array
6
+ def pick_one!
7
+ index = Kernel.rand(self.size)
8
+ self[index]
9
+ end
10
+
11
+ def pick num
12
+ num.times.inject([]) {|res, x| res << pick_one!}
13
+ end
14
+
6
15
  def without(*values)
7
16
  copy = self.dup
8
17
  values.flatten.each { |value| copy.delete(value) }
9
18
  copy
10
19
  end
11
-
20
+
12
21
  def to_symbols
13
22
  res = self.flatten.select_labels
14
23
  res = res.map{|a| a.to_s.to_sym } if res
15
24
  res || []
16
- end
25
+ end
17
26
 
18
27
  def to_symbols!
19
28
  self.flatten!
@@ -0,0 +1,7 @@
1
+ require 'sugar-high/array'
2
+
3
+ class Boolean
4
+ def self.random
5
+ [true, false].pick_one!
6
+ end
7
+ end
@@ -1,7 +1,7 @@
1
1
  require 'sugar-high/kind_of'
2
2
  require 'sugar-high/array'
3
3
 
4
- class Module
4
+ class Module
5
5
  def include_and_extend(the_module, options={})
6
6
  options[:instance_methods] ||= :InstanceMethods
7
7
  options[:class_methods] ||= :ClassMethods
@@ -11,7 +11,7 @@ class Module
11
11
  include main_module.const_get(options[:instance_methods]) if main_module.const_defined?(options[:instance_methods])
12
12
  extend main_module.const_get(options[:class_methods]) if main_module.const_defined?(options[:class_methods])
13
13
  end
14
-
14
+
15
15
  def autoload_modules *args
16
16
 
17
17
  options = args.extract_options!
@@ -57,16 +57,16 @@ module AutoLoader
57
57
  namespaces[clazz_name.to_sym] ? namespaces[clazz_name.to_sym] : name
58
58
  end.join('/')
59
59
  end
60
- end
60
+ end
61
61
 
62
- module ClassExt
62
+ module ClassExt
63
63
  def get_module name
64
64
  # Module.const_get(name)
65
65
  name.to_s.camelize.constantize
66
66
  rescue
67
67
  nil
68
68
  end
69
-
69
+
70
70
  def is_class?(clazz)
71
71
  clazz.is_a?(Class) && (clazz.respond_to? :new)
72
72
  end
@@ -74,42 +74,42 @@ module ClassExt
74
74
  def is_module?(clazz)
75
75
  clazz.is_a?(Module) && !(clazz.respond_to? :new)
76
76
  end
77
-
77
+
78
78
  def class_exists?(name)
79
79
  is_class? get_module(name)
80
80
  rescue
81
81
  return false
82
- end
82
+ end
83
83
 
84
84
  def module_exists?(name)
85
85
  is_module? get_module(name)
86
86
  rescue NameError
87
87
  return false
88
- end
89
-
88
+ end
89
+
90
90
  def try_class name
91
91
  return name if name.kind_of?(Class)
92
92
  found = get_module(name) if name.kind_of_label?
93
93
  return found if found.is_a?(Class)
94
- rescue
94
+ rescue
95
95
  false
96
- end
96
+ end
97
97
 
98
98
  def try_module name
99
99
  return name if name.kind_of?(Module)
100
100
  found = get_module(name) if name.kind_of_label?
101
101
  return found if found.is_a?(Module)
102
- rescue
102
+ rescue
103
103
  false
104
- end
104
+ end
105
105
 
106
106
  def try_module_only name
107
107
  return name if is_module?(name)
108
108
  found = get_module(name) if name.kind_of_label?
109
109
  return found if is_module?(found)
110
- rescue
110
+ rescue
111
111
  false
112
- end
112
+ end
113
113
 
114
114
 
115
115
  def find_first_class *names
@@ -7,15 +7,15 @@ class Object
7
7
  end
8
8
 
9
9
  def any_kind_of? *kinds
10
- kinds.all_kinds.each do |kind|
11
- return true if self.kind_of? kind
10
+ kinds.all_kinds.each do |kind|
11
+ return true if self.kind_of? kind
12
12
  end
13
13
  false
14
14
  end
15
15
 
16
16
  def not_any_kind_of? *kinds
17
- kinds.all_kinds.each do |kind|
18
- return false if self.kind_of? kind
17
+ kinds.all_kinds.each do |kind|
18
+ return false if self.kind_of? kind
19
19
  end
20
20
  true
21
21
  end
@@ -33,11 +33,11 @@ class Object
33
33
  self.any_kind_of? Symbols, Symbol
34
34
  end
35
35
  end
36
-
37
- class Kinds
36
+
37
+ class Kinds
38
38
  attr_accessor :kinds
39
-
39
+
40
40
  def initialize *kinds
41
41
  self.kinds = *kinds
42
42
  end
43
- end
43
+ end
@@ -1,5 +1,5 @@
1
1
  class Object
2
2
  def self.metaclass
3
3
  class << self; self; end
4
- end
5
- end
4
+ end
5
+ end
@@ -1,12 +1,25 @@
1
1
  class String
2
- def trim
3
- self.strip
2
+ def self.random_letters count, type = :lower
3
+ letters(type).pick(count)
4
4
  end
5
-
6
- def concat *args
7
- args.inject(self) do |res, arg|
8
- res << arg.to_s
9
- res
5
+
6
+ def self.letters type = :lower
7
+ letters = ('a'..'z').to_a
8
+ type == :upper ? letters.map!(&:upcase) : letters
9
+ end
10
+
11
+ unless respond_to? :trim
12
+ def trim
13
+ self.strip
14
+ end
15
+ end
16
+
17
+ unless respond_to? :concat
18
+ def concat *args
19
+ args.inject(self) do |res, arg|
20
+ res << arg.to_s
21
+ res
22
+ end
10
23
  end
11
24
  end
12
25
 
@@ -14,7 +27,7 @@ class String
14
27
  def alpha_numeric
15
28
  self.gsub(/^\-+/, '').gsub(/[^0-9a-zA-Z_\-]+/i, '')
16
29
  end
17
-
30
+
18
31
  def insert_before_last str, marker = 'end'
19
32
  res = []
20
33
  found = false
@@ -25,17 +38,12 @@ class String
25
38
  marker[:marker].to_s
26
39
  else
27
40
  raise ArgumentException, "last argument is the marker and must be a String, Symbol or even Hash with a :marker option pointing to the marker (String or Symbol)"
28
- end
29
-
41
+ end
42
+
30
43
  marker = Regexp.escape(marker.to_s.reverse)
31
44
  nl = Regexp.escape("\n")
32
- # puts self
33
- # puts "marker: #{marker}"
34
- # puts "nl: #{nl}"
35
- # puts "str: #{str}"
36
-
37
45
  self.reverse.each_line do |x|
38
- x.gsub! /#{nl}/, ''
46
+ x.gsub! /#{nl}/, ''
39
47
  if !found && x =~ /#{marker}/
40
48
  replace = "#{str}\n" << x.reverse
41
49
  res << replace
@@ -43,7 +51,7 @@ class String
43
51
  else
44
52
  res << x.reverse
45
53
  end
46
- end
54
+ end
47
55
  res = res.reverse.join("\n")
48
56
  end
49
- end
57
+ end
data/sugar-high.gemspec CHANGED
@@ -5,23 +5,23 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-07-20}
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = %q{2011-07-31}
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 = [
16
16
  "LICENSE",
17
- "README.markdown"
17
+ "README.textile"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
22
  "Gemfile",
23
23
  "LICENSE",
24
- "README.markdown",
24
+ "README.textile",
25
25
  "Rakefile",
26
26
  "VERSION",
27
27
  "lib/sugar-high.rb",
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/sugar-high/arguments.rb",
30
30
  "lib/sugar-high/array.rb",
31
31
  "lib/sugar-high/blank.rb",
32
+ "lib/sugar-high/boolean.rb",
32
33
  "lib/sugar-high/class_ext.rb",
33
34
  "lib/sugar-high/enumerable.rb",
34
35
  "lib/sugar-high/file.rb",
@@ -110,8 +111,8 @@ Gem::Specification.new do |s|
110
111
  "sugar-high.gemspec"
111
112
  ]
112
113
  s.homepage = %q{http://github.com/kristianmandrup/sugar-high}
113
- s.require_paths = [%q{lib}]
114
- s.rubygems_version = %q{1.8.5}
114
+ s.require_paths = ["lib"]
115
+ s.rubygems_version = %q{1.6.2}
115
116
  s.summary = %q{Ruby convenience sugar packs!}
116
117
 
117
118
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,80 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
- version: !ruby/object:Gem::Version
4
- hash: 11
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.1
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kristian Mandrup
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-07-20 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-07-31 00:00:00.000000000 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &2155962220 !ruby/object:Gem::Requirement
22
18
  none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- version_requirements: *id001
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
31
23
  type: :development
32
- name: rspec
33
24
  prerelease: false
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *2155962220
26
+ - !ruby/object:Gem::Dependency
27
+ name: active_support
28
+ requirement: &2155961300 !ruby/object:Gem::Requirement
36
29
  none: false
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- hash: 3
41
- segments:
42
- - 0
43
- version: "0"
44
- version_requirements: *id002
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
45
34
  type: :development
46
- name: active_support
47
35
  prerelease: false
48
- - !ruby/object:Gem::Dependency
49
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *2155961300
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ requirement: &2155960580 !ruby/object:Gem::Requirement
50
40
  none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 9
55
- segments:
56
- - 2
57
- - 5
58
- version: "2.5"
59
- version_requirements: *id003
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '2.5'
60
45
  type: :development
61
- name: rspec
62
46
  prerelease: false
47
+ version_requirements: *2155960580
63
48
  description: More Ruby sugar - inspired by the 'zuker' project
64
49
  email: kmandrup@gmail.com
65
50
  executables: []
66
-
67
51
  extensions: []
68
-
69
- extra_rdoc_files:
52
+ extra_rdoc_files:
70
53
  - LICENSE
71
- - README.markdown
72
- files:
54
+ - README.textile
55
+ files:
73
56
  - .document
74
57
  - .rspec
75
58
  - Gemfile
76
59
  - LICENSE
77
- - README.markdown
60
+ - README.textile
78
61
  - Rakefile
79
62
  - VERSION
80
63
  - lib/sugar-high.rb
@@ -82,6 +65,7 @@ files:
82
65
  - lib/sugar-high/arguments.rb
83
66
  - lib/sugar-high/array.rb
84
67
  - lib/sugar-high/blank.rb
68
+ - lib/sugar-high/boolean.rb
85
69
  - lib/sugar-high/class_ext.rb
86
70
  - lib/sugar-high/enumerable.rb
87
71
  - lib/sugar-high/file.rb
@@ -161,38 +145,29 @@ files:
161
145
  - spec/sugar-high/regexp_spec.rb
162
146
  - spec/sugar-high/string_spec.rb
163
147
  - sugar-high.gemspec
148
+ has_rdoc: true
164
149
  homepage: http://github.com/kristianmandrup/sugar-high
165
150
  licenses: []
166
-
167
151
  post_install_message:
168
152
  rdoc_options: []
169
-
170
- require_paths:
153
+ require_paths:
171
154
  - lib
172
- required_ruby_version: !ruby/object:Gem::Requirement
155
+ required_ruby_version: !ruby/object:Gem::Requirement
173
156
  none: false
174
- requirements:
175
- - - ">="
176
- - !ruby/object:Gem::Version
177
- hash: 3
178
- segments:
179
- - 0
180
- version: "0"
181
- required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
162
  none: false
183
- requirements:
184
- - - ">="
185
- - !ruby/object:Gem::Version
186
- hash: 3
187
- segments:
188
- - 0
189
- version: "0"
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
190
167
  requirements: []
191
-
192
168
  rubyforge_project:
193
- rubygems_version: 1.8.5
169
+ rubygems_version: 1.6.2
194
170
  signing_key:
195
171
  specification_version: 3
196
172
  summary: Ruby convenience sugar packs!
197
173
  test_files: []
198
-