rplusplus 0.0.3 → 0.0.4

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: 446702f23e9654cb84e635114fa2b9d27fc3e2a2
4
- data.tar.gz: bccd78bcfb59ba820bdebab6f61ca2652cf7b46a
3
+ metadata.gz: 0989e8c5ffe3aae629bfbf79784467f6c1677b32
4
+ data.tar.gz: 635f42a74effc1ff5e20ce09448735cd1e3a62eb
5
5
  SHA512:
6
- metadata.gz: 458624828a67224493f6023640750ecb14a78addd9cf6f3e1b6169f86bd1ec9afff3e0119268364c68386a4d870739e11174bd61e1bbe435a059b63e3fdf34ef
7
- data.tar.gz: 9cbe6ac573fe8e1550cfe06bea6e5b3536bedf6fd8fa1029c70275d1d765d9d1dcb18b362a3b3e5807846d28da6486848943e308ebf54e2b305227829be477f6
6
+ metadata.gz: 8da90c09d0bb646389ec6012013f153adca607234b44eff0d0e4fc40ee8a706c26cb5fee12d631e24f31da4ee0709b1435595c09c88acecd2f2a9326febcd676
7
+ data.tar.gz: 09919db3de64c94cb4e61b0b0501d7bd84fe4e03178c9254b0fef12c59dc6f2ca6ab7f445959858ff36e5ce96775ed9c6f602741cb108a8060bd4a92c56bc875
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # R++
1
+ # R++ [![Gem Version](https://badge.fury.io/rb/rplusplus.svg)](http://badge.fury.io/rb/rplusplus) [![Code Climate](https://codeclimate.com/github/jellymann/rplusplus/badges/gpa.svg)](https://codeclimate.com/github/jellymann/rplusplus) [![Test Coverage](https://codeclimate.com/github/jellymann/rplusplus/badges/coverage.svg)](https://codeclimate.com/github/jellymann/rplusplus/coverage) [![Circle CI](https://circleci.com/gh/jellymann/rplusplus.svg?style=svg)](https://circleci.com/gh/jellymann/rplusplus)
2
2
 
3
3
  Making C++ slightly less painful.
4
4
 
@@ -31,88 +31,69 @@ module RPlusPlus
31
31
  end
32
32
 
33
33
  def objects_hash
34
- @cpp_info ||= info_hash('cpp')
35
- @header_info ||= info_hash('h')
34
+ @cpp_metadata ||= metadata_for_filetype('cpp')
35
+ @header_metadata ||= metadata_for_filetype('h')
36
36
 
37
- hash = {}
38
- @cpp_info.each do |cpp,info|
39
- hash[objectify cpp] = [cpp] | deps_for(info)
37
+ @cpp_metadata.each_with_object({}) do |(cpp_file, metadata), hash|
38
+ hash[objectify cpp_file] = [cpp_file] | dependencies_from_metadata(metadata)
40
39
  end
41
- hash
42
40
  end
43
41
 
44
- def deps_for info
45
- info[:deps] | info[:deps].map do |d|
46
- deps_for(@header_info[d])
47
- end.flatten
42
+ def dependencies_from_metadata metadata
43
+ dependency_dependencies = metadata[:dependencies].flat_map do |dependency|
44
+ dependencies_from_metadata(@header_metadata[dependency])
45
+ end
46
+ metadata[:dependencies] | dependency_dependencies
48
47
  end
49
48
 
50
49
  def builds_hash
51
50
  objects
52
- hash = {}
53
- @cpp_info.each do |cpp,info|
54
- next unless info[:main]
55
-
56
- hash[basename cpp] = obj_deps objectify(cpp)
51
+ @cpp_metadata.each_with_object({}) do |(cpp_file, metadata), hash|
52
+ hash[File.basename cpp_file, '.cpp'] = object_dependencies objectify(cpp_file) if metadata[:is_main]
57
53
  end
58
- hash
59
54
  end
60
55
 
61
- def obj_deps obj, visited=[]
62
- deps = []
63
- objects[obj].each do |d|
64
- o = objectify(d)
65
- next if visited.include?(o)
66
- if objects.include?(o)
67
- deps << o
68
- deps |= obj_deps(o, [o,*visited])
56
+ def object_dependencies object_file, visited=[]
57
+ objects[object_file].each_with_object([]) do |source_dependency, dependencies|
58
+ object_dependency = objectify(source_dependency)
59
+ if !visited.include?(object_dependency) && objects.include?(object_dependency)
60
+ dependencies << object_dependency
61
+ dependencies |= object_dependencies(object_dependency, [object_dependency, *visited])
69
62
  end
70
63
  end
71
- deps
72
64
  end
73
65
 
74
- def info_hash type
75
- hash = {}
76
- Dir[Pathname(@path).join("**/*.#{type}")].each do |f|
77
- hash[f] = info_for f
66
+ def metadata_for_filetype type
67
+ metadata = Dir[Pathname(@path).join("**/*.#{type}")].each_with_object({}) do |filename, hash|
68
+ hash[filename] = metadata_for filename
78
69
  end
79
- Dir[Pathname(@path).join("**/*.#{type}.erb")].each do |f|
80
- hash[unerb(f)] = info_for f
70
+ Dir[Pathname(@path).join("**/*.#{type}.erb")].each_with_object(metadata) do |filename, hash|
71
+ hash[File.basename filename, '.erb'] = metadata_for filename
81
72
  end
82
- hash
83
73
  end
84
74
 
85
- def info_for fn
86
- main = false
87
- deps = []
88
- File.foreach(fn) do |l|
89
- main ||= !!main_match(l)
90
- dep = include_match l
91
- deps << dep if dep
75
+ def metadata_for filename
76
+ is_main = false
77
+ dependencies = []
78
+ File.foreach(filename) do |line|
79
+ is_main ||= is_main_declaration(line)
80
+ dependency = get_included_file line
81
+ dependencies << dependency if dependency
92
82
  end
93
- {main: main, deps: deps}
94
- end
95
-
96
- def unerb fn
97
- fn.gsub(/\.erb$/,'')
83
+ {is_main: is_main, dependencies: dependencies}
98
84
  end
99
85
 
100
- def basename fn
101
- fn.gsub(/\..*$/,'')
86
+ def is_main_declaration line
87
+ !!(line =~ /^\W*int\W*main\(.*?\)/)
102
88
  end
103
89
 
104
- def main_match l
105
- l =~ /^\W*int\W*main\(.*?\)/
106
- end
107
-
108
- def include_match l
109
- m = /#include "(?<file>.*)"/.match(l)
90
+ def get_included_file line
91
+ m = /#include "(?<file>.*)"/.match(line)
110
92
  m[:file] if m
111
93
  end
112
94
 
113
95
  def objectify filename
114
96
  filename.gsub(/\.(cpp|cpp\.erb|h|h\.erb)$/,'.o')
115
97
  end
116
-
117
98
  end
118
99
  end
@@ -1,3 +1,3 @@
1
1
  module Rplusplus
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency "rake", "~> 10.3"
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
28
  spec.add_development_dependency "pry", "~> 0.10"
29
- spec.add_development_dependency "fakefs", "~> 0.6"
29
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
30
30
  end
@@ -1,5 +1,7 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  require 'bundler/setup'
2
- require 'fakefs/spec_helpers'
3
5
 
4
6
  require 'rplusplus'
5
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rplusplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Smith
@@ -81,19 +81,19 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.10'
83
83
  - !ruby/object:Gem::Dependency
84
- name: fakefs
84
+ name: codeclimate-test-reporter
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0.6'
89
+ version: '0.4'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0.6'
96
+ version: '0.4'
97
97
  description: A collection of command-line tools for making C++ development easier.
98
98
  email:
99
99
  - jellymann@gmail.com