metafusion-thor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ module Metafusion
2
+ module Thor
3
+ end
4
+ end
5
+
6
+ require 'yaml'
7
+
8
+ require 'metafusion/thor/version'
9
+ require 'metafusion/thor/meta'
10
+
11
+ require 'metafusion/thor/core'
@@ -0,0 +1,27 @@
1
+ # File that includes extensions to the Ruby standard library and core APIs
2
+ # in the Metafusion::Thor library.
3
+ module Metafusion
4
+ module Thor
5
+ # Module that contains core reusable features
6
+ module Core
7
+ class ThorUndefinedProjectName < Exception; end
8
+ end
9
+ end
10
+ end
11
+
12
+ require('thor')
13
+
14
+ class Thor
15
+ def project_name
16
+ raise ::Metafusion::Thor::Core::ThorUndefinedProjectName, "Please define a project_name methods in your Thor subclass that returns the name of your project"
17
+ end
18
+
19
+ desc "gem", "Build gem from .gemspec file"
20
+ def gem
21
+ path = project_name + ".gemspec"
22
+ gemspec = eval(File.read(path))
23
+ builder = Gem::Builder.new(gemspec)
24
+ builder.build
25
+ end
26
+ end
27
+
@@ -0,0 +1,57 @@
1
+ # meta.rb contains <tt>Metafusion::Thor::Meta</tt> and related classes that
2
+ # help define the metadata of the <tt>metafusion-thor</tt> project.
3
+
4
+ require('rubygems')
5
+ require('erb')
6
+
7
+ class Metafusion::Thor::Meta #:nodoc:
8
+ attr_accessor :root_dir
9
+ attr_reader :gem_spec, :project_files, :spec_files
10
+
11
+ # Initializer for Metafusion::Thor::Meta class. Takes <tt>root_dir</tt> as parameter.
12
+ def initialize(root_dir)
13
+ @root_dir = root_dir
14
+ end
15
+
16
+ # Returns package information defined in <tt>root_dir</tt>/pkg-info.yml
17
+ def pkg_info
18
+ yaml_file = File.join(@root_dir, 'pkg-info.yml')
19
+ ryaml = ERB.new(File.read(yaml_file), 0)
20
+ s = ryaml.result(binding)
21
+ YAML.load(s)
22
+ end
23
+
24
+ # Returns RubyGems spec information
25
+ def spec_info
26
+ self.pkg_info['spec'] if self.pkg_info
27
+ end
28
+
29
+ # Returns list of project files
30
+ def project_files
31
+ @project_files ||= Dir.glob(File.join(@root_dir, 'lib/**/*.rb'))
32
+ @project_files
33
+ end
34
+
35
+ # Returns list of specification files
36
+ def spec_files
37
+ @spec_files ||= Dir.glob(File.join(@root_dir, 'spec/**/*_spec.rb'))
38
+ @spec_files
39
+ end
40
+
41
+ # Returns RubyGem specification for Metafusion::Thor project
42
+ def gem_spec
43
+ @gem_spec ||= Gem::Specification.new do |spec|
44
+ self.spec_info.each do |key, val|
45
+ # if val.is_a?(Hash)
46
+ # puts val.inspect
47
+ # val.each do |k, v|
48
+ # spec.send(key, k, v)
49
+ # end
50
+ # else
51
+ spec.send("#{key}=", val)
52
+ # end
53
+ end
54
+ end
55
+ @gem_spec
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ # version.rb contains <tt>Metafusion::Thor::Version</tt> that provides helper
2
+ # methods related to versioning of the <tt>metafusion-thor</tt> project.
3
+
4
+ module Metafusion::Thor::Version #:nodoc:
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ REVISION = 0
8
+ class << self
9
+ # Returns X.Y.Z formatted version string
10
+ def to_version
11
+ "#{MAJOR}.#{MINOR}.#{REVISION}"
12
+ end
13
+
14
+ # Returns X-Y-Z formatted version name
15
+ def to_name
16
+ "#{MAJOR}_#{MINOR}_#{REVISION}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,59 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ require('metafusion/thor/core')
4
+
5
+ describe Metafusion::Thor::Core do
6
+ include Metafusion::Thor::Core
7
+ end
8
+
9
+ describe Metafusion::Thor::Core::ThorUndefinedProjectName do
10
+ before(:all) do
11
+ @class = Metafusion::Thor::Core::ThorUndefinedProjectName
12
+ end
13
+
14
+ it "should have superclass Exception" do
15
+ @class.superclass.should be(Exception)
16
+ end
17
+ end
18
+
19
+ describe Thor do
20
+ before(:each) do
21
+ @thor = Thor.new
22
+ end
23
+
24
+ describe "#project_name" do
25
+ it "should raise PersonalLife::Core::ThorUndefinedProjectName exception when calling default project_name instance method" do
26
+ lambda {
27
+ @thor.project_name
28
+ }.should raise_error(Metafusion::Thor::Core::ThorUndefinedProjectName)
29
+ end
30
+ end
31
+
32
+ describe "#gem" do
33
+ before(:each) do
34
+ @project_name = "test"
35
+ @gemspec_contents = ""
36
+ @thor.stub!(:project_name).and_return(@project_name)
37
+ File.stub!(:read).and_return(@gemspec_contents)
38
+ @builder = mock(Gem::Builder)
39
+ @builder.stub!(:build)
40
+ Gem::Builder.stub!(:new).and_return(@builder)
41
+ end
42
+
43
+ it "should read [project_name].gemspec file" do
44
+ File.should_receive(:read).with(@project_name + ".gemspec").and_return(@gemspec_contents)
45
+ @thor.gem
46
+ end
47
+
48
+ it "should create a Gem::Builder object" do
49
+ Gem::Builder.should_receive(:new).and_return(@builder)
50
+ @thor.gem
51
+ end
52
+
53
+ it "should build the Gem::Builder object" do
54
+ @builder.should_receive(:build)
55
+ @thor.gem
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,90 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ def glob_files(*path_elements)
4
+ Dir.glob(File.join(*path_elements))
5
+ end
6
+
7
+ def load_erb_yaml(path, context)
8
+ ryaml = ERB.new(File.read(path), 0)
9
+ YAML.load(ryaml.result(context))
10
+ end
11
+
12
+ module ERBMetaMixin
13
+ # Needed to make the YAML load work...
14
+ def project_files
15
+ glob_files(@root_dir, 'lib', '**/*.rb')
16
+ end
17
+
18
+ # Needed to make the YAML load work...
19
+ def spec_files
20
+ glob_files(@root_dir, 'spec', '**/*_spec.rb')
21
+ end
22
+ end
23
+
24
+ describe "Metafusion::Thor::Meta cache policy" do
25
+ include ERBMetaMixin
26
+ before(:each) do
27
+ @root_dir = project_root_dir
28
+ @meta = Metafusion::Thor::Meta.new(@root_dir)
29
+ @expected_pkg_info = load_erb_yaml(File.join(@root_dir, 'pkg-info.yml'), binding)
30
+ @expected_project_files = project_files
31
+ @expected_spec_files = spec_files
32
+ end
33
+
34
+ it "should store value returned from project_files in @project_files after first glob" do
35
+ @meta.instance_eval("@project_files").should eql(nil)
36
+ @meta.project_files
37
+ @meta.instance_eval("@project_files").should eql(@expected_project_files)
38
+ @meta.project_files
39
+ @meta.instance_eval("@project_files").should eql(@expected_project_files)
40
+ end
41
+
42
+ it "should store value returned from spec_files in @spec_files after first glob" do
43
+ @meta.instance_eval("@spec_files").should eql(nil)
44
+ @meta.spec_files
45
+ @meta.instance_eval("@spec_files").should eql(@expected_spec_files)
46
+ @meta.spec_files
47
+ @meta.instance_eval("@spec_files").should eql(@expected_spec_files)
48
+ end
49
+ end
50
+
51
+ describe "Metafusion::Thor::Meta" do
52
+ include ERBMetaMixin
53
+ before(:each) do
54
+ @root_dir = project_root_dir
55
+ @meta = Metafusion::Thor::Meta.new(@root_dir)
56
+ @expected_yaml_hash = load_erb_yaml(File.join(@root_dir, 'pkg-info.yml'), binding)
57
+ @expected_project_files = project_files
58
+ @expected_spec_files = spec_files
59
+ end
60
+
61
+ it "should load and return YAML file into Hash object upon #pkg_info call" do
62
+ yaml_hash = @meta.pkg_info
63
+ yaml_hash.should.eql? @expected_yaml_hash
64
+ end
65
+
66
+ it "should return the embedded hash responding to key 'spec' of #pkg_info call upon #spec_info call" do
67
+ yaml_hash = @meta.spec_info
68
+ yaml_hash.should.eql? @expected_yaml_hash['spec']
69
+ end
70
+
71
+ it "should return list of files matching ROOT_DIR/lib/**/*.rb upon #project_files call" do
72
+ project_files = @meta.project_files
73
+ project_files.should.eql? @expected_project_files
74
+ end
75
+
76
+ it "should return list of files matching ROOT_DIR/spec/**/*.rb upon #spec_files call" do
77
+ spec_files = @meta.spec_files
78
+ spec_files.should.eql? @expected_spec_files
79
+ end
80
+
81
+ it "should return Gem specification based on YAML file contents and #project_files and #spec_files return values" do
82
+ spec = @meta.gem_spec
83
+ expected_spec_hash = @expected_yaml_hash['spec']
84
+ expected_spec_hash.each do |key, val|
85
+ unless val.is_a?(Hash)
86
+ spec.send(key).to_s.should eql(expected_spec_hash[key].to_s)
87
+ end
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', '..', 'spec_helper')
2
+
3
+ VERSION_LIST = [Metafusion::Thor::Version::MAJOR, Metafusion::Thor::Version::MINOR, Metafusion::Thor::Version::REVISION]
4
+
5
+ EXPECTED_VERSION = VERSION_LIST.join('.')
6
+ EXPECTED_NAME = VERSION_LIST.join('_')
7
+
8
+ describe Metafusion::Thor::Version, ".to_version" do
9
+ it "should return #{EXPECTED_VERSION}" do
10
+ Metafusion::Thor::Version.to_version.should eql(EXPECTED_VERSION)
11
+ end
12
+ end
13
+
14
+ describe Metafusion::Thor::Version, ".to_name" do
15
+ it "should return #{EXPECTED_NAME}" do
16
+ Metafusion::Thor::Version.to_name.should eql(EXPECTED_NAME)
17
+ end
18
+ end
19
+
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metafusion-thor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Susan Potter
8
+ autorequire: metafusion/thor
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-02 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: metafusion@googlegroups.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/metafusion/thor/meta.rb
26
+ - lib/metafusion/thor/version.rb
27
+ - lib/metafusion/thor/core.rb
28
+ - lib/metafusion/thor.rb
29
+ - spec/metafusion/thor/meta_spec.rb
30
+ - spec/metafusion/thor/core_spec.rb
31
+ - spec/metafusion/thor/version_spec.rb
32
+ has_rdoc: true
33
+ homepage: http://metafusion.rubyforge.org
34
+ post_install_message:
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.6
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements:
52
+ - Ruby 1.8.6+
53
+ rubyforge_project: metafusion
54
+ rubygems_version: 1.3.1
55
+ signing_key:
56
+ specification_version: 2
57
+ summary: Provides Thor extensions for any type of Ruby project.
58
+ test_files: []
59
+