rplusplus 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af2b70a8e4415e61ee91023a7d5d39aa2ad373e6
4
- data.tar.gz: ad4ef2a7baf8ba17fd0b158ca765e424bd962cb7
3
+ metadata.gz: 1f11712f1e2e7bfb1949089f363d8e99bd588125
4
+ data.tar.gz: e21fa0e4daaf9185ea35878a74e3ee7905817f4e
5
5
  SHA512:
6
- metadata.gz: 9a301b16027df9bb54809759621ef511dd35e9b4a02a7dc6208fb62c6d71035d29d54de146306998494e3c95f1af9c287b7a046a8f2d6547bba83caf255586bc
7
- data.tar.gz: 9c02e6a66f19a2e2562d7ee014178931caaef0628a787971f9acb539a1539a595204f9e0f8dc2cf6597aada134d74204309219f2c153c8133c3a1ca562fc8a34
6
+ metadata.gz: c14309834c20d92ca82239aba502400cc64e12ec74916a3c43c8a06484a8b141feb46aa550b58b2ff18282125043716e4a556b0695f5145769148e4cc6fe9662
7
+ data.tar.gz: d6d06c50765b6a6078971ad2644b957bdc4558054bfbef4b33dd62998b776accd692bb9499c75ee77d3f1938c1ad662662977defafd509bb503f48d2ec980396
data/README.md CHANGED
@@ -2,9 +2,7 @@
2
2
 
3
3
  Making C++ slightly less painful.
4
4
 
5
- Of all the horrid languages to ever exist, C++ has to be the most widely used. R++ aims to being a collection of command-line utilities and magical fairy dust to make all the C++ monsters go away and let you, as the awesome programmer, get to what's important.
6
-
7
- R++ also aims to bring some kind of order to the world of C++ by following the principle of convention over configuration.
5
+ R++ aims to being a collection of command-line utilities and magical fairy dust to make all the C++ monsters go away and let you, as the awesome programmer, get to what's important.
8
6
 
9
7
  WARNING: I just started this project so functionality is super limited. You have been warned!
10
8
 
@@ -14,8 +12,6 @@ WARNING: I just started this project so functionality is super limited. You have
14
12
 
15
13
  ## Using it in your Rakefile
16
14
 
17
- This bit of functionality exists, and it's super useful (but still in BETA):
18
-
19
15
  In your Rakefile, do this:
20
16
 
21
17
  ```
@@ -23,11 +19,11 @@ require 'rplusplus'
23
19
  env = RPlusPlus::Environment.new
24
20
  ```
25
21
 
26
- Now, env has some useful properties:
22
+ Now, env has some useful properties which you can make use of in your Rake tasks:
27
23
 
28
- * `env.objects` contains a hash of the form `'foo.o' => ['foo.cpp', 'foo.h', ...]` which you can use for creating file tasks for all your o-files.
29
- * `env.builds` contains a hash of the form `'main' => ['main.o', 'foo.o', ...]` which you can use for file tasks for all your executables.
30
- * `env.erbs` contains a hash of the form `'foo.cpp' => ['foo.cpp.erb']` so you can make file tasks for generating source code from embedded ruby source files.
24
+ * `env.objects` is a hash of the form `'foo.o' => ['foo.cpp', 'foo.h', ...]`
25
+ * `env.builds` is a hash of the form `'main' => ['main.o', 'foo.o', ...]`
26
+ * `env.erbs` is a hash of the form `'foo.cpp' => ['foo.cpp.erb']`
31
27
 
32
28
  `env.objects` and `env.builds` magically take into account any `*.erb` files in existence so you can just code away without any funny business.
33
29
 
@@ -41,6 +37,8 @@ The builds are discovered by finding each cpp file with a main function, and the
41
37
 
42
38
  The ERB dependencies are simply computed by finding each erb file and then removing the erb extention.
43
39
 
40
+ Go ahead and crack open that codebase and see for yourself!
41
+
44
42
  ## Ideas for the soon-to-exist command-line tool
45
43
 
46
44
  Make a new C++ app, with a Rakefile, .gitignore, and some skeleton source files:
@@ -49,13 +47,6 @@ Make a new C++ app, with a Rakefile, .gitignore, and some skeleton source files:
49
47
  $ r++ new MyApp
50
48
  ```
51
49
 
52
- Some other things I plan on including:
53
-
54
- Work out the dependencies a-la `g++ -MM`, except in rake-friendly syntax instead of Make:
55
- ```
56
- $ r++ -MM some_code.cpp
57
- ```
58
-
59
50
  Generates a header and source file skeleton for a class:
60
51
  ```
61
52
  $ r++ generate class MyClass
@@ -67,12 +58,13 @@ $ r++ generate class MyClass
67
58
  * Add some magical C++ code generating libraries to use with ERB.
68
59
  * Make it easy for people to package their library or app or whatever into a deb or an rpm or a pkg or a whatever using a config file called a "libspec" or something (a-la "gemspec").
69
60
  * On that note, make it easy for people to publish to a package repository (apt, yum, aur, etc).
61
+ * Get a better name perhaps, I don't thing "R++" is the best name for this, since it's already been used by a past, failed project (we might pick up its bad luck or something).
70
62
 
71
63
  ## Disclaimer
72
64
 
73
65
  This has absolutely nothing to do with Bell labs R++.
74
66
 
75
- ## I want you to help make R++ better for everyone.
67
+ ## Help me make R++ better for everyone! :)
76
68
 
77
69
  The easiest way to contribute is to try this thing out and submit an issue when it breaks.
78
70
 
data/bin/r++ ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rplusplus'
4
+
5
+ RPlusPlus.call ARGV
data/lib/rplusplus.rb CHANGED
@@ -1,5 +1,14 @@
1
+ require 'active_support/all'
2
+
1
3
  require "rplusplus/version"
2
- require "environment"
4
+ require "rplusplus/environment"
5
+ require "rplusplus/command"
6
+ require "rplusplus/commands/generate"
7
+ require "rplusplus/generators/class_generator"
3
8
 
4
9
  module RPlusPlus
10
+ def self.call argv
11
+ command, *arguments = *argv
12
+ Command.call command, *arguments
13
+ end
5
14
  end
@@ -0,0 +1,26 @@
1
+ module RPlusPlus
2
+ class Command
3
+ def self.commands
4
+ @@commands ||= {}
5
+ end
6
+
7
+ def self.register name, command
8
+ self.commands[name] = command
9
+ end
10
+
11
+ def self.list
12
+ self.commands.keys
13
+ end
14
+
15
+ def self.call name, *args
16
+ name = name.to_sym
17
+ if !self.commands.has_key? name
18
+ raise MissingCommandError.new("'#{name}' is not a r++ command")
19
+ end
20
+ self.commands[name].call(*args)
21
+ end
22
+
23
+ class MissingCommandError < StandardError
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,30 @@
1
+ module RPlusPlus
2
+ module Commands
3
+ class Generate
4
+ Command.register :generate, self
5
+
6
+ def self.generators
7
+ @@generators ||= {}
8
+ end
9
+
10
+ def self.register name, generator
11
+ self.generators[name.to_sym] = generator
12
+ end
13
+
14
+ def self.list
15
+ self.generators.keys
16
+ end
17
+
18
+ def self.call name, *args
19
+ name = name.to_sym
20
+ if !self.generators.has_key? name
21
+ raise MissingGeneratorError.new("'#{name}' is not a r++ generator")
22
+ end
23
+ self.generators[name].call(*args)
24
+ end
25
+
26
+ class MissingGeneratorError < StandardError
27
+ end
28
+ end
29
+ end
30
+ end
File without changes
@@ -0,0 +1,27 @@
1
+ module RPlusPlus
2
+ module Generators
3
+ class ClassGenerator
4
+ Commands::Generate.register :class, self
5
+
6
+ def self.call class_name
7
+ File.write("#{class_name.underscore}.h", header_erb.result(binding))
8
+ File.write("#{class_name.underscore}.cpp", class_erb.result(binding))
9
+ end
10
+
11
+ class << self
12
+ private
13
+ def template_dir
14
+ File.join File.dirname(__FILE__), '../templates'
15
+ end
16
+
17
+ def class_erb
18
+ ERB.new(File.read(File.join(template_dir, 'class.erb')))
19
+ end
20
+
21
+ def header_erb
22
+ ERB.new(File.read(File.join(template_dir, 'class_header.erb')))
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ #include "<%= class_name.underscore.downcase %>.h"
2
+
3
+ <%= class_name %>::<%= class_name %>() {
4
+
5
+ }
6
+
7
+ <%= class_name %>::~<%= class_name %>() {
8
+
9
+ }
@@ -0,0 +1,12 @@
1
+ #ifndef <%= class_name.underscore.upcase %>_H
2
+ #define <%= class_name.underscore.upcase %>_H
3
+
4
+ class <%= class_name %> {
5
+ public:
6
+ <%= class_name %>();
7
+ virtual ~<%= class_name %>();
8
+
9
+ private:
10
+ };
11
+
12
+ #endif
@@ -1,3 +1,3 @@
1
1
  module Rplusplus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/rplusplus.gemspec CHANGED
@@ -20,7 +20,11 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = '>= 1.9.3'
22
22
 
23
+ spec.add_runtime_dependency "activesupport", "~> 4.2"
24
+
23
25
  spec.add_development_dependency "bundler", "~> 1.6"
24
26
  spec.add_development_dependency "rake", "~> 10.3"
25
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry", "~> 0.10"
29
+ spec.add_development_dependency "fakefs", "~> 0.6"
26
30
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe RPlusPlus::Command do
4
+ let(:fake_command) { spy('command') }
5
+ after do
6
+ RPlusPlus::Command.commands.delete :test_command
7
+ end
8
+
9
+ describe '#register' do
10
+ it 'registers a command' do
11
+ RPlusPlus::Command::register :test_command, fake_command
12
+
13
+ expect(RPlusPlus::Command.commands).to include(:test_command => fake_command)
14
+ end
15
+ end
16
+
17
+ describe '#list' do
18
+ after do
19
+ [:foo, :bar, :baz].each { |x| RPlusPlus::Command.commands.delete x }
20
+ end
21
+
22
+ it 'lists all registered generators' do
23
+ RPlusPlus::Command.register(:foo, fake_command)
24
+ RPlusPlus::Command.register(:bar, fake_command)
25
+ RPlusPlus::Command.register(:baz, fake_command)
26
+
27
+ expect(RPlusPlus::Command.list).to include(:foo, :bar, :baz)
28
+ end
29
+ end
30
+
31
+ describe '#call' do
32
+ before do
33
+ RPlusPlus::Command.register :test_command, fake_command
34
+ end
35
+
36
+ it 'calls the specific command with the given arguments' do
37
+ RPlusPlus::Command.call :test_command, 'foo', 'bar', 'baz'
38
+
39
+ expect(fake_command).to have_received(:call).with('foo', 'bar', 'baz')
40
+ end
41
+
42
+ it 'converts command strings to symbols' do
43
+ RPlusPlus::Command.call 'test_command', 'foo', 'bar', 'baz'
44
+
45
+ expect(fake_command).to have_received(:call).with('foo', 'bar', 'baz')
46
+ end
47
+
48
+ it 'raises if the specific command does not exists' do
49
+ expect {
50
+ RPlusPlus::Command.call :nonexistent, :something
51
+ }.to raise_error(RPlusPlus::Command::MissingCommandError,
52
+ "'nonexistent' is not a r++ command")
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe RPlusPlus::Commands::Generate do
4
+ let(:fake_generator) { spy('generator') }
5
+
6
+ after do
7
+ RPlusPlus::Commands::Generate.generators.delete :test_generator
8
+ end
9
+
10
+ it 'registers itself with Command' do
11
+ expect(RPlusPlus::Command.commands).to include(
12
+ :generate => RPlusPlus::Commands::Generate)
13
+ end
14
+
15
+ describe '#register' do
16
+ it 'registers a generator' do
17
+ RPlusPlus::Commands::Generate.register(:test_generator, fake_generator)
18
+
19
+ expect(RPlusPlus::Commands::Generate.generators).to include(
20
+ :test_generator => fake_generator)
21
+ end
22
+ end
23
+
24
+ describe '#list' do
25
+ after do
26
+ [:foo, :bar, :baz].each { |x| RPlusPlus::Commands::Generate.generators.delete x }
27
+ end
28
+
29
+ it 'lists all registered generators' do
30
+ RPlusPlus::Commands::Generate.register(:foo, fake_generator)
31
+ RPlusPlus::Commands::Generate.register(:bar, fake_generator)
32
+ RPlusPlus::Commands::Generate.register(:baz, fake_generator)
33
+
34
+ expect(RPlusPlus::Commands::Generate.list).to include(:foo, :bar, :baz)
35
+ end
36
+ end
37
+
38
+ describe '#call' do
39
+ before do
40
+ RPlusPlus::Commands::Generate.register(:test_generator, fake_generator)
41
+ end
42
+
43
+ it 'runs the specified generator with the given arguments' do
44
+ RPlusPlus::Commands::Generate.call(:test_generator, 'foo', 'bar', 'baz')
45
+
46
+ expect(fake_generator).to have_received(:call).with('foo', 'bar', 'baz')
47
+ end
48
+
49
+ it 'converts generator strings into symbols' do
50
+ RPlusPlus::Commands::Generate.call('test_generator', 'foo', 'bar', 'baz')
51
+
52
+ expect(fake_generator).to have_received(:call).with('foo', 'bar', 'baz')
53
+ end
54
+
55
+ it 'raises if the specific generator does not exists' do
56
+ expect {
57
+ RPlusPlus::Commands::Generate.call :nonexistent, :something
58
+ }.to raise_error(RPlusPlus::Commands::Generate::MissingGeneratorError,
59
+ "'nonexistent' is not a r++ generator")
60
+ end
61
+ end
62
+ end
@@ -4,9 +4,14 @@ describe RPlusPlus::Environment do
4
4
  let(:env) { RPlusPlus::Environment.new }
5
5
 
6
6
  before(:all) do
7
+ @pwd = Dir.pwd
7
8
  Dir.chdir('spec/support/samples')
8
9
  end
9
10
 
11
+ after(:all) do
12
+ Dir.chdir(@pwd)
13
+ end
14
+
10
15
  describe '#objects' do
11
16
  it 'contains a list of objects with their dependencies' do
12
17
  expect(env.objects).to include(
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe RPlusPlus::Generators::ClassGenerator do
4
+ it 'registers itself with the generate command' do
5
+ expect(RPlusPlus::Commands::Generate.generators).to include(
6
+ :class => RPlusPlus::Generators::ClassGenerator)
7
+ end
8
+
9
+ describe '#call' do
10
+ # include FakeFS::SpecHelpers
11
+
12
+ before(:all) do
13
+ @pwd = Dir.pwd
14
+ Dir.chdir('spec/support/sandbox')
15
+ end
16
+
17
+ after(:all) do
18
+ Dir.chdir(@pwd)
19
+ end
20
+
21
+ after do
22
+ FileUtils.rm 'my_class.h'
23
+ FileUtils.rm 'my_class.cpp'
24
+ end
25
+
26
+ it 'generates a class' do
27
+ RPlusPlus::Generators::ClassGenerator.call('MyClass')
28
+
29
+ header_file = File.read('my_class.h')
30
+ class_file = File.read('my_class.cpp')
31
+
32
+ expect(header_file).to include('#ifndef MY_CLASS_H', '#define MY_CLASS_H',
33
+ 'class MyClass {', 'MyClass();', 'virtual ~MyClass();')
34
+ expect(class_file).to include('#include "my_class.h"', 'MyClass::MyClass() {',
35
+ 'MyClass::~MyClass() {')
36
+ end
37
+ end
38
+ end
@@ -1,4 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe RPlusPlus do
4
+ describe '#call' do
5
+ let (:fake_command) { spy('fake_command') }
6
+
7
+ before do
8
+ RPlusPlus::Command.register :test_command, fake_command
9
+ end
10
+
11
+ after do
12
+ RPlusPlus::Command.commands.delete :test_command
13
+ end
14
+
15
+ it 'calls the specified command with the given arguments' do
16
+ RPlusPlus.call ['test_command', 'foo', 'bar', 'baz']
17
+
18
+ expect(fake_command).to have_received(:call).with('foo', 'bar', 'baz')
19
+ end
20
+ end
4
21
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'bundler/setup'
2
- Bundler.setup
2
+ require 'fakefs/spec_helpers'
3
3
 
4
4
  require 'rplusplus'
5
5
 
File without changes
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rplusplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-28 00:00:00.000000000 Z
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,10 +66,39 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fakefs
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.6'
55
97
  description: A collection of command-line tools for making C++ development easier.
56
98
  email:
57
99
  - jellymann@gmail.com
58
- executables: []
100
+ executables:
101
+ - r++
59
102
  extensions: []
60
103
  extra_rdoc_files: []
61
104
  files:
@@ -65,12 +108,20 @@ files:
65
108
  - LICENSE.txt
66
109
  - README.md
67
110
  - Rakefile
68
- - lib/environment.rb
111
+ - bin/r++
69
112
  - lib/rplusplus.rb
113
+ - lib/rplusplus/command.rb
114
+ - lib/rplusplus/commands/generate.rb
115
+ - lib/rplusplus/environment.rb
116
+ - lib/rplusplus/generators/class_generator.rb
117
+ - lib/rplusplus/templates/class.erb
118
+ - lib/rplusplus/templates/class_header.erb
70
119
  - lib/rplusplus/version.rb
71
120
  - rplusplus.gemspec
121
+ - spec/command_spec.rb
122
+ - spec/commands/generate_spec.rb
72
123
  - spec/environment_spec.rb
73
- - spec/r++_spec.rb
124
+ - spec/generators/class_generator_spec.rb
74
125
  - spec/rplusplus_spec.rb
75
126
  - spec/spec_helper.rb
76
127
  - spec/support/load_file.rb
@@ -87,6 +138,7 @@ files:
87
138
  - spec/support/samples/other_class.cpp
88
139
  - spec/support/samples/other_class.h
89
140
  - spec/support/samples/other_main.cpp
141
+ - spec/support/sandbox/.keep
90
142
  homepage: https://github.com/jellymann/rplusplus
91
143
  licenses:
92
144
  - MIT
@@ -107,13 +159,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
159
  version: '0'
108
160
  requirements: []
109
161
  rubyforge_project:
110
- rubygems_version: 2.3.0
162
+ rubygems_version: 2.4.5
111
163
  signing_key:
112
164
  specification_version: 4
113
165
  summary: Making C++ slightly less painful.
114
166
  test_files:
167
+ - spec/command_spec.rb
168
+ - spec/commands/generate_spec.rb
115
169
  - spec/environment_spec.rb
116
- - spec/r++_spec.rb
170
+ - spec/generators/class_generator_spec.rb
117
171
  - spec/rplusplus_spec.rb
118
172
  - spec/spec_helper.rb
119
173
  - spec/support/load_file.rb
@@ -130,3 +184,5 @@ test_files:
130
184
  - spec/support/samples/other_class.cpp
131
185
  - spec/support/samples/other_class.h
132
186
  - spec/support/samples/other_main.cpp
187
+ - spec/support/sandbox/.keep
188
+ has_rdoc:
data/spec/r++_spec.rb DELETED
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'r++' do
4
- pending 'Write tests using the r++ command'
5
- end