sugar-high 0.1.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/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.markdown +90 -0
- data/Rakefile +16 -0
- data/VERSION +1 -0
- data/lib/sugar-high/alias.rb +43 -0
- data/lib/sugar-high/arguments.rb +22 -0
- data/lib/sugar-high/file.rb +35 -0
- data/lib/sugar-high/kind_of.rb +12 -0
- data/lib/sugar-high/matchers/have_aliases.rb +52 -0
- data/lib/sugar-high/metaclass.rb +5 -0
- data/lib/sugar-high/methods.rb +13 -0
- data/lib/sugar-high/module.rb +21 -0
- data/lib/sugar-high/rspec.rb +6 -0
- data/lib/sugar-high/string.rb +11 -0
- data/lib/sugar-high.rb +0 -0
- data/spec/fixtures/empty.txt +0 -0
- data/spec/fixtures/non-empty.txt +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/sugar-high/alias_spec.rb +34 -0
- data/spec/sugar-high/arguments_spec.rb +40 -0
- data/spec/sugar-high/file_spec.rb +57 -0
- data/spec/sugar-high/kind_of_spec.rb +49 -0
- data/spec/sugar-high/methods_spec.rb +57 -0
- data/spec/sugar-high/module_spec.rb +35 -0
- data/sugar-high.gemspec +77 -0
- metadata +114 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested --color
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Sugar high!
|
2
|
+
|
3
|
+
Named in honor of the bailouts after 2008 crisis which led to a temporary 'sugar-high' in the markets. Inspired by the 'zucker' project.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
<code>gem install sugar-high</code>
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
See specs for example use
|
12
|
+
|
13
|
+
## Sugar packs
|
14
|
+
|
15
|
+
* alias
|
16
|
+
* arguments
|
17
|
+
* file
|
18
|
+
* kind_of
|
19
|
+
* metaclass
|
20
|
+
* methods
|
21
|
+
* module
|
22
|
+
* string
|
23
|
+
|
24
|
+
### Alias
|
25
|
+
|
26
|
+
* multi_alias name, options_hash : creates multiple aliases using patterns
|
27
|
+
|
28
|
+
### Arguments
|
29
|
+
|
30
|
+
* args (Used in generator CLI testing)
|
31
|
+
* last_option *args : Returns last argument if hash or empty hash otherwise
|
32
|
+
|
33
|
+
### File
|
34
|
+
|
35
|
+
* self.blank? and blank? : Is file empty?
|
36
|
+
|
37
|
+
String:
|
38
|
+
* path : expand String with path operations :up and :down
|
39
|
+
|
40
|
+
PathString:
|
41
|
+
* up lv : Go up some directory levels, prefixing with a number of '../'
|
42
|
+
* down lv : Go down some directory levels, stripping off a number of prefixed '../'
|
43
|
+
|
44
|
+
### Kind of
|
45
|
+
|
46
|
+
* any_kind_of? *const_list
|
47
|
+
* kind_of_label? : Symbol or String ?
|
48
|
+
|
49
|
+
### Metaclass
|
50
|
+
|
51
|
+
* metaclass : Get the metaclass
|
52
|
+
|
53
|
+
### Methods
|
54
|
+
|
55
|
+
* get_methods *types : Get collection of methods, fx :private and :protected (or :all)
|
56
|
+
|
57
|
+
### Module
|
58
|
+
|
59
|
+
* modules *names
|
60
|
+
* nested_modules *names
|
61
|
+
|
62
|
+
Create empty namespaces
|
63
|
+
|
64
|
+
### String
|
65
|
+
|
66
|
+
* blank?
|
67
|
+
|
68
|
+
## RSpec 2 Matchers
|
69
|
+
|
70
|
+
* have_aliases(method, *alias_methods)
|
71
|
+
|
72
|
+
<pre>
|
73
|
+
require 'sugar-high/rspec'
|
74
|
+
|
75
|
+
have_aliases :original, :alias_1, :alias2
|
76
|
+
</pre>
|
77
|
+
|
78
|
+
## Note on Patches/Pull Requests
|
79
|
+
|
80
|
+
* Fork the project.
|
81
|
+
* Make your feature addition or bug fix.
|
82
|
+
* Add tests for it. This is important so I don't break it in a
|
83
|
+
future version unintentionally.
|
84
|
+
* Commit, do not mess with rakefile, version, or history.
|
85
|
+
(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)
|
86
|
+
* Send me a pull request. Bonus points for topic branches.
|
87
|
+
|
88
|
+
## Copyright
|
89
|
+
|
90
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "sugar-high"
|
5
|
+
gem.summary = %Q{Ruby convenience sugar packs!}
|
6
|
+
gem.description = %Q{More Ruby sugar - inspired by the 'zuker' project}
|
7
|
+
gem.email = "kmandrup@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/kristianmandrup/sugar-high"
|
9
|
+
gem.authors = ["Kristian Mandrup"]
|
10
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
|
11
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
12
|
+
end
|
13
|
+
Jeweler::GemcutterTasks.new
|
14
|
+
rescue LoadError
|
15
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
16
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'sugar-high/methods'
|
2
|
+
|
3
|
+
class Module
|
4
|
+
|
5
|
+
# multi_alias name, :create => :new, :insert_into => [:inject_into, :update], :read => :X_content
|
6
|
+
# :options => :after
|
7
|
+
#
|
8
|
+
# create_xxx becomes new_xxx
|
9
|
+
# insert_into_xxx becomes inject_into_xxx and update_xxx
|
10
|
+
# read_xxx becomes xxx_content (overriding default :after action to insert at the X)
|
11
|
+
|
12
|
+
def multi_alias name, options={}
|
13
|
+
config_options = options[:options]
|
14
|
+
options.each_pair do |original, aliases|
|
15
|
+
next if original == :options
|
16
|
+
alias_methods name, original, [aliases].flatten, config_options
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def alias_methods name, original, aliases, config_options
|
21
|
+
aliases.each do |alias_name|
|
22
|
+
new_alias = make_name(name, alias_name.to_s, config_options)
|
23
|
+
original_name = make_name(name, original.to_s, config_options)
|
24
|
+
begin
|
25
|
+
alias_method new_alias, original_name
|
26
|
+
rescue
|
27
|
+
raise ArgumentError, "Error creaing alias for ##{original_name} with #{new_alias}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def make_name name, alias_name, config_options
|
35
|
+
return alias_name.gsub(/X/, name.to_s) if alias_name =~ /X/
|
36
|
+
case config_options
|
37
|
+
when :after
|
38
|
+
"#{alias_name}_#{name}"
|
39
|
+
when :before
|
40
|
+
"#{name}_#{alias_name}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Array
|
2
|
+
def args
|
3
|
+
flatten.map{|a| a.args}.flatten
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Symbol
|
8
|
+
def args
|
9
|
+
[to_s]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class String
|
14
|
+
def args
|
15
|
+
(self =~ /\w+\s+\w+/) ? self.split : self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def last_option *args
|
20
|
+
last = args.flatten.last
|
21
|
+
last.kind_of?(Hash) ? last : {}
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'sugar-high/string'
|
2
|
+
|
3
|
+
class File
|
4
|
+
def self.blank? file_name
|
5
|
+
raise ArgumentError, "Filename argument must not be blank" if file_name.blank?
|
6
|
+
raise ArgumentError, "There is no file at: #{file_name}" if !File.file?(file_name)
|
7
|
+
File.zero?(file_name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def blank?
|
11
|
+
File.zero?(self.path)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class String
|
16
|
+
def path
|
17
|
+
self.extend PathString
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module PathString
|
22
|
+
def up lv
|
23
|
+
('../' * lv) + self
|
24
|
+
end
|
25
|
+
|
26
|
+
def down lv
|
27
|
+
up_dir = Regexp.escape('../')
|
28
|
+
orig = self.clone
|
29
|
+
lv.times do
|
30
|
+
self.gsub! /^#{up_dir}/, ''
|
31
|
+
return self if self == orig
|
32
|
+
end
|
33
|
+
self
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Sugar
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
module RSpec::Sugar
|
7
|
+
module Matchers
|
8
|
+
class HaveAliases
|
9
|
+
|
10
|
+
attr_reader :method, :alias_methods, :cause
|
11
|
+
|
12
|
+
def initialize method, *alias_methods
|
13
|
+
@method = method
|
14
|
+
@alias_methods = alias_methods.flatten
|
15
|
+
@cause = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def matches? obj, options={}
|
19
|
+
if !obj.respond_to? method
|
20
|
+
cause << "Method ##{method} to alias does NOT exist"
|
21
|
+
return nil
|
22
|
+
end
|
23
|
+
|
24
|
+
alias_methods.each do |method|
|
25
|
+
cause << "Alias method ##{method} does NOT exist" if !is_alias? obj, alias_meth
|
26
|
+
end
|
27
|
+
cause.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_alias? obj, alias_meth
|
31
|
+
obj.respond_to? alias_meth
|
32
|
+
end
|
33
|
+
|
34
|
+
def cause_msg
|
35
|
+
cause[0..3].join('.')
|
36
|
+
end
|
37
|
+
|
38
|
+
def failure_message
|
39
|
+
"Expected aliases to exist, but: #{cause_msg}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def negative_failure_message
|
43
|
+
"Did not expect aliases to exist but, #{cause_msg}".gsub /NOT/, ''
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def have_aliases method, *alias_methods
|
48
|
+
HaveAliases.new method, *alias_methods
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Object
|
2
|
+
def get_methods *types
|
3
|
+
types.inject([]) do |list, type|
|
4
|
+
list << case type
|
5
|
+
when :all
|
6
|
+
get_methods(:private, :protected, :public)
|
7
|
+
when :private, :protected, :public
|
8
|
+
send :"#{type}_methods"
|
9
|
+
end
|
10
|
+
list.flatten
|
11
|
+
end.flatten.uniq
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
def modules *module_names, &block
|
4
|
+
module_names.each do |name|
|
5
|
+
class_eval %{
|
6
|
+
module #{name.to_s.camelize}
|
7
|
+
#{yield block if block}
|
8
|
+
end
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def nested_modules *module_names, &block
|
14
|
+
module_names.inject([]) do |res, name|
|
15
|
+
res << %{
|
16
|
+
module #{name.to_s.camelize}
|
17
|
+
#{yield block if block}
|
18
|
+
end}
|
19
|
+
end.join("\n")
|
20
|
+
end
|
21
|
+
|
data/lib/sugar-high.rb
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
blip
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# multi_alias name, :create => :new, :insert_into => [:inject_into, :update], :read => :X_content
|
2
|
+
# :options => :after
|
3
|
+
#
|
4
|
+
# create_xxx becomes new_xxx
|
5
|
+
# insert_into_xxx becomes inject_into_xxx and update_xxx
|
6
|
+
# read_xxx becomes xxx_content (overriding default :after action to insert at the X)
|
7
|
+
|
8
|
+
require 'spec_helper'
|
9
|
+
require 'sugar-high/alias'
|
10
|
+
|
11
|
+
class Abc
|
12
|
+
def hello_kristian
|
13
|
+
'hi'
|
14
|
+
end
|
15
|
+
multi_alias :kristian, :hello => :howdy, :options => :after
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "SugarHigh" do
|
19
|
+
describe "Arguments" do
|
20
|
+
before do
|
21
|
+
@obj = Abc.new
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'Aliased :hello_kristian with :howdy_kristian ' do
|
25
|
+
it "should find alias" do
|
26
|
+
@obj.respond_to?(:howdy_kristian).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should find all methods saying 'hi' to kristian" do
|
30
|
+
Abc.new.get_methods(:all).sort.grep(/(.*)_kristian$/).should have(2).items
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/arguments'
|
3
|
+
|
4
|
+
describe "SugarHigh" do
|
5
|
+
describe "Arguments" do
|
6
|
+
|
7
|
+
context 'Symbol' do
|
8
|
+
it "should return arg list with 'hello'" do
|
9
|
+
:hello.args.should == ['hello']
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'String' do
|
14
|
+
it "should return arg list with 'hello'" do
|
15
|
+
:hello.args.should == ['hello']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'Array' do
|
20
|
+
it "should return arg list with 'hello', 'you'" do
|
21
|
+
[:hello, ['you']].args.should == ['hello', 'you']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Last option" do
|
26
|
+
context 'Last arg is Hash' do
|
27
|
+
it "should return the last hash" do
|
28
|
+
last_option(3,4, :x => 3, :y => 5).should == {:x => 3, :y => 5}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'Last arg is NOT Hash' do
|
33
|
+
it "should return an empty hash" do
|
34
|
+
last_option(3,4,3).should == {}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/file'
|
3
|
+
|
4
|
+
describe "SugarHigh" do
|
5
|
+
describe "File" do
|
6
|
+
let(:empty_file) { fixture_file 'empty.txt' }
|
7
|
+
let(:file) { fixture_file 'non-empty.txt'}
|
8
|
+
|
9
|
+
describe '#self.blank' do
|
10
|
+
it "should return true for an empty file" do
|
11
|
+
File.blank?(empty_file).should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return false for a NON-empty file" do
|
15
|
+
File.blank?(file).should_not be_true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#blank' do
|
20
|
+
it "should return true for an empty file" do
|
21
|
+
File.new(empty_file).blank?.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return false for a NON-empty file" do
|
25
|
+
File.new(file).blank?.should_not be_true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'String path ext' do
|
31
|
+
describe '#path' do
|
32
|
+
it "should return a String extended with PathString" do
|
33
|
+
path_str = "a/b/c".path
|
34
|
+
path_str.kind_of?(PathString).should be_true
|
35
|
+
path_str.respond_to?(:up).should be_true
|
36
|
+
path_str.respond_to?(:down).should be_true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'PathString' do
|
42
|
+
describe '#up' do
|
43
|
+
it "should go up two folder levels" do
|
44
|
+
up_path = "a/b/c".path.up(2)
|
45
|
+
up_path.should == "../../a/b/c"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#down' do
|
50
|
+
it "should go down two folder levels" do
|
51
|
+
dwn_path = "../../a/b/c".path.down(2)
|
52
|
+
dwn_path.should == "a/b/c"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/kind_of'
|
3
|
+
|
4
|
+
describe "SugarHigh" do
|
5
|
+
describe "Kind of helpers" do
|
6
|
+
describe '#any_kind_of?' do
|
7
|
+
context 'The number 3' do
|
8
|
+
before do
|
9
|
+
@obj = 3
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not be a kind of String or Symbol" do
|
13
|
+
@obj.any_kind_of?(String, Symbol).should be_false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'a String and a Symbol' do
|
18
|
+
before do
|
19
|
+
@obj_str = "Hello"
|
20
|
+
@obj_sym = :hello
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return true for a String" do
|
24
|
+
@obj_str.any_kind_of?(String, Symbol).should be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return true for a File" do
|
28
|
+
@obj_sym.any_kind_of?(String, Symbol).should be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#kind_of_label?' do
|
34
|
+
before do
|
35
|
+
@obj_str = "Hello"
|
36
|
+
@obj_sym = :hello
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return true for a String" do
|
40
|
+
@obj_str.kind_of_label?.should be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return true for a File" do
|
44
|
+
@obj_sym.kind_of_label?.should be_true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/methods'
|
3
|
+
|
4
|
+
class Abc
|
5
|
+
def hello_kristian
|
6
|
+
'hi'
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def howdy_kristian
|
12
|
+
'hi'
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def humm_kristian
|
18
|
+
'hi'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "SugarHigh" do
|
23
|
+
describe "Methods" do
|
24
|
+
before do
|
25
|
+
@obj = Abc.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should find all 3 methods saying 'hi' to kristian" do
|
29
|
+
@obj.get_methods(:all).sort.grep(/(.*)_kristian$/).should have(3).items
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should find public methods saying 'hi' to kristian" do
|
33
|
+
@obj.get_methods(:public).sort.grep(/(.*)_kristian$/).should have(1).items
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
it "should find public methods saying 'hi' to kristian" do
|
38
|
+
@obj.get_methods(:protected).sort.grep(/(.*)_kristian$/).should have(1).items
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should find public and protected methods saying 'hi' to kristian" do
|
42
|
+
@obj.get_methods(:public, :protected).sort.grep(/(.*)_kristian$/).should have(2).items
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should find private and protected methods saying 'hi' to kristian" do
|
46
|
+
@obj.get_methods(:private, :protected).sort.grep(/(.*)_kristian$/).should have(2).items
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should find private and public methods saying 'hi' to kristian" do
|
50
|
+
@obj.get_methods(:private, :public).sort.grep(/(.*)_kristian$/).should have(2).items
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should find all 3 methods saying 'hi' to kristian" do
|
54
|
+
@obj.get_methods(:private, :public, :protected).sort.grep(/(.*)_kristian$/).should have(3).items
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sugar-high/module'
|
3
|
+
|
4
|
+
module Simple
|
5
|
+
modules :x, :y
|
6
|
+
end
|
7
|
+
|
8
|
+
module Nested
|
9
|
+
modules :x, :y do
|
10
|
+
nested_modules :a, :b
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
describe "SugarHigh" do
|
16
|
+
describe "Module ext" do
|
17
|
+
describe '#modules' do
|
18
|
+
it "should create namespaces under Simple for modules X and Y" do
|
19
|
+
Simple::X.should_not be_nil
|
20
|
+
Simple::Y.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should create namespaces under Nested for modules X and Y, and modules A and B under each of those X and Y modules" do
|
24
|
+
Nested::X.should_not be_nil
|
25
|
+
Nested::Y.should_not be_nil
|
26
|
+
|
27
|
+
Nested::X::A.should_not be_nil
|
28
|
+
Nested::Y::A.should_not be_nil
|
29
|
+
|
30
|
+
Nested::X::B.should_not be_nil
|
31
|
+
Nested::Y::B.should_not be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/sugar-high.gemspec
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sugar-high}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Kristian Mandrup"]
|
12
|
+
s.date = %q{2010-08-24}
|
13
|
+
s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
|
14
|
+
s.email = %q{kmandrup@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
".rspec",
|
23
|
+
"LICENSE",
|
24
|
+
"README.markdown",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/sugar-high.rb",
|
28
|
+
"lib/sugar-high/alias.rb",
|
29
|
+
"lib/sugar-high/arguments.rb",
|
30
|
+
"lib/sugar-high/file.rb",
|
31
|
+
"lib/sugar-high/kind_of.rb",
|
32
|
+
"lib/sugar-high/matchers/have_aliases.rb",
|
33
|
+
"lib/sugar-high/metaclass.rb",
|
34
|
+
"lib/sugar-high/methods.rb",
|
35
|
+
"lib/sugar-high/module.rb",
|
36
|
+
"lib/sugar-high/rspec.rb",
|
37
|
+
"lib/sugar-high/string.rb",
|
38
|
+
"spec/fixtures/empty.txt",
|
39
|
+
"spec/fixtures/non-empty.txt",
|
40
|
+
"spec/spec_helper.rb",
|
41
|
+
"spec/sugar-high/alias_spec.rb",
|
42
|
+
"spec/sugar-high/arguments_spec.rb",
|
43
|
+
"spec/sugar-high/file_spec.rb",
|
44
|
+
"spec/sugar-high/kind_of_spec.rb",
|
45
|
+
"spec/sugar-high/methods_spec.rb",
|
46
|
+
"spec/sugar-high/module_spec.rb",
|
47
|
+
"sugar-high.gemspec"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/kristianmandrup/sugar-high}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.7}
|
53
|
+
s.summary = %q{Ruby convenience sugar packs!}
|
54
|
+
s.test_files = [
|
55
|
+
"spec/spec_helper.rb",
|
56
|
+
"spec/sugar-high/alias_spec.rb",
|
57
|
+
"spec/sugar-high/arguments_spec.rb",
|
58
|
+
"spec/sugar-high/file_spec.rb",
|
59
|
+
"spec/sugar-high/kind_of_spec.rb",
|
60
|
+
"spec/sugar-high/methods_spec.rb",
|
61
|
+
"spec/sugar-high/module_spec.rb"
|
62
|
+
]
|
63
|
+
|
64
|
+
if s.respond_to? :specification_version then
|
65
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
66
|
+
s.specification_version = 3
|
67
|
+
|
68
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
69
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
70
|
+
else
|
71
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sugar-high
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kristian Mandrup
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-24 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
- 19
|
34
|
+
version: 2.0.0.beta.19
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: More Ruby sugar - inspired by the 'zuker' project
|
38
|
+
email: kmandrup@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.markdown
|
46
|
+
files:
|
47
|
+
- .document
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- LICENSE
|
51
|
+
- README.markdown
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- lib/sugar-high.rb
|
55
|
+
- lib/sugar-high/alias.rb
|
56
|
+
- lib/sugar-high/arguments.rb
|
57
|
+
- lib/sugar-high/file.rb
|
58
|
+
- lib/sugar-high/kind_of.rb
|
59
|
+
- lib/sugar-high/matchers/have_aliases.rb
|
60
|
+
- lib/sugar-high/metaclass.rb
|
61
|
+
- lib/sugar-high/methods.rb
|
62
|
+
- lib/sugar-high/module.rb
|
63
|
+
- lib/sugar-high/rspec.rb
|
64
|
+
- lib/sugar-high/string.rb
|
65
|
+
- spec/fixtures/empty.txt
|
66
|
+
- spec/fixtures/non-empty.txt
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/sugar-high/alias_spec.rb
|
69
|
+
- spec/sugar-high/arguments_spec.rb
|
70
|
+
- spec/sugar-high/file_spec.rb
|
71
|
+
- spec/sugar-high/kind_of_spec.rb
|
72
|
+
- spec/sugar-high/methods_spec.rb
|
73
|
+
- spec/sugar-high/module_spec.rb
|
74
|
+
- sugar-high.gemspec
|
75
|
+
has_rdoc: true
|
76
|
+
homepage: http://github.com/kristianmandrup/sugar-high
|
77
|
+
licenses: []
|
78
|
+
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options:
|
81
|
+
- --charset=UTF-8
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
requirements: []
|
101
|
+
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.3.7
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Ruby convenience sugar packs!
|
107
|
+
test_files:
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/sugar-high/alias_spec.rb
|
110
|
+
- spec/sugar-high/arguments_spec.rb
|
111
|
+
- spec/sugar-high/file_spec.rb
|
112
|
+
- spec/sugar-high/kind_of_spec.rb
|
113
|
+
- spec/sugar-high/methods_spec.rb
|
114
|
+
- spec/sugar-high/module_spec.rb
|