Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 1a830a8cb0a1ac8c1d17e2736b50fc464700f476 0 parents
@benlangfeld authored
7 .gitignore
@@ -0,0 +1,7 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+.*.swp
+.*.swo
+coverage/
3  .rspec
@@ -0,0 +1,3 @@
+--format documentation
+--colour
+--tty
4 CHANGELOG.md
@@ -0,0 +1,4 @@
+# develop
+
+# v0.0.1
+ * First release!
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in class_lister.gemspec
+gemspec
5 Guardfile
@@ -0,0 +1,5 @@
+guard 'rspec', :version => 2, :cli => '--format documentation' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec/" }
+end
22 LICENSE.txt
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2012 Ben Langfeld
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 README.md
@@ -0,0 +1,51 @@
+class_lister
+===========
+
+Lists all classes under a given module.
+
+Install
+-------
+
+ gem install class_lister
+
+Examples
+--------
+
+```ruby
+ require 'class_lister'
+
+ module Foo
+ VERSION = 2
+ class Bar; end
+ class Baz; end
+ end
+
+ ClassLister.list Foo
+ # => [Foo::Bar, Foo::Baz]
+```
+
+Author
+------
+
+Original author: Ben Langfeld
+
+Links
+-----
+* [Source](https://github.com/benlangfeld/class_lister)
+* [Documentation](http://rdoc.info/github/benlangfeld/class_lister/master/frames)
+* [Bug Tracker](https://github.com/benlangfeld/class_lister/issues)
+
+Note on Patches/Pull Requests
+-----------------------------
+
+* Fork the project.
+* Make your feature addition or bug fix.
+* Add tests for it. This is important so I don't break it in a future version unintentionally.
+* Commit, do not mess with rakefile, version, or history.
+ * If you want to have your own version, that is fine but bump version in a commit by itself so I can ignore when I pull
+* Send me a pull request. Bonus points for topic branches.
+
+Copyright
+---------
+
+Copyright (c) 2012 Ben Langfeld. MIT licence (see LICENSE for details).
23 Rakefile
@@ -0,0 +1,23 @@
+begin
+ require 'bones'
+rescue LoadError
+ abort '### Please install the "bones" gem ###'
+end
+
+require 'bundler/gem_tasks'
+
+task :default => :spec
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+require 'ci/reporter/rake/rspec'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rspec_opts = '--color'
+end
+
+task :default => :spec
+task :ci => ['ci:setup:rspec', :spec]
+
+require 'yard'
+YARD::Rake::YardocTask.new
26 class_lister.gemspec
@@ -0,0 +1,26 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "class_lister/version"
+
+Gem::Specification.new do |s|
+ s.name = "class_lister"
+ s.version = ClassLister::VERSION
+ s.authors = ["Ben Langfeld"]
+ s.email = ["ben@langfeld.me"]
+ s.homepage = "http://github.com/benlangfeld/class_lister"
+ s.summary = %q{Lists all classes under a given module.}
+ s.description = %q{Lists all classes under a given module.}
+
+ s.rubyforge_project = "class_lister"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ s.add_development_dependency %q<bundler>, ["~> 1.1"]
+ s.add_development_dependency %q<rspec>, [">= 2.5.0"]
+ s.add_development_dependency %q<yard>, ["~> 0.6.0"]
+ s.add_development_dependency %q<rake>, [">= 0"]
+ s.add_development_dependency %q<guard-rspec>
+end
18 lib/class_lister.rb
@@ -0,0 +1,18 @@
+require "class_lister/version"
+
+module ClassLister
+ class << self
+ def list(mod)
+ list_all(mod).flatten.select { |c| c.is_a? Class }
+ end
+
+ def list_all(mod)
+ mod.constants.map do |c|
+ const = mod.const_get c
+ [const] + ClassLister.list_all(const)
+ end
+ rescue
+ []
+ end
+ end
+end
3  lib/class_lister/version.rb
@@ -0,0 +1,3 @@
+module ClassLister
+ VERSION = "0.0.1"
+end
32 spec/class_lister_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe ClassLister do
+ module TestModule
+ VERSION = :foo
+
+ class A
+ class C; end
+
+ module D
+ class E; end
+ end
+ end
+
+ module B
+ class F; end
+ end
+
+ module G; end
+ end
+
+ describe "#list" do
+ it "should list all classes within the specified namespace" do
+ described_class.list(TestModule).should be == [
+ TestModule::A,
+ TestModule::A::C,
+ TestModule::A::D::E,
+ TestModule::B::F
+ ]
+ end
+ end
+end
8 spec/spec_helper.rb
@@ -0,0 +1,8 @@
+require 'class_lister'
+
+Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+ config.filter_run :focus => true
+ config.run_all_when_everything_filtered = true
+end
Please sign in to comment.
Something went wrong with that request. Please try again.