rdm 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile.lock +80 -0
  4. data/bin/rdm +78 -10
  5. data/example/.rdm/helpers/render_helper.rb +12 -0
  6. data/example/.rdm/templates/package/.gitignore +1 -0
  7. data/example/.rdm/templates/package/.rspec +2 -0
  8. data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
  9. data/example/.rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
  10. data/{lib/rdm/templates/package/package.rb.erb → example/.rdm/templates/package/Package.rb} +0 -0
  11. data/{lib/rdm/templates/package/bin/console_irb → example/.rdm/templates/package/bin/console} +0 -0
  12. data/example/.rdm/templates/package/spec/spec_helper.rb +10 -0
  13. data/example/.rdm/templates/repository/dao/<%=name%>_dao.rb +4 -0
  14. data/example/.rdm/templates/repository/mapper/<%=name%>_mapper.rb +2 -0
  15. data/example/.rdm/templates/repository/repository/<%=name%>_repository.rb +2 -0
  16. data/example/.rdm/templates/repository/views/users.html.erb +2 -0
  17. data/example/Gemfile.lock +50 -0
  18. data/example/Rdm.packages +1 -0
  19. data/example/tests/diff_run +0 -0
  20. data/example/tests/run +0 -0
  21. data/lib/rdm.rb +40 -8
  22. data/lib/rdm/cli/compile_package.rb +56 -0
  23. data/lib/rdm/cli/dependencies_controller.rb +30 -0
  24. data/lib/rdm/cli/diff_package.rb +21 -0
  25. data/lib/rdm/cli/gen_package.rb +24 -32
  26. data/lib/rdm/cli/init.rb +20 -27
  27. data/lib/rdm/cli/template_generator.rb +38 -0
  28. data/lib/rdm/errors.rb +37 -0
  29. data/lib/rdm/gen/init.rb +29 -44
  30. data/lib/rdm/gen/package.rb +24 -78
  31. data/lib/rdm/git/diff_command.rb +13 -0
  32. data/lib/rdm/git/diff_manager.rb +30 -0
  33. data/lib/rdm/git/repository_locator.rb +23 -0
  34. data/lib/rdm/handlers/dependencies_handler.rb +110 -0
  35. data/lib/rdm/handlers/diff_package_handler.rb +48 -0
  36. data/lib/rdm/handlers/template_handler.rb +118 -0
  37. data/lib/rdm/helpers/path_helper.rb +15 -0
  38. data/lib/rdm/package.rb +6 -0
  39. data/lib/rdm/package_importer.rb +1 -1
  40. data/lib/rdm/packages/compiler_service.rb +78 -0
  41. data/lib/rdm/packages/locator.rb +28 -0
  42. data/lib/rdm/settings.rb +14 -1
  43. data/lib/rdm/spec_runner.rb +5 -0
  44. data/lib/rdm/spec_runner/command_generator.rb +28 -0
  45. data/lib/rdm/spec_runner/command_params.rb +3 -0
  46. data/lib/rdm/spec_runner/package_fetcher.rb +13 -0
  47. data/lib/rdm/spec_runner/runner.rb +122 -0
  48. data/lib/rdm/spec_runner/view.rb +20 -0
  49. data/lib/rdm/templates/init/.rdm/helpers/render_helper.rb +12 -0
  50. data/lib/rdm/templates/init/{Gemfile.erb → Gemfile} +0 -0
  51. data/lib/rdm/templates/init/{Rdm.packages.erb → Rdm.packages} +0 -0
  52. data/lib/rdm/templates/init/{Readme.md.erb → Readme.md} +0 -0
  53. data/lib/rdm/templates/init/tests/diff_run +29 -0
  54. data/lib/rdm/templates/init/tests/run +7 -210
  55. data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>.rb +3 -0
  56. data/lib/rdm/templates/package/<%=package_subdir_name%>/<%=package_name%>/.gitkeep +0 -0
  57. data/lib/rdm/templates/package/Package.rb +8 -0
  58. data/lib/rdm/templates/package/bin/console +16 -0
  59. data/lib/rdm/templates/template_detector.rb +32 -0
  60. data/lib/rdm/templates/template_renderer.rb +49 -0
  61. data/lib/rdm/utils/file_utils.rb +20 -0
  62. data/lib/rdm/utils/render_util.rb +24 -0
  63. data/lib/rdm/utils/string_utils.rb +16 -0
  64. data/lib/rdm/version.rb +1 -1
  65. data/rdm.gemspec +1 -1
  66. data/spec/helpers/example_project_helper.rb +217 -0
  67. data/spec/helpers/git_commands_helper.rb +13 -0
  68. data/spec/rdm/cli/compile_package_spec.rb +114 -0
  69. data/spec/rdm/cli/dependencies_controller_spec.rb +50 -0
  70. data/spec/rdm/cli/diff_package_spec.rb +5 -0
  71. data/spec/rdm/cli/gen_package_spec.rb +60 -86
  72. data/spec/rdm/cli/init_spec.rb +53 -70
  73. data/spec/rdm/gen/init_spec.rb +21 -38
  74. data/spec/rdm/gen/package_spec.rb +70 -51
  75. data/spec/rdm/git/diff_manager_spec.rb +81 -0
  76. data/spec/rdm/git/repository_locator_spec.rb +31 -0
  77. data/spec/rdm/handlers/dependencies_handler_spec.rb +84 -0
  78. data/spec/rdm/handlers/diff_package_handler_spec.rb +78 -0
  79. data/spec/rdm/handlers/template_handler_spec.rb +94 -0
  80. data/spec/rdm/helpers/path_helper_spec.rb +52 -0
  81. data/spec/rdm/package/compiler_service_spec.rb +124 -0
  82. data/spec/rdm/package/locator_spec.rb +31 -0
  83. data/spec/rdm/rdm_spec.rb +2 -2
  84. data/spec/rdm/spec_runner/runner_spec.rb +12 -0
  85. data/spec/rdm/templates/template_detector_spec.rb +39 -0
  86. data/spec/rdm/templates/template_renderer_spec.rb +42 -0
  87. data/spec/spec_helper.rb +31 -25
  88. metadata +84 -17
  89. data/lib/rdm/gen/concerns/template_handling.rb +0 -81
  90. data/lib/rdm/support/colorize.rb +0 -106
  91. data/lib/rdm/support/render.rb +0 -17
  92. data/lib/rdm/support/template.rb +0 -30
  93. data/lib/rdm/templates/package/main_module_file.rb.erb +0 -3
  94. data/spec/rdm/support/colorize_spec.rb +0 -24
  95. data/spec/rdm/support/template_spec.rb +0 -20
@@ -1,81 +0,0 @@
1
- module Rdm
2
- module Gen
3
- module Concerns
4
- module TemplateHandling
5
- # depends on target_path, templates_path methods in the including class!
6
-
7
- module ClassMethods
8
- def disable_logger!
9
- @logger_disabled = true
10
- end
11
-
12
- def enable_logger!
13
- @logger_disabled = false
14
- end
15
-
16
- def should_log?
17
- !@logger_disabled
18
- end
19
- end
20
-
21
- def self.included(base)
22
- base.instance_eval do
23
- include Rdm::Support::Colorize
24
- extend ClassMethods
25
- end
26
- end
27
-
28
- private
29
-
30
- def log(msg)
31
- puts(msg) if self.class.should_log?
32
- end
33
-
34
- def warning(msg)
35
- log brown(msg)
36
- end
37
-
38
- def info(msg)
39
- log green(msg)
40
- end
41
-
42
- def info_created(file)
43
- info("Generated: #{file}")
44
- end
45
-
46
- def warning_exists(file)
47
- warning("File #{file} already exists, skipping...")
48
- end
49
-
50
- def ensure_file(path_array, content = '')
51
- filename = File.join(*path_array)
52
- FileUtils.mkdir_p(File.dirname(filename))
53
- return warning_exists(filename) if File.exist?(filename)
54
- File.write(filename, content)
55
- info_created(filename)
56
- end
57
-
58
- def copy_template(filepath, target_name = nil)
59
- from = filepath
60
- target_name ||= filepath
61
- to = File.join(target_path, target_name)
62
- return warning_exists(to) if File.exist?(to)
63
- FileUtils.mkdir_p(File.dirname(to))
64
- # copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)
65
- FileUtils.copy_entry(from, to, true, false, true)
66
- info_created(relative_path(to))
67
- end
68
-
69
- def template_content(file, locals = {})
70
- template_path = templates_path.join(file)
71
- template_content = File.read(template_path)
72
- Rdm::Support::Render.render(template_content, locals)
73
- end
74
-
75
- def relative_path(file)
76
- file.gsub(current_dir + '/', '')
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,106 +0,0 @@
1
- module Rdm
2
- module Support
3
- # http://stackoverflow.com/questions/1489183/colorized-ruby-output
4
- module Colorize
5
- module ClassMethods
6
- def black(msg)
7
- color_wrap(msg, 30)
8
- end
9
-
10
- def red(msg)
11
- color_wrap(msg, 31)
12
- end
13
-
14
- def green(msg)
15
- color_wrap(msg, 32)
16
- end
17
-
18
- def brown(msg)
19
- color_wrap(msg, 33)
20
- end
21
-
22
- def blue(msg)
23
- color_wrap(msg, 34)
24
- end
25
-
26
- def magenta(msg)
27
- color_wrap(msg, 35)
28
- end
29
-
30
- def cyan(msg)
31
- color_wrap(msg, 36)
32
- end
33
-
34
- def gray(msg)
35
- color_wrap(msg, 37)
36
- end
37
-
38
- def bg_black(msg)
39
- color_wrap(msg, 40)
40
- end
41
-
42
- def bg_red(msg)
43
- color_wrap(msg, 41)
44
- end
45
-
46
- def bg_green(msg)
47
- color_wrap(msg, 42)
48
- end
49
-
50
- def bg_brown(msg)
51
- color_wrap(msg, 43)
52
- end
53
-
54
- def bg_blue(msg)
55
- color_wrap(msg, 44)
56
- end
57
-
58
- def bg_magenta(msg)
59
- color_wrap(msg, 45)
60
- end
61
-
62
- def bg_cyan(msg)
63
- color_wrap(msg, 46)
64
- end
65
-
66
- def bg_gray(msg)
67
- color_wrap(msg, 47)
68
- end
69
-
70
- def bold(msg)
71
- color_wrap(msg, 1, 22)
72
- end
73
-
74
- def italic(msg)
75
- color_wrap(msg, 3, 23)
76
- end
77
-
78
- def underline(msg)
79
- color_wrap(msg, 4, 24)
80
- end
81
-
82
- def blink(msg)
83
- color_wrap(msg, 5, 25)
84
- end
85
-
86
- def reverse_color(msg)
87
- color_wrap(msg, 7, 27)
88
- end
89
-
90
- def color_wrap(msg, from, to = 0)
91
- "\e[#{from}m#{msg}\e[#{to}m"
92
- end
93
-
94
- def no_colors(msg)
95
- msg.gsub(/\e\[\d+m/, '')
96
- end
97
- end
98
-
99
- extend ClassMethods
100
-
101
- def self.included(base)
102
- base.include(ClassMethods)
103
- end
104
- end
105
- end
106
- end
@@ -1,17 +0,0 @@
1
- # http://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash
2
- require 'erb'
3
- require 'ostruct'
4
-
5
- module Rdm
6
- module Support
7
- class Render < OpenStruct
8
- def self.render(template, locals)
9
- new(locals).render(template)
10
- end
11
-
12
- def render(template)
13
- ERB.new(template).result(binding)
14
- end
15
- end
16
- end
17
- end
@@ -1,30 +0,0 @@
1
- module Rdm
2
- module Support
3
- class Template
4
- attr_accessor :tmpl_path
5
- def initialize(tmpl_path = nil)
6
- @tmpl_path = construct_path(tmpl_path)
7
- end
8
-
9
- def content(file, locals = {})
10
- path = tmpl_path.join(file)
11
- content = File.read(path)
12
- Rdm::Support::Render.render(content, locals)
13
- end
14
-
15
- def construct_path(some_path = nil)
16
- Pathname.new(
17
- File.expand_path(
18
- (some_path || default_templates_path)
19
- )
20
- )
21
- end
22
-
23
- def default_templates_path
24
- File.expand_path(
25
- File.join(File.dirname(__FILE__), '..', 'templates')
26
- )
27
- end
28
- end
29
- end
30
- end
@@ -1,3 +0,0 @@
1
- module <%= package_name_camelized %>
2
-
3
- end
@@ -1,24 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Rdm::Support::Colorize do
4
- let(:subject){Rdm::Support::Colorize}
5
- context "colorize" do
6
- it "red works" do
7
- expect(subject.red('hello')).to eq("\e[31mhello\e[0m")
8
- end
9
-
10
- it "green works" do
11
- expect(subject.green('hello')).to eq("\e[32mhello\e[0m")
12
- end
13
-
14
- it "brown works" do
15
- expect(subject.brown('hello')).to eq("\e[33mhello\e[0m")
16
- end
17
- end
18
-
19
- context "no_colors" do
20
- it "removes colors from string" do
21
- expect(subject.no_colors(subject.red('hello'))).to eq("hello")
22
- end
23
- end
24
- end
@@ -1,20 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Rdm::Support::Template" do
4
- let(:template) {Rdm::Support::Template.new}
5
- describe ":default_templates_path" do
6
- it "is correct" do
7
- expect(template.default_templates_path.to_s).to match(/lib\/rdm\/templates$/)
8
- end
9
- end
10
-
11
- describe ":content" do
12
- it "renders template content without locals" do
13
- expect(template.content("package/.rspec")).to eq("--color\n--require spec_helper\n")
14
- end
15
-
16
- it "renders template content without locals" do
17
- expect(template.content("package/main_module_file.rb.erb", {package_name_camelized: "Some"})).to eq("module Some\n\nend\n")
18
- end
19
- end
20
- end