algerb 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -fd -c
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 1.9.2
4
+
5
+ branches:
6
+ only:
7
+ - master
8
+ - develop
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'thor'
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'cucumber'
8
+ gem 'aruba'
9
+ gem 'guard-cucumber'
10
+ gem 'rspec'
11
+ gem 'guard-rspec'
12
+ gem 'jeweler', '~> 1.6.4'
13
+ gem 'rcov', '>= 0'
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ aruba (0.4.11)
5
+ childprocess (>= 0.2.3)
6
+ cucumber (>= 1.1.1)
7
+ ffi (>= 1.0.11)
8
+ rspec (>= 2.7.0)
9
+ builder (3.0.0)
10
+ childprocess (0.2.4)
11
+ ffi (~> 1.0.6)
12
+ cucumber (1.1.4)
13
+ builder (>= 2.1.2)
14
+ diff-lcs (>= 1.1.2)
15
+ gherkin (~> 2.7.1)
16
+ json (>= 1.4.6)
17
+ term-ansicolor (>= 1.0.6)
18
+ diff-lcs (1.1.3)
19
+ ffi (1.0.11)
20
+ gherkin (2.7.1)
21
+ json (>= 1.4.6)
22
+ git (1.2.5)
23
+ guard (0.9.4)
24
+ ffi (>= 0.5.0)
25
+ thor (~> 0.14.6)
26
+ guard-cucumber (0.7.4)
27
+ cucumber (>= 0.10)
28
+ guard (>= 0.8.3)
29
+ guard-rspec (0.5.11)
30
+ guard (>= 0.8.4)
31
+ jeweler (1.6.4)
32
+ bundler (~> 1.0)
33
+ git (>= 1.2.5)
34
+ rake
35
+ json (1.6.4)
36
+ rake (0.9.2.2)
37
+ rcov (0.9.11)
38
+ rspec (2.7.0)
39
+ rspec-core (~> 2.7.0)
40
+ rspec-expectations (~> 2.7.0)
41
+ rspec-mocks (~> 2.7.0)
42
+ rspec-core (2.7.1)
43
+ rspec-expectations (2.7.0)
44
+ diff-lcs (~> 1.1.2)
45
+ rspec-mocks (2.7.0)
46
+ term-ansicolor (1.0.7)
47
+ thor (0.14.6)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ aruba
54
+ cucumber
55
+ guard-cucumber
56
+ guard-rspec
57
+ jeweler (~> 1.6.4)
58
+ rake
59
+ rcov
60
+ rspec
61
+ thor
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ group :feature do
5
+ guard 'cucumber' do
6
+ watch(%r{^features/.+\.feature$})
7
+ watch(%r{^features/support/.+$}) { 'features' }
8
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
9
+ watch(%r{^bin/algerb$}) { 'features' }
10
+ end
11
+ end
12
+
13
+ group :spec do
14
+ guard 'rspec', :version => 2 do
15
+ watch(%r{^spec/.+_spec\.rb$})
16
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
17
+ watch('spec/spec_helper.rb') { "spec" }
18
+ end
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Yuya Takeyama
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.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ = algerb
2
+
3
+ Autoloader generator for Ruby.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2011 Yuya Takeyama. See LICENSE.txt for
8
+ further details.
9
+
data/Rakefile ADDED
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ Bundler.setup(:default, :development)
4
+ require 'rake'
5
+
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = 'algerb'
9
+ gem.homepage = "http://github.com/yuya-takeyama/algerb"
10
+ gem.license = 'MIT'
11
+ gem.summary = %Q{Autoloader generator for Ruby}
12
+ gem.description = %Q{Generates autoloader script for your Ruby library.}
13
+ gem.email = 'sign.of.the.wolf.pentagram@gmail.com'
14
+ gem.authors = ['Yuya Takeyama']
15
+ end
16
+ Jeweler::RubygemsDotOrgTasks.new
17
+
18
+ require 'cucumber/rake/task'
19
+ Cucumber::Rake::Task.new
20
+
21
+ require 'rspec/core/rake_task'
22
+ desc 'Run RSpec'
23
+ RSpec::Core::RakeTask.new do |spec|
24
+ spec.pattern = 'spec/**/*_spec.rb'
25
+ spec.rspec_opts = ['--color', '--format nested']
26
+ end
27
+
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'spec'
31
+ test.pattern = 'spec/**/*_spec.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc 'Run tests, both RSpec and Cucumber'
36
+ task :test => [:spec, :cucumber]
37
+
38
+ task :default => :test
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "algerb #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/algerb.gemspec ADDED
@@ -0,0 +1,91 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "algerb"
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Yuya Takeyama"]
12
+ s.date = "2011-12-31"
13
+ s.description = "Generates autoloader script for your Ruby library."
14
+ s.email = "sign.of.the.wolf.pentagram@gmail.com"
15
+ s.executables = ["algerb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "Guardfile",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "algerb.gemspec",
31
+ "autoloader.rb",
32
+ "bin/algerb",
33
+ "features/autoloader_generation.feature",
34
+ "features/step_definitions/autoloader_generation_steps.rb",
35
+ "features/support/env.rb",
36
+ "lib/algerb.rb",
37
+ "lib/algerb/app.rb",
38
+ "lib/algerb/file.rb",
39
+ "lib/algerb/files.rb",
40
+ "lib/algerb/files_builder.rb",
41
+ "lib/algerb/generator.rb",
42
+ "lib/algerb/util.rb",
43
+ "spec/spec_helper.rb",
44
+ "spec/unit/algerb/files_builder_spec.rb",
45
+ "spec/unit/algerb/files_spec.rb",
46
+ "spec/unit/algerb/generator_spec.rb",
47
+ "spec/unit/algerb/util_spec.rb"
48
+ ]
49
+ s.homepage = "http://github.com/yuya-takeyama/algerb"
50
+ s.licenses = ["MIT"]
51
+ s.require_paths = ["lib"]
52
+ s.rubygems_version = "1.8.10"
53
+ s.summary = "Autoloader generator for Ruby"
54
+
55
+ if s.respond_to? :specification_version then
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
60
+ s.add_development_dependency(%q<rake>, [">= 0"])
61
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
62
+ s.add_development_dependency(%q<aruba>, [">= 0"])
63
+ s.add_development_dependency(%q<guard-cucumber>, [">= 0"])
64
+ s.add_development_dependency(%q<rspec>, [">= 0"])
65
+ s.add_development_dependency(%q<guard-rspec>, [">= 0"])
66
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
67
+ s.add_development_dependency(%q<rcov>, [">= 0"])
68
+ else
69
+ s.add_dependency(%q<thor>, [">= 0"])
70
+ s.add_dependency(%q<rake>, [">= 0"])
71
+ s.add_dependency(%q<cucumber>, [">= 0"])
72
+ s.add_dependency(%q<aruba>, [">= 0"])
73
+ s.add_dependency(%q<guard-cucumber>, [">= 0"])
74
+ s.add_dependency(%q<rspec>, [">= 0"])
75
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
76
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
77
+ s.add_dependency(%q<rcov>, [">= 0"])
78
+ end
79
+ else
80
+ s.add_dependency(%q<thor>, [">= 0"])
81
+ s.add_dependency(%q<rake>, [">= 0"])
82
+ s.add_dependency(%q<cucumber>, [">= 0"])
83
+ s.add_dependency(%q<aruba>, [">= 0"])
84
+ s.add_dependency(%q<guard-cucumber>, [">= 0"])
85
+ s.add_dependency(%q<rspec>, [">= 0"])
86
+ s.add_dependency(%q<guard-rspec>, [">= 0"])
87
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
88
+ s.add_dependency(%q<rcov>, [">= 0"])
89
+ end
90
+ end
91
+
data/autoloader.rb ADDED
@@ -0,0 +1,9 @@
1
+ module Algerb
2
+ autoload :App, 'algerb/app'
3
+ autoload :File, 'algerb/file'
4
+ autoload :Files, 'algerb/files'
5
+ autoload :FilesBuilder, 'algerb/files_builder'
6
+ autoload :Generator, 'algerb/generator'
7
+ autoload :Util, 'algerb/util'
8
+ end
9
+ autoload :Algerb, 'algerb'
data/bin/algerb ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
3
+ require 'bundler'
4
+ Bundler.setup(:default)
5
+ require File.dirname(__FILE__) + '/../autoloader.rb'
6
+
7
+ Algerb::App.start
@@ -0,0 +1,40 @@
1
+ Feature: Autoloader generation
2
+ Writing Ruby's Kernel.#autoload by hand is so messy.
3
+ So Algerb generates autoloader file automatically.
4
+
5
+ Scenario: Autoloader generation for single file
6
+ Given an empty file named "./lib/foo.rb"
7
+ When I run `algerb`
8
+ Then the file "./autoloader.rb" should contain exactly:
9
+ """
10
+ autoload :Foo, 'foo'
11
+
12
+ """
13
+
14
+ Scenario: Autoloader generation for multiple files
15
+ Given an empty file named "./lib/foo.rb"
16
+ And an empty file named "./lib/bar.rb"
17
+ When I run `algerb`
18
+ Then the file "./autoloader.rb" should contain exactly:
19
+ """
20
+ autoload :Bar, 'bar'
21
+ autoload :Foo, 'foo'
22
+
23
+ """
24
+
25
+ Scenario: Autoloader generation for library has nested structure.
26
+ Given an empty file named "./lib/foo.rb"
27
+ And an empty file named "./lib/foo/bar.rb"
28
+ And an empty file named "./lib/foo/bar/baz.rb"
29
+ When I run `algerb`
30
+ Then the file "./autoloader.rb" should contain exactly:
31
+ """
32
+ module Foo
33
+ module Bar
34
+ autoload :Baz, 'foo/bar/baz'
35
+ end
36
+ autoload :Bar, 'foo/bar'
37
+ end
38
+ autoload :Foo, 'foo'
39
+
40
+ """
@@ -0,0 +1,7 @@
1
+ Given /^I am in "([^"]*)" directory$/ do |dir|
2
+ Dir.chdir(File.realpath(File.dirname(__FILE__) + '/../../' + dir))
3
+ end
4
+
5
+ When /^I execute algerb command$/ do
6
+ @command_result = `#{File.dirname(__FILE__) + '/../../bin/algerb'}`
7
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'aruba/cucumber'
3
+ require 'rspec/expectations'
data/lib/algerb/app.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'thor'
2
+
3
+ module Algerb; end
4
+ class Algerb::App < Thor
5
+ default_task :generate
6
+
7
+ method_option :target, :default => './lib'
8
+ method_option :output, :default => './autoloader.rb'
9
+
10
+ desc 'generate', 'Generates autoloader script'
11
+ def generate
12
+ open(options[:output], 'w') do |file|
13
+ file.puts ::Algerb::Generator.new.generate(target_files(options['target']))
14
+ end
15
+ end
16
+
17
+ private
18
+ def target_files(target_dir)
19
+ original_dir = Dir.pwd
20
+ Dir.chdir(target_dir)
21
+ result = Dir.glob('**/*.rb')
22
+ Dir.chdir(original_dir)
23
+ result.sort
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ class Algerb::File
2
+ include Algerb::Util
3
+
4
+ FILE_PATTERN = %r{/?(a-z0-9\-_\.)$}i
5
+
6
+ attr_reader :name
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def each(&block)
13
+ each_files(&block)
14
+ end
15
+
16
+ def ==(another)
17
+ self.name == another.name
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ class Algerb::Files
2
+ include ::Enumerable
3
+
4
+ attr_reader :name, :files
5
+
6
+ def initialize(name = nil, files = {})
7
+ @name = name
8
+ @files = files
9
+ end
10
+
11
+ def add(file)
12
+ if @files.has_key?(file.name)
13
+ file.files.each do |name, _file|
14
+ @files[file.name].files[name] = _file
15
+ end
16
+ else
17
+ @files[file.name] = file
18
+ end
19
+ self
20
+ end
21
+
22
+ def ==(another)
23
+ self.name == another.name and self.files == another.files
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ class Algerb::FilesBuilder
2
+ attr_reader :files
3
+
4
+ FILE_PATTERN = %r{^([a-z0-9\_\.])/?}
5
+
6
+ def initialize
7
+ @files = Algerb::Files.new
8
+ end
9
+
10
+ def add(path)
11
+ paths = path.split('/').reverse
12
+ file = Algerb::File.new(paths.slice!(0, 1)[0])
13
+ files = paths.inject(file) do |file, path|
14
+ files = Algerb::Files.new(path).add(file)
15
+ files
16
+ end
17
+ @files.add files
18
+ self
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ class Algerb::Generator
2
+ include Algerb::Util
3
+
4
+ def generate(files)
5
+ generate_autoloader_body(files)
6
+ end
7
+
8
+ def generate_autoloader_body(files)
9
+ builder = Algerb::FilesBuilder.new
10
+ files.each do |file|
11
+ builder.add file
12
+ end
13
+ _generate_autoloader_body(builder.files.files)
14
+ end
15
+
16
+ private
17
+ def _generate_autoloader_body(files, parent = nil, level = 0)
18
+ files.sort_by {|name, file| name }.inject('') do |result, key_value|
19
+ name, file = key_value
20
+ path = remove_ext(prefix(parent) + file.name)
21
+ if file.is_a?(Algerb::File)
22
+ result += indent(level) + "autoload :#{file_to_class(file.name)}, '#{path}'\n"
23
+ else
24
+ result += indent(level) + "module #{file_to_class(file.name)}\n"
25
+ result += _generate_autoloader_body(file.files, path, level + 1)
26
+ result += indent(level) + "end\n"
27
+ end
28
+ result
29
+ end
30
+ end
31
+
32
+ def prefix(parent)
33
+ if parent.nil?
34
+ ''
35
+ else
36
+ "#{parent}/"
37
+ end
38
+ end
39
+
40
+ def indent(level)
41
+ ' ' * level
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ module Algerb::Util
2
+ def file_to_class(file)
3
+ remove_ext(file).split('_').map {|word| word.capitalize }.join('')
4
+ end
5
+
6
+ def indentation(code, level)
7
+ code.split("\n").map {|line| ' ' * level + line + "\n" }.join('')
8
+ end
9
+
10
+ def remove_dir(path)
11
+ path.sub(%r{^([a-z0-9\_]*/)*}, '')
12
+ end
13
+
14
+ def remove_ext(path)
15
+ path.sub(/\.rb$/, '')
16
+ end
17
+ end
data/lib/algerb.rb ADDED
@@ -0,0 +1,2 @@
1
+ module Algerb
2
+ end
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'bundler'
3
+ Bundler.setup(:default, :development)
4
+ require 'rspec'
5
+ require File.realpath(File.dirname(__FILE__)) + '/../autoloader.rb'
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Algerb::FilesBuilder do
4
+ let(:builder) { Algerb::FilesBuilder.new }
5
+
6
+ describe 'files' do
7
+ subject { builder.files }
8
+
9
+ context 'without any files' do
10
+ it { should == Algerb::Files.new }
11
+ end
12
+
13
+ context 'when 1 file ("foo.rb") is added' do
14
+ before { builder.add('foo.rb') }
15
+ it { should == Algerb::Files.new.add(Algerb::File.new('foo.rb'))}
16
+ end
17
+
18
+ context 'when 1 file ("foo/bar.rb") is added' do
19
+ before { builder.add('foo/bar.rb') }
20
+ it { should == Algerb::Files.new.add(Algerb::Files.new('foo').add(Algerb::File.new('bar.rb')))}
21
+ end
22
+
23
+ context 'when 2 files ("foo/bar.rb", "foo/baz.rb") are added' do
24
+ before do
25
+ builder.add('foo/bar.rb')
26
+ builder.add('foo/baz.rb')
27
+ end
28
+ it { should == Algerb::Files.new.add(Algerb::Files.new('foo').add(Algerb::File.new('bar.rb')).add(Algerb::File.new('baz.rb'))) }
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Algerb::Files do
4
+ let(:root) { Algerb::Files.new }
5
+
6
+ describe '#files' do
7
+ subject { root.files }
8
+
9
+ context 'when no files are added' do
10
+ it { should == {} }
11
+ end
12
+
13
+ context 'when 1 file ("foo.rb") is added' do
14
+ before { root.add(file) }
15
+ let(:file) { Algerb::File.new('foo.rb') }
16
+
17
+ it { should == {'foo.rb' => file} }
18
+ end
19
+
20
+ context 'when 2 files ("foo.rb", "bar.rb") are added' do
21
+ before do
22
+ root.add(file1)
23
+ root.add(file2)
24
+ end
25
+
26
+ let(:file1) { Algerb::File.new('foo.rb') }
27
+ let(:file2) { Algerb::File.new('bar.rb') }
28
+
29
+ it { should == {'foo.rb' => file1, 'bar.rb' => file2} }
30
+ end
31
+
32
+ context 'when 1 dir ("foo") is added' do
33
+ before { root.add(dir) }
34
+ let(:dir) { Algerb::Files.new('foo') }
35
+
36
+ it { should == {'foo' => dir} }
37
+ end
38
+
39
+ context 'when 2 dirs ("foo", "bar") are added' do
40
+ before do
41
+ root.add(dir1)
42
+ root.add(dir2)
43
+ end
44
+
45
+ let(:dir1) { Algerb::Files.new('foo') }
46
+ let(:dir2) { Algerb::Files.new('bar') }
47
+
48
+ it { should == {'foo' => dir1, 'bar' => dir2} }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Algerb::Generator do
4
+ describe '#generate_autoloader_body' do
5
+ subject { Algerb::Generator.new.generate_autoloader_body(files) }
6
+
7
+ context 'with 1 file ("foo.rb")' do
8
+ let(:files) { ["foo.rb"] }
9
+
10
+ it { should == "autoload :Foo, 'foo'\n" }
11
+ end
12
+
13
+ context 'with 2 files ("foo.rb", "bar.rb")' do
14
+ let(:files) { ["foo.rb", "bar.rb"] }
15
+
16
+ it do
17
+ should == "autoload :Bar, 'bar'\n" +
18
+ "autoload :Foo, 'foo'\n"
19
+ end
20
+ end
21
+
22
+ context 'with 2 files ("foo.rb", "foo/bar.rb")' do
23
+ let(:files) { ['foo.rb', 'foo/bar.rb'] }
24
+ it do
25
+ should == "module Foo\n" +
26
+ " autoload :Bar, 'foo/bar'\n" +
27
+ "end\n" +
28
+ "autoload :Foo, 'foo'\n"
29
+ end
30
+ end
31
+
32
+ context 'with 2files ("foo.rb", "foo/bar/baz/foo_bar.rb")' do
33
+ let(:files) { ['foo.rb', 'foo/bar/baz/foo_bar.rb'] }
34
+ it do
35
+ should == "module Foo\n" +
36
+ " module Bar\n" +
37
+ " module Baz\n" +
38
+ " autoload :FooBar, 'foo/bar/baz/foo_bar'\n" +
39
+ " end\n" +
40
+ " end\n" +
41
+ "end\n" +
42
+ "autoload :Foo, 'foo'\n"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Algerb::Util do
4
+ include Algerb::Util
5
+
6
+ describe '#file_to_class' do
7
+ subject { file_to_class(file) }
8
+
9
+ context 'with file name only alpabets' do
10
+ let(:file) { 'foo' }
11
+ it 'should be capitalized' do
12
+ subject.should == 'Foo'
13
+ end
14
+ end
15
+
16
+ context 'with file name with alphabets and underscore' do
17
+ let(:file) { 'foo_bar' }
18
+
19
+ it 'should be CamelCase' do
20
+ subject.should == 'FooBar'
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#indentation' do
26
+ subject { indentation(code, 2) }
27
+
28
+ context 'with single line' do
29
+ let(:code) { "foo\n" }
30
+
31
+ it { should == " foo\n" }
32
+ end
33
+
34
+ context 'with multiple lines' do
35
+ let(:code) { "foo\nbar" }
36
+
37
+ it { should == " foo\n bar\n" }
38
+ end
39
+ end
40
+
41
+ describe '#remove_dir' do
42
+ subject { remove_dir(path) }
43
+
44
+ context 'without dir ("foo")' do
45
+ let(:path) { 'foo' }
46
+
47
+ it { should == 'foo' }
48
+ end
49
+
50
+ context 'with 1 nested dir ("foo/bar")' do
51
+ let(:path) { 'foo/bar' }
52
+
53
+ it { should == 'bar' }
54
+ end
55
+
56
+ context 'with 2 nested dir ("foo/bar/baz")' do
57
+ let(:path) { 'foo/bar/baz' }
58
+
59
+ it { should == 'baz' }
60
+ end
61
+ end
62
+
63
+ describe '#remove_ext' do
64
+ subject { remove_ext(path) }
65
+
66
+ context 'without directory ("foo.rb")' do
67
+ let(:path) { 'foo.rb' }
68
+
69
+ it { should == 'foo' }
70
+ end
71
+
72
+ context 'with directory ("foo/bar.rb")' do
73
+ let(:path) { 'foo/bar.rb' }
74
+
75
+ it { should == 'foo/bar' }
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: algerb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yuya Takeyama
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-31 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &28381860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *28381860
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &28381300 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *28381300
36
+ - !ruby/object:Gem::Dependency
37
+ name: cucumber
38
+ requirement: &28380260 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *28380260
47
+ - !ruby/object:Gem::Dependency
48
+ name: aruba
49
+ requirement: &28379700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *28379700
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-cucumber
60
+ requirement: &28378960 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *28378960
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &28378100 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *28378100
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-rspec
82
+ requirement: &28346620 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *28346620
91
+ - !ruby/object:Gem::Dependency
92
+ name: jeweler
93
+ requirement: &28346080 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.6.4
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *28346080
102
+ - !ruby/object:Gem::Dependency
103
+ name: rcov
104
+ requirement: &28345560 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *28345560
113
+ description: Generates autoloader script for your Ruby library.
114
+ email: sign.of.the.wolf.pentagram@gmail.com
115
+ executables:
116
+ - algerb
117
+ extensions: []
118
+ extra_rdoc_files:
119
+ - LICENSE.txt
120
+ - README.rdoc
121
+ files:
122
+ - .rspec
123
+ - .travis.yml
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - Guardfile
127
+ - LICENSE.txt
128
+ - README.rdoc
129
+ - Rakefile
130
+ - VERSION
131
+ - algerb.gemspec
132
+ - autoloader.rb
133
+ - bin/algerb
134
+ - features/autoloader_generation.feature
135
+ - features/step_definitions/autoloader_generation_steps.rb
136
+ - features/support/env.rb
137
+ - lib/algerb.rb
138
+ - lib/algerb/app.rb
139
+ - lib/algerb/file.rb
140
+ - lib/algerb/files.rb
141
+ - lib/algerb/files_builder.rb
142
+ - lib/algerb/generator.rb
143
+ - lib/algerb/util.rb
144
+ - spec/spec_helper.rb
145
+ - spec/unit/algerb/files_builder_spec.rb
146
+ - spec/unit/algerb/files_spec.rb
147
+ - spec/unit/algerb/generator_spec.rb
148
+ - spec/unit/algerb/util_spec.rb
149
+ homepage: http://github.com/yuya-takeyama/algerb
150
+ licenses:
151
+ - MIT
152
+ post_install_message:
153
+ rdoc_options: []
154
+ require_paths:
155
+ - lib
156
+ required_ruby_version: !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ segments:
163
+ - 0
164
+ hash: -1824357919057677533
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 1.8.10
174
+ signing_key:
175
+ specification_version: 3
176
+ summary: Autoloader generator for Ruby
177
+ test_files: []