rdm 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/Gemfile +2 -1
- data/lib/rdm/package_generator.rb +58 -31
- data/lib/rdm/templates/bin/console_irb +14 -0
- data/lib/rdm/templates/main_module_file.rb.erb +3 -0
- data/lib/rdm/templates/package.rb.erb +8 -0
- data/lib/rdm/templates/{rspec → spec}/spec_helper.rb +1 -1
- data/lib/rdm/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030a4105373d24a3ba5d97a52cb34d0bf2c79d2f
|
4
|
+
data.tar.gz: af38a6d0eeb9354bfe33d1beba9c1d289b75fcd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d042a73c45f127800653f8dab0fc5a4cb40c5ab1fdddd0a1c842e2579c245205523389d751099b301a128b89eea3e59a896998ee9764e341b682e0f6c4ece6c3
|
7
|
+
data.tar.gz: 056d522dc8c85d7ebfe1450ad119431bda4e33ccf54c7e0a015ff9c749f0c2de4328836b700f6e32757941a9f25e04e946339825ae632c4d800a4f6ffebdac2d
|
data/example/Gemfile
CHANGED
@@ -1,4 +1,20 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'pathname'
|
3
|
+
require "active_support/inflector"
|
4
|
+
|
5
|
+
|
6
|
+
# http://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash
|
7
|
+
require 'erb'
|
8
|
+
require 'ostruct'
|
9
|
+
class ErbalT < OpenStruct
|
10
|
+
def self.render(template, locals)
|
11
|
+
self.new(locals).render(template)
|
12
|
+
end
|
13
|
+
def render(template)
|
14
|
+
ERB.new(template).result(binding)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
2
18
|
|
3
19
|
class Rdm::PackageGenerator
|
4
20
|
class << self
|
@@ -32,17 +48,35 @@ class Rdm::PackageGenerator
|
|
32
48
|
package_subdir_name = Rdm.settings.send(:package_subdir_name)
|
33
49
|
|
34
50
|
Dir.chdir(current_dir) do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
51
|
+
ensure_file([package_relative_path, '.gitignore'])
|
52
|
+
ensure_file(
|
53
|
+
[package_relative_path, package_subdir_name, "#{package_name}.rb"],
|
54
|
+
template_content("main_module_file.rb.erb", {package_name_camelized: package_name.camelize})
|
55
|
+
)
|
56
|
+
ensure_file(
|
57
|
+
[package_relative_path, 'Package.rb'],
|
58
|
+
template_content("package.rb.erb", {package_name: package_name})
|
59
|
+
)
|
39
60
|
if !skip_rspec
|
40
61
|
init_rspec
|
41
62
|
end
|
42
|
-
|
43
|
-
File.write(File.join(package_relative_path, 'Package.rb'), package_rb_template)
|
44
63
|
end
|
64
|
+
|
45
65
|
move_templates
|
66
|
+
append_package_to_rdm_packages
|
67
|
+
end
|
68
|
+
|
69
|
+
def check_preconditions!
|
70
|
+
if Dir.exist?(File.join(current_dir, package_relative_path))
|
71
|
+
raise Rdm::Errors::PackageDirExists, "package dir exists"
|
72
|
+
end
|
73
|
+
|
74
|
+
if rdm_source.package_paths.include?(package_relative_path)
|
75
|
+
raise Rdm::Errors::PackageExists, "package exists"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def append_package_to_rdm_packages
|
46
80
|
new_source_content = source_content + "\npackage '#{package_relative_path}'"
|
47
81
|
File.write(source_path, new_source_content)
|
48
82
|
end
|
@@ -57,37 +91,30 @@ class Rdm::PackageGenerator
|
|
57
91
|
Dir.chdir(File.join(File.dirname(__FILE__), "templates")) do
|
58
92
|
copy_template(".rspec")
|
59
93
|
copy_template(".gitignore")
|
60
|
-
copy_template("
|
94
|
+
copy_template("spec/spec_helper.rb")
|
95
|
+
copy_template("bin/console_irb", "bin/console")
|
61
96
|
end
|
62
97
|
end
|
63
98
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
FileUtils.mkdir_p(File.dirname(
|
68
|
-
|
99
|
+
private
|
100
|
+
def ensure_file(path_array, content="")
|
101
|
+
filename = File.join(*path_array)
|
102
|
+
FileUtils.mkdir_p(File.dirname(filename))
|
103
|
+
File.write(filename, content)
|
69
104
|
end
|
70
105
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
106
|
+
def copy_template(filepath, target_name=nil)
|
107
|
+
from = filepath
|
108
|
+
target_name ||= filepath
|
109
|
+
to = File.join(current_dir, package_relative_path, target_name)
|
110
|
+
FileUtils.mkdir_p(File.dirname(to))
|
111
|
+
# copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
|
112
|
+
FileUtils.copy_entry(from, to, true, false, true)
|
79
113
|
end
|
80
114
|
|
81
|
-
def
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
version '1.0.0'
|
86
|
-
end
|
87
|
-
|
88
|
-
dependency do
|
89
|
-
# import 'utils'
|
90
|
-
end
|
91
|
-
EOF
|
115
|
+
def template_content(file, locals={})
|
116
|
+
template_path = Pathname.new(File.join(File.dirname(__FILE__), "templates")).join(file)
|
117
|
+
template_content = File.read(template_path)
|
118
|
+
ErbalT.render(template_content, locals)
|
92
119
|
end
|
93
120
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "bundler/setup"
|
3
|
+
require "rdm"
|
4
|
+
Rdm.init(File.expand_path('../../', __FILE__))
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/lib/rdm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droid Labs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,7 +115,10 @@ files:
|
|
115
115
|
- lib/rdm/source_parser.rb
|
116
116
|
- lib/rdm/templates/.gitignore
|
117
117
|
- lib/rdm/templates/.rspec
|
118
|
-
- lib/rdm/templates/
|
118
|
+
- lib/rdm/templates/bin/console_irb
|
119
|
+
- lib/rdm/templates/main_module_file.rb.erb
|
120
|
+
- lib/rdm/templates/package.rb.erb
|
121
|
+
- lib/rdm/templates/spec/spec_helper.rb
|
119
122
|
- lib/rdm/version.rb
|
120
123
|
- rdm.gemspec
|
121
124
|
- spec/fixtures/SampleSource.rb
|