tony 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.swp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tony.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tony (0.0.1)
5
+ rspec
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.1.2)
11
+ rspec (2.5.0)
12
+ rspec-core (~> 2.5.0)
13
+ rspec-expectations (~> 2.5.0)
14
+ rspec-mocks (~> 2.5.0)
15
+ rspec-core (2.5.1)
16
+ rspec-expectations (2.5.0)
17
+ diff-lcs (~> 1.1.2)
18
+ rspec-mocks (2.5.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ rspec
25
+ tony!
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs.'
7
+ task :default => :spec
8
+
9
+ desc "Run specs"
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
12
+ end
13
+
14
+ desc "Generate code coverage"
15
+ RSpec::Core::RakeTask.new(:coverage) do |t|
16
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
17
+ t.rcov = true
18
+ t.rcov_opts = ['--exclude', 'spec']
19
+ end
20
+
data/bin/tony ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/tony'
4
+ Tony.generate
@@ -0,0 +1,26 @@
1
+ require 'ostruct'
2
+ require 'fileutils'
3
+
4
+ module Tony
5
+ class Generator
6
+ attr_reader :name, :description, :files
7
+ def initialize(&block)
8
+ options = OpenStruct.new
9
+ yield options
10
+ @name = options.name
11
+ @description = options.description
12
+ @files = options.files
13
+ end
14
+
15
+ def generate
16
+ files.each do |path, contents|
17
+ FileUtils.mkdir_p(File.dirname(path))
18
+ puts "create #{path}" unless File.exist?(path)
19
+ puts "append #{path}" if File.exist?(path)
20
+ File.open(path, 'a') do |file|
21
+ file.puts(contents)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ Tony::generators << Tony::Generator.new do |options|
2
+ options.name = "rspec"
3
+ options.description = "Generates rspec rake tasks, spec directories and a spec_helper"
4
+ options.files = {
5
+ 'Rakefile' => <<-FILE
6
+ require 'rspec/core/rake_task'
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
11
+ end
12
+ FILE
13
+ }
14
+ end
data/lib/tony/tony.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Tony
2
+ def self.generators
3
+ @@generators = [] unless defined? @@generators
4
+ @@generators
5
+ end
6
+ def self.generate
7
+ ARGV.each do |argument|
8
+ generator = generators.find { |g| g.name == argument }
9
+ generator.generate
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Tony
2
+ VERSION = "0.0.1"
3
+ end
data/lib/tony.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative 'tony/tony'
2
+ require_relative 'tony/generator'
3
+ require_relative 'tony/generators/rspec_generator'
@@ -0,0 +1,104 @@
1
+ require_relative 'helper'
2
+
3
+ describe Tony::Generator do
4
+ before :each do
5
+ @test_directory = File.join(File.dirname(__FILE__), 'test')
6
+ Dir.mkdir(@test_directory)
7
+ end
8
+
9
+ after :each do
10
+ FileUtils.rm_rf(@test_directory)
11
+ end
12
+
13
+ it "takes a name" do
14
+ generator = Tony::Generator.new do |options|
15
+ options.name = "name"
16
+ end
17
+ generator.name.should == "name"
18
+ end
19
+
20
+ it "can be executed from the command line" do
21
+ ARGV = ['test_generator']
22
+ generator = Tony::Generator.new do |options|
23
+ options.name = "test_generator"
24
+ end
25
+ Tony::generators << generator
26
+ generator.should_receive(:generate)
27
+ Tony::generate
28
+ end
29
+
30
+ it "takes a description" do
31
+ generator = Tony::Generator.new do |options|
32
+ options.description = "description"
33
+ end
34
+ generator.description.should == "description"
35
+ end
36
+
37
+ it "takes files" do
38
+ expected_file_contents = {'file1' => 'file1 contents'}
39
+ generator = Tony::Generator.new do |options|
40
+ options.files = expected_file_contents
41
+ end
42
+ generator.files.should == expected_file_contents
43
+ end
44
+
45
+ describe ".generate" do
46
+ it "creates files if they don't exist" do
47
+ test_file = File.join(@test_directory, 'test.file')
48
+ generator = Tony::Generator.new { |options|
49
+ options.files = {
50
+ test_file => ''
51
+ }
52
+ }.generate
53
+ File.exist?(test_file).should == true
54
+ end
55
+
56
+ it "creates all directories below the file if they don't exist" do
57
+ non_existent_directory = File.join(@test_directory, 'non_existent_directory')
58
+ test_file = File.join(non_existent_directory, 'test.file')
59
+ generator = Tony::Generator.new { |options|
60
+ options.files = {
61
+ test_file => ''
62
+ }
63
+ }.generate
64
+ File.directory?(non_existent_directory).should == true
65
+ File.exist?(test_file).should == true
66
+ end
67
+
68
+ it "writes the specified text to the file" do
69
+ test_file = File.join(@test_directory, 'test.file')
70
+ file_contents = "this is some text"
71
+ generator = Tony::Generator.new { |options|
72
+ options.files = {
73
+ test_file => file_contents
74
+ }
75
+ }.generate
76
+ File.read(test_file).should == file_contents + "\n"
77
+ end
78
+
79
+ it "appends the specified text to the file if it exists" do
80
+ test_file = File.join(@test_directory, 'test.file')
81
+ generator = Tony::Generator.new { |options|
82
+ options.files = {
83
+ test_file => "hello"
84
+ }
85
+ }
86
+ generator.generate
87
+ generator.generate
88
+ File.read(test_file).should == "hello\nhello\n"
89
+ end
90
+
91
+ it "outputs information about whether the file was created or appended" do
92
+ test_file = File.join(@test_directory, 'test.file')
93
+ generator = Tony::Generator.new { |options|
94
+ options.files = {
95
+ test_file => ''
96
+ }
97
+ }
98
+ generator.should_receive(:puts).with("create #{test_file}")
99
+ generator.generate
100
+ generator.should_receive(:puts).with("append #{test_file}")
101
+ generator.generate
102
+ end
103
+ end
104
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'generators'))
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ require 'rspec'
5
+ require 'tony'
data/spec/tony_spec.rb ADDED
@@ -0,0 +1,4 @@
1
+ require_relative 'helper'
2
+
3
+ describe Tony do
4
+ end
data/tony.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tony/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tony"
7
+ s.version = Tony::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Andrew Vos"]
10
+ s.email = ["andrew.vos@gmail.com"]
11
+ s.homepage = "https://github.com/AndrewVos/tony"
12
+ s.summary = %q{A generator for ruby projects}
13
+ s.description = %q{A generator for ruby projects}
14
+
15
+ s.rubyforge_project = "tony"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ s.bindir = 'bin'
22
+ s.executables = ['tony']
23
+ s.add_dependency 'rspec'
24
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tony
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Andrew Vos
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-08 00:00:00 +01: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
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: A generator for ruby projects
34
+ email:
35
+ - andrew.vos@gmail.com
36
+ executables:
37
+ - tony
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - .gitignore
44
+ - .rspec
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - Rakefile
48
+ - bin/tony
49
+ - lib/tony.rb
50
+ - lib/tony/generator.rb
51
+ - lib/tony/generators/rspec_generator.rb
52
+ - lib/tony/tony.rb
53
+ - lib/tony/version.rb
54
+ - spec/generator_spec.rb
55
+ - spec/helper.rb
56
+ - spec/tony_spec.rb
57
+ - tony.gemspec
58
+ has_rdoc: true
59
+ homepage: https://github.com/AndrewVos/tony
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: tony
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A generator for ruby projects
90
+ test_files:
91
+ - spec/generator_spec.rb
92
+ - spec/helper.rb
93
+ - spec/tony_spec.rb