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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4947208b5f0d21df716919d7c796e6af40f6795e
4
- data.tar.gz: bef05794da4fca103eaedd3d1b6e441b427ad1cc
3
+ metadata.gz: 030a4105373d24a3ba5d97a52cb34d0bf2c79d2f
4
+ data.tar.gz: af38a6d0eeb9354bfe33d1beba9c1d289b75fcd5
5
5
  SHA512:
6
- metadata.gz: c5eb3843050d05e5e0a5b72eccf98c617349e8790b2a72dc7987365a6063d08361ee5b96ebf420d240c1f4e2e49682107975f644832ad8953b912f30951637aa
7
- data.tar.gz: e248fb9f3cefa59e8ceb324820b688ba50fbcec5b7ccffd0796daee94326d9049c98f0e6d841aa5feaf7214bf45c434c1dcee9c0a0326a5cda7c87fa0ef74ddc
6
+ metadata.gz: d042a73c45f127800653f8dab0fc5a4cb40c5ab1fdddd0a1c842e2579c245205523389d751099b301a128b89eea3e59a896998ee9764e341b682e0f6c4ece6c3
7
+ data.tar.gz: 056d522dc8c85d7ebfe1450ad119431bda4e33ccf54c7e0a015ff9c749f0c2de4328836b700f6e32757941a9f25e04e946339825ae632c4d800a4f6ffebdac2d
@@ -1,4 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "sequel"
4
- gem "rdm", path: "../"
4
+ gem "rspec"
5
+ gem "rdm", path: "../"
@@ -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
- FileUtils.mkdir_p(File.join(package_relative_path, package_subdir_name, package_name))
36
- FileUtils.touch(File.join(package_relative_path, package_subdir_name, "#{package_name}.rb"))
37
- FileUtils.touch(File.join(package_relative_path, '.gitignore'))
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("rspec/spec_helper.rb")
94
+ copy_template("spec/spec_helper.rb")
95
+ copy_template("bin/console_irb", "bin/console")
61
96
  end
62
97
  end
63
98
 
64
- def copy_template(filepath)
65
- from = filepath
66
- to = File.join(current_dir, package_relative_path, filepath)
67
- FileUtils.mkdir_p(File.dirname(to))
68
- FileUtils.cp(from, to)
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 check_preconditions!
72
- if Dir.exist?(File.join(current_dir, package_relative_path))
73
- raise Rdm::Errors::PackageDirExists, "package dir exists"
74
- end
75
-
76
- if rdm_source.package_paths.include?(package_relative_path)
77
- raise Rdm::Errors::PackageExists, "package exists"
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 package_rb_template
82
- v = <<EOF
83
- package do
84
- name '#{package_name}'
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
@@ -0,0 +1,3 @@
1
+ module <%= package_name_camelized %>
2
+
3
+ end
@@ -0,0 +1,8 @@
1
+ package do
2
+ name '<%= package_name %>'
3
+ version '1.0.0'
4
+ end
5
+
6
+ dependency do
7
+ # import 'utils'
8
+ end
@@ -1,7 +1,7 @@
1
1
  ENV['RUBY_ENV'] = 'test'
2
2
 
3
3
  require 'rdm'
4
- Rdm.init(File.expand_path('../../', FILE), :test)
4
+ Rdm.init(File.expand_path('../../', __FILE__), :test)
5
5
 
6
6
  require 'rspec'
7
7
  require 'byebug'
@@ -1,3 +1,3 @@
1
1
  module Rdm
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
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.10
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-06 00:00:00.000000000 Z
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/rspec/spec_helper.rb
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