Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Migrate a first project structure with ruby tools.

  • Loading branch information...
commit cfbcbe7346c0511685562cda749db09df4da0416 0 parents
@blambeau authored
23 .autotest
@@ -0,0 +1,23 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+# Autotest.add_hook :initialize do |at|
+# at.extra_files << "../some/external/dependency.rb"
+#
+# at.libs << ":../some/external"
+#
+# at.add_exception 'vendor'
+#
+# at.add_mapping(/dependency.rb/) do |f, _|
+# at.files_matching(/test_.*rb$/)
+# end
+#
+# %w(TestA TestB).each do |klass|
+# at.extra_class_map[klass] = "test/test_misc.rb"
+# end
+# end
+
+# Autotest.add_hook :run_command do |at|
+# system "rake build"
+# end
6 History.txt
@@ -0,0 +1,6 @@
+=== 1.0.0 / 2010-12-22
+
+* 1 major enhancement
+
+ * Birthday!
+
7 Manifest.txt
@@ -0,0 +1,7 @@
+History.txt
+Manifest.txt
+README.txt
+Rakefile
+bin/minicom
+lib/minicom.rb
+test/test_minicom.rb
44 README.md
@@ -0,0 +1,44 @@
+# minicom
+
+* http://github.com/blambeau/minicom
+
+## DESCRIPTION:
+
+Minicom helps you create commandline programs.
+
+## FEATURES/PROBLEMS:
+
+## SYNOPSIS:
+
+Minicom helps you create commandline programs.
+
+## REQUIREMENTS:
+
+## INSTALL:
+
+ sudo gem install minicom
+
+## LICENSE:
+
+ (The MIT License)
+
+ Copyright (c) 2010 Bernard Lambeau <blambeau@gmail.com>
+
+ 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.
21 Rakefile
@@ -0,0 +1,21 @@
+# -*- ruby -*-
+$here = File.dirname(__FILE__)
+require 'rubygems'
+require 'hoe'
+require 'spec/rake/spectask'
+
+desc "Run all rspec test"
+Spec::Rake::SpecTask.new(:spec) do |t|
+ t.ruby_opts = ['-I.', '-Ilib', '-Itest']
+ t.spec_files = Dir["#{$here}/test/**/*.spec"]
+end
+
+# Hoe specification
+Hoe.spec 'minicom' do
+ self.developer('Bernard Lambeau', 'blambeau@gmail.com')
+ self.readme_file = 'README.md'
+ self.extra_rdoc_files = FileList['README.md']
+ self.extra_dev_deps << [ 'hoe', '>= 2.8.0' ]
+end
+
+# vim: syntax=ruby
3  bin/minicom
@@ -0,0 +1,3 @@
+#!/usr/bin/env ruby
+
+abort "you need to write me"
6 lib/minicom.rb
@@ -0,0 +1,6 @@
+require 'minicom/ruby_tools'
+module Minicom
+
+ VERSION = '0.1.0'
+
+end
78 lib/minicom/ruby_tools.rb
@@ -0,0 +1,78 @@
+module Minicom
+ module RubyTools
+
+ # Returns the parent module of a class
+ def parent_module(clazz)
+ name = clazz.name
+ if name =~ /^(.*?)::([^:]+)$/
+ Kernel.eval($1)
+ else
+ nil
+ end
+ end
+
+ # Returns the unqualified name of a class
+ def class_unqualified_name(clazz)
+ name = clazz.name
+ if name =~ /::([^:]+)$/
+ $1
+ else
+ name
+ end
+ end
+ alias :unqualified_class_name :class_unqualified_name
+
+ # Makes a call to a block that accepts optional arguments
+ def optional_args_block_call(block, args)
+ if RUBY_VERSION >= "1.9.0"
+ if block.arity == 0
+ block.call
+ else
+ block.call(*args)
+ end
+ else
+ block.call(*args)
+ end
+ end
+
+ # Extracts the rdoc of a given ruby file source
+ def extract_file_rdoc(file)
+ source, doc, started = File.read(file), "", false
+ source.each_line{|line|
+ if /^\s*[#]/ =~ line
+ doc << line
+ started = true
+ elsif started
+ break
+ end
+ }
+ doc.gsub(/^\s*[#] ?/, "")
+ end
+
+ # Splits a text obtained through extract_file_rdoc into paragraphs
+ def rdoc_paragraphs(rdoc_text)
+ paragraphs, current = [], ""
+ rdoc_text.each_line do |s|
+ if s.strip.empty?
+ unless current.strip.empty?
+ paragraphs << current
+ end
+ current = ""
+ else
+ current << s
+ end
+ end
+ unless current.strip.empty?
+ paragraphs << current
+ end
+ paragraphs
+ end
+
+ # Convenient method for <code>rdoc_paragraphs(extract_file_rdoc(file))</code>
+ def rdoc_file_paragraphs(file)
+ rdoc_paragraphs(extract_file_rdoc(file))
+ end
+
+ extend(RubyTools)
+ end # module RubyTools
+end # module Minicom
28 test/ruby_tools/class_unqualified_name.spec
@@ -0,0 +1,28 @@
+require File.expand_path('../fixtures', __FILE__)
+module Minicom
+ describe "RubyTools#class_unqualified_name /" do
+
+ subject{ RubyTools::class_unqualified_name(clazz) }
+
+ describe "when called on unqualified class" do
+ let(:clazz){ ::String }
+ it{ should == "String" }
+ end
+
+ describe "when called on qualified class" do
+ let(:clazz){ RubyTools }
+ it{ should == "RubyTools" }
+ end
+
+ describe "when called on long qualified class" do
+ let(:clazz){ Minicom::Fixtures::Utils }
+ it{ should == "Utils" }
+ end
+
+ describe "when piped with parent_module" do
+ let(:clazz){ RubyTools::parent_module(Minicom::Fixtures::Utils) }
+ it{ should == "Fixtures" }
+ end
+
+ end
+end
12 test/ruby_tools/extract_file_rdoc.spec
@@ -0,0 +1,12 @@
+require File.expand_path('../fixtures', __FILE__)
+module Minicom
+ describe "RubyTools#extract_file_rdoc /" do
+
+ subject{ RubyTools::extract_file_rdoc(File.expand_path('../fixtures.rb', __FILE__)) }
+
+ it "should be as expected" do
+ subject.should == File.read(File.expand_path('../fixtures/rdoc.txt', __FILE__))
+ end
+
+ end
+end
21 test/ruby_tools/fixtures.rb
@@ -0,0 +1,21 @@
+require File.expand_path('../../spec_helper', __FILE__)
+module Minicom
+ module Fixtures
+ #
+ # This is a fixtures helper that matches documentation conventions.
+ #
+ # This is a second paragraph
+ # That append on two lines
+ #
+ #
+ # WARNING:
+ # This kind of indentation should not be interpreted as code
+ #
+ # But this one yes
+ #
+ module RubyTools
+ end # module RubyTools
+ module Utils
+ end # module Utils
+ end # module Fixtures
+end # module Minicom
12 test/ruby_tools/fixtures/rdoc.txt
@@ -0,0 +1,12 @@
+
+This is a fixtures helper that matches documentation conventions.
+
+This is a second paragraph
+That append on two lines
+
+
+WARNING:
+ This kind of indentation should not be interpreted as code
+
+ But this one yes
+
37 test/ruby_tools/optional_args_block_call.spec
@@ -0,0 +1,37 @@
+require File.expand_path('../fixtures', __FILE__)
+module Minicom
+ describe "RubyTools#optional_args_block_call /" do
+
+ subject{ RubyTools::optional_args_block_call(block, args) }
+
+ describe "when block has no arguments /" do
+ let(:block){ lambda {
+ "ok"
+ } }
+
+ describe "when no args are given" do
+ let(:args){ [ ] }
+ it { should == "ok" }
+ end
+
+ describe "when no args are given" do
+ let(:args){ [ "hello" ] }
+ it { should == "ok" }
+ end
+
+ end
+
+ describe "when block has one arguments /" do
+ let(:block){ lambda {|name|
+ name
+ } }
+
+ describe "when args are given" do
+ let(:args){ [ "hello" ] }
+ it { should == "hello" }
+ end
+
+ end
+
+ end
+end
23 test/ruby_tools/parent_module.spec
@@ -0,0 +1,23 @@
+require File.expand_path('../fixtures', __FILE__)
+module Minicom
+ describe "RubyTools#parent_module /" do
+
+ subject{ RubyTools::parent_module(clazz) }
+
+ describe "when called on unqualified class" do
+ let(:clazz){ ::String }
+ it{ should be_nil }
+ end
+
+ describe "when called on qualified class" do
+ let(:clazz){ RubyTools }
+ it{ should == Minicom }
+ end
+
+ describe "when called on long qualified class" do
+ let(:clazz){ Minicom::Fixtures::Utils }
+ it{ should == Minicom::Fixtures }
+ end
+
+ end
+end
15 test/ruby_tools/rdoc_file_paragraphs.spec
@@ -0,0 +1,15 @@
+require File.expand_path('../fixtures', __FILE__)
+module Minicom
+ describe "RubyTools#extract_file_rdoc /" do
+
+ subject{ RubyTools::rdoc_file_paragraphs(File.expand_path('../fixtures.rb', __FILE__)) }
+
+ it "should be as expected" do
+ subject.should == ["This is a fixtures helper that matches documentation conventions.\n",
+ "This is a second paragraph\nThat append on two lines\n",
+ "WARNING:\n This kind of indentation should not be interpreted as code\n",
+ " But this one yes\n"]
+ end
+
+ end
+end
12 test/spec_helper.rb
@@ -0,0 +1,12 @@
+dir = File.dirname(__FILE__)
+$LOAD_PATH.unshift "#{dir}/../lib"
+
+require 'rubygems'
+require 'spec'
+require 'spec/autorun'
+require 'pp'
+require 'fileutils'
+require 'minicom'
+
+Spec::Runner.configure do |config|
+end
Please sign in to comment.
Something went wrong with that request. Please try again.