sugar-high 0.4.7 → 0.4.8
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/Gemfile +6 -0
- data/VERSION +1 -1
- data/lib/sugar-high/array.rb +5 -0
- data/lib/sugar-high/class_ext.rb +20 -1
- data/lib/sugar-high/enumerable.rb +13 -1
- data/lib/sugar-high/kind_of.rb +7 -2
- data/spec/fixtures/autoload_modules/first.rb +7 -0
- data/spec/fixtures/autoload_modules/second.rb +5 -0
- data/spec/fixtures/autoload_modules/third.rb +4 -0
- data/spec/fixtures/autoload_modules.rb +9 -0
- data/spec/sugar-high/class_ext_spec.rb +9 -0
- data/sugar-high.gemspec +9 -1
- metadata +19 -3
data/Gemfile
ADDED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.8
|
data/lib/sugar-high/array.rb
CHANGED
@@ -97,6 +97,11 @@ class Array
|
|
97
97
|
def extract(sym)
|
98
98
|
map { |e| e.send(sym) }
|
99
99
|
end
|
100
|
+
|
101
|
+
# Repeat overall-used method here, to use it without Rails
|
102
|
+
def extract_options!
|
103
|
+
last.is_a?(::Hash) ? pop : {}
|
104
|
+
end unless defined? Array.new.extract_options!
|
100
105
|
end
|
101
106
|
|
102
107
|
module MathArray
|
data/lib/sugar-high/class_ext.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'sugar-high/kind_of'
|
2
|
+
require 'sugar-high/array'
|
2
3
|
|
3
4
|
class Class
|
4
5
|
def include_and_extend(the_module, options={})
|
@@ -84,4 +85,22 @@ module ClassExt
|
|
84
85
|
raise "Not one Module for any of: #{names} is currently loaded" if modules.empty?
|
85
86
|
modules.first
|
86
87
|
end
|
87
|
-
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class Object
|
91
|
+
# Mixing this method to Object, so both modules and classes would be able to use it!
|
92
|
+
def autoload_modules *args
|
93
|
+
|
94
|
+
options = args.extract_options!
|
95
|
+
from = options[:from]
|
96
|
+
|
97
|
+
raise "Define load path like :from => '#{self.name.to_s.downcase}'" unless from
|
98
|
+
|
99
|
+
# Here also could be adding of the file in top of load_paths like: $:.unshift File.dirname(__FILE__)
|
100
|
+
# It is very useful for situations of having not load_paths built Rails or Gems way.
|
101
|
+
|
102
|
+
args.each do |req_name|
|
103
|
+
send :autoload, req_name, "#{from}/#{req_name.to_s.downcase}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -6,6 +6,10 @@ module Enumerable
|
|
6
6
|
def only_labels?
|
7
7
|
all?{|a| a.kind_of_label? }
|
8
8
|
end
|
9
|
+
|
10
|
+
def only_numbers?
|
11
|
+
all?{|a| a.kind_of_number? }
|
12
|
+
end
|
9
13
|
|
10
14
|
def select_kinds_of *kinds
|
11
15
|
select{|a| a.any_kind_of? *kinds }
|
@@ -20,12 +24,20 @@ module Enumerable
|
|
20
24
|
select{|a| a.kind_of_label? }
|
21
25
|
end
|
22
26
|
|
27
|
+
def select_numbers
|
28
|
+
select{|a| a.is_a?(Numeric) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def select_numbers!
|
32
|
+
select!{|a| a.is_a?(Numeric) }
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
23
36
|
def select_labels!
|
24
37
|
select!{|a| a.kind_of_label? }
|
25
38
|
self
|
26
39
|
end
|
27
40
|
|
28
|
-
|
29
41
|
def select_symbols
|
30
42
|
select_only :symbol
|
31
43
|
end
|
data/lib/sugar-high/kind_of.rb
CHANGED
@@ -21,11 +21,16 @@ class Object
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def kind_of_label?
|
24
|
-
self.any_kind_of? String, Symbol
|
24
|
+
self.any_kind_of? String, Symbol
|
25
25
|
end
|
26
26
|
|
27
|
+
def kind_of_number?
|
28
|
+
self.any_kind_of? Numeric
|
29
|
+
end
|
30
|
+
|
31
|
+
|
27
32
|
def kind_of_symbol?
|
28
|
-
self.any_kind_of? Symbols, Symbol
|
33
|
+
self.any_kind_of? Symbols, Symbol
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
module AutoloadModules
|
4
|
+
#autoload :First, 'autoload_modules/first'
|
5
|
+
#autoload :Second, 'autoload_modules/second'
|
6
|
+
#autoload :Third, 'autoload_modules/third'
|
7
|
+
autoload_modules :First, :Second, :Third, :from => 'autoload_modules'
|
8
|
+
end
|
9
|
+
|
@@ -35,6 +35,15 @@ def trial
|
|
35
35
|
@trial ||= Trial.new
|
36
36
|
end
|
37
37
|
|
38
|
+
describe Object do
|
39
|
+
describe "#autoload_modules" do
|
40
|
+
it "should autoload modules" do
|
41
|
+
require 'fixtures/autoload_modules'
|
42
|
+
AutoloadModules::Third.should respond_to(:test)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
38
47
|
describe Class do
|
39
48
|
|
40
49
|
describe "#include_and_extend" do
|
data/sugar-high.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
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.8"
|
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}]
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
|
+
"Gemfile",
|
22
23
|
"LICENSE",
|
23
24
|
"README.markdown",
|
24
25
|
"Rakefile",
|
@@ -58,6 +59,10 @@ Gem::Specification.new do |s|
|
|
58
59
|
"lib/sugar-high/string.rb",
|
59
60
|
"sandbox/test_routes_mutate.rb",
|
60
61
|
"spec/fixtures/application_file.rb",
|
62
|
+
"spec/fixtures/autoload_modules.rb",
|
63
|
+
"spec/fixtures/autoload_modules/first.rb",
|
64
|
+
"spec/fixtures/autoload_modules/second.rb",
|
65
|
+
"spec/fixtures/autoload_modules/third.rb",
|
61
66
|
"spec/fixtures/class_file.rb",
|
62
67
|
"spec/fixtures/class_file.txt",
|
63
68
|
"spec/fixtures/content_file.txt",
|
@@ -101,11 +106,14 @@ Gem::Specification.new do |s|
|
|
101
106
|
s.specification_version = 3
|
102
107
|
|
103
108
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
109
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
104
110
|
s.add_development_dependency(%q<rspec>, [">= 2.5"])
|
105
111
|
else
|
112
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
106
113
|
s.add_dependency(%q<rspec>, [">= 2.5"])
|
107
114
|
end
|
108
115
|
else
|
116
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
109
117
|
s.add_dependency(%q<rspec>, [">= 2.5"])
|
110
118
|
end
|
111
119
|
end
|
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.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,18 @@ 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: &2156725160 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2156725160
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2156724680 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,7 +32,7 @@ dependencies:
|
|
21
32
|
version: '2.5'
|
22
33
|
type: :development
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *2156724680
|
25
36
|
description: More Ruby sugar - inspired by the 'zuker' project
|
26
37
|
email: kmandrup@gmail.com
|
27
38
|
executables: []
|
@@ -32,6 +43,7 @@ extra_rdoc_files:
|
|
32
43
|
files:
|
33
44
|
- .document
|
34
45
|
- .rspec
|
46
|
+
- Gemfile
|
35
47
|
- LICENSE
|
36
48
|
- README.markdown
|
37
49
|
- Rakefile
|
@@ -71,6 +83,10 @@ files:
|
|
71
83
|
- lib/sugar-high/string.rb
|
72
84
|
- sandbox/test_routes_mutate.rb
|
73
85
|
- spec/fixtures/application_file.rb
|
86
|
+
- spec/fixtures/autoload_modules.rb
|
87
|
+
- spec/fixtures/autoload_modules/first.rb
|
88
|
+
- spec/fixtures/autoload_modules/second.rb
|
89
|
+
- spec/fixtures/autoload_modules/third.rb
|
74
90
|
- spec/fixtures/class_file.rb
|
75
91
|
- spec/fixtures/class_file.txt
|
76
92
|
- spec/fixtures/content_file.txt
|