rdm 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -1
  3. data/.rubocop.yml +17 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +5 -1
  6. data/LICENSE.txt +1 -1
  7. data/README.md +84 -28
  8. data/bin/rdm +72 -0
  9. data/bin/rubocop +6 -0
  10. data/docs/_config.yml +1 -0
  11. data/docs/index.md +98 -0
  12. data/docs/interface_brainstorming.md +31 -0
  13. data/example/Rdm.packages +1 -1
  14. data/example/Readme.md +1 -3
  15. data/lib/rdm.rb +29 -20
  16. data/lib/rdm/cli/gen_package.rb +48 -0
  17. data/lib/rdm/cli/init.rb +43 -0
  18. data/lib/rdm/config.rb +9 -1
  19. data/lib/rdm/config_manager.rb +5 -5
  20. data/lib/rdm/config_scope.rb +3 -3
  21. data/lib/rdm/errors.rb +2 -0
  22. data/lib/rdm/gen/concerns/template_handling.rb +81 -0
  23. data/lib/rdm/gen/init.rb +69 -0
  24. data/lib/rdm/gen/package.rb +99 -0
  25. data/lib/rdm/package.rb +17 -16
  26. data/lib/rdm/package_importer.rb +89 -79
  27. data/lib/rdm/package_parser.rb +25 -5
  28. data/lib/rdm/settings.rb +21 -20
  29. data/lib/rdm/source.rb +1 -1
  30. data/lib/rdm/source_locator.rb +31 -0
  31. data/lib/rdm/source_parser.rb +83 -68
  32. data/lib/rdm/support/colorize.rb +106 -0
  33. data/lib/rdm/support/render.rb +17 -0
  34. data/lib/rdm/support/template.rb +30 -0
  35. data/lib/rdm/templates/init/Gemfile.erb +25 -0
  36. data/lib/rdm/templates/init/Rdm.packages.erb +18 -0
  37. data/lib/rdm/templates/init/Readme.md.erb +24 -0
  38. data/lib/rdm/templates/{tests → init/tests}/run +27 -31
  39. data/lib/rdm/templates/package/.gitignore +1 -0
  40. data/lib/rdm/templates/{.rspec → package/.rspec} +0 -0
  41. data/lib/rdm/templates/{bin → package/bin}/console_irb +4 -5
  42. data/lib/rdm/templates/{main_module_file.rb.erb → package/main_module_file.rb.erb} +0 -0
  43. data/lib/rdm/templates/{package.rb.erb → package/package.rb.erb} +0 -0
  44. data/lib/rdm/templates/{spec → package/spec}/spec_helper.rb +0 -0
  45. data/lib/rdm/version.rb +1 -1
  46. data/rdm.gemspec +3 -0
  47. data/spec/fixtures/SampleSource.rb +3 -1
  48. data/spec/fixtures/sample_prj/Rdm.packages +12 -0
  49. data/spec/fixtures/sample_prj/infrastructure/web/Package.rb +16 -0
  50. data/spec/rdm/cli/gen_package_spec.rb +130 -0
  51. data/spec/rdm/cli/init_spec.rb +97 -0
  52. data/spec/rdm/config_manager_spec.rb +37 -1
  53. data/spec/rdm/gen/init_spec.rb +63 -0
  54. data/spec/rdm/gen/package_spec.rb +87 -0
  55. data/spec/rdm/package_importer_spec.rb +5 -1
  56. data/spec/rdm/package_parser_spec.rb +10 -24
  57. data/spec/rdm/rdm_spec.rb +42 -0
  58. data/spec/rdm/source_locator_spec.rb +45 -0
  59. data/spec/rdm/source_parser_spec.rb +45 -3
  60. data/spec/rdm/support/colorize_spec.rb +24 -0
  61. data/spec/rdm/support/template_spec.rb +20 -0
  62. data/spec/spec_helper.rb +45 -0
  63. metadata +92 -16
  64. data/bin/rdm-generate +0 -55
  65. data/bin/rdm-install +0 -13
  66. data/lib/rdm/auto_updater.rb +0 -41
  67. data/lib/rdm/package_generator.rb +0 -121
  68. data/lib/rdm/source_installer.rb +0 -35
  69. data/lib/rdm/templates/.gitignore +0 -1
@@ -0,0 +1,106 @@
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
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,25 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rdm', '0.1.12', require: false
4
+
5
+ # gem 'activesupport', '5.0.0.1', require: false
6
+ # gem 'smart_ioc', '0.1.18', require: false
7
+ # gem 'configuration', '1.3.4', require: false
8
+ # gem 'contracts-lite', '0.15.0', require: false
9
+ # gem 'sequel', '4.41.0', require: false
10
+ # gem 'pg', '0.19.0', require: false
11
+ # gem 'i18n', '0.7.0', require: false
12
+ # gem 'hashcast', '0.4.0 ', require: false
13
+ # gem 'pure_validator', '0.3.0 ', require: false
14
+ # gem 'oj', '2.18.0', require: false
15
+
16
+ ### Web / Rails
17
+ # gem 'rails', '5.0.0.1', require: false
18
+ # gem 'rack-app', '5.6.0', require: false
19
+
20
+ group :test do
21
+ gem 'rspec', '3.5.0', require: false
22
+ # gem 'byebug', '9.0.6', require: false
23
+ # gem 'zeus', '0.15.10', require: false
24
+ # gem 'rake', '12.0.0', require: false
25
+ end
@@ -0,0 +1,18 @@
1
+ setup do
2
+ role do
3
+ ENV['RUBY_ENV'] || raise('please set RUBY_ENV environment variable')
4
+ end
5
+
6
+ configs_dir 'configs'
7
+ config_path ':configs_dir/:config_name/default.yml'
8
+ role_config_path ':configs_dir/:config_name/:role.yml'
9
+ package_subdir_name 'package'
10
+ silence_missing_package true
11
+ end
12
+
13
+ config :database
14
+ config :logging
15
+
16
+
17
+ # package 'core/application/commands'
18
+ # package 'core/utils'
@@ -0,0 +1,24 @@
1
+ # My Awesome App
2
+
3
+
4
+
5
+ This application is using [RDM](https://github.com/droidlabs/rdm) to structure different parts of your application.
6
+ Rdm adds the missing layer of separation that is very lightweight and additional to Bundler.
7
+
8
+ Applications managed with Rdm can be packaged as single or as multiple interdependent Ruby applications with ease and as little friction as possible. When you ever tried to split up your main application into different Ruby gems, you will greatly appreciate Rdm:
9
+ - no self-hosted Rubygems repositories needed
10
+ - no conflicting Gems - RDM packages share a single Gemfile with lazily-loaded gems
11
+ - arbitrary folder structures without nesting lots of Ruby module definitions
12
+ - clear dependencies between your application packages, with different environments
13
+
14
+ Rdm-Apps lend themselves to be used in conjunction with DDD, a technology-agnostic methodology that works much better than CRUD / MVC for more complex requirements.
15
+
16
+
17
+ ### Recommended Gems to use in combination with Rdm are:
18
+
19
+ - [smart_ioc](https://github.com/droidlabs/smart_ioc) - Really convenient dependency injection library
20
+ - [contracts-lite](https://github.com/ddd-ruby/contracts-lite) - Define clear contracts for your Ruby methods
21
+ - [activesupport]() - this is mainly used to enable lazy-loading for constants
22
+ - [sequel](https://github.com/jeremyevans/sequel) - a very flexible Database toolkit
23
+ - [hashcast](https://github.com/ddd-ruby/hashcast) - Hash attributes caster in declarative way
24
+ - [pure_validator](https://github.com/ddd-ruby/pure_validator) - flexible Ruby domain object validation library
@@ -19,8 +19,8 @@ module SpecRunner
19
19
  class InputParams
20
20
  attr_accessor :package_name, :spec_matcher, :run_all
21
21
  def initialize(argv)
22
- @package_name = argv[0].to_s if !argv[0].nil?
23
- @spec_matcher = argv[1].to_s if !argv[1].nil?
22
+ @package_name = argv[0].to_s unless argv[0].nil?
23
+ @spec_matcher = argv[1].to_s unless argv[1].nil?
24
24
  @run_all = !@package_name
25
25
  end
26
26
  end
@@ -75,9 +75,9 @@ module SpecRunner
75
75
  class View
76
76
  def packages_menu(prepared_command_params)
77
77
  prepared_command_params
78
- .sort_by{|x| x.package_path }
79
- .map{|x| " - #{x.package_name} (#{x.spec_count} spec files)"}
80
- .join("\n")
78
+ .sort_by(&:package_path)
79
+ .map { |x| " - #{x.package_name} (#{x.spec_count} spec files)" }
80
+ .join("\n")
81
81
  end
82
82
 
83
83
  def package_not_found_message(package_name, prepared_command_params)
@@ -85,7 +85,7 @@ module SpecRunner
85
85
  end
86
86
 
87
87
  def missing_specs_message(skipped_packages)
88
- "NO SPECS FOUND FOR PACKAGES: \n#{skipped_packages.map{|x| " - #{x}"}.join("\n")}\n\n**** SPECS *****: "
88
+ "NO SPECS FOUND FOR PACKAGES: \n#{skipped_packages.map { |x| " - #{x}" }.join("\n")}\n\n**** SPECS *****: "
89
89
  end
90
90
 
91
91
  def no_specs_for_package(package_name)
@@ -130,7 +130,7 @@ module SpecRunner
130
130
 
131
131
  def check_input_params!
132
132
  if input_params.package_name
133
- if not is_package_included?(input_params.package_name)
133
+ unless is_package_included?(input_params.package_name)
134
134
  exit_with_message(
135
135
  view.package_not_found_message(input_params.package_name, prepared_command_params)
136
136
  )
@@ -145,9 +145,9 @@ module SpecRunner
145
145
  end
146
146
 
147
147
  def is_package_included?(package_name)
148
- prepared_command_params.select{|x|
148
+ !prepared_command_params.select do |x|
149
149
  x.package_name == package_name
150
- }.size > 0
150
+ end.empty?
151
151
  end
152
152
 
153
153
  def prepare!
@@ -161,18 +161,18 @@ module SpecRunner
161
161
 
162
162
  def prepare_command_params
163
163
  @prepared_command_params ||= begin
164
- packages.map{|name, package|
164
+ packages.map do |_name, package|
165
165
  CommandGenerator.new(
166
166
  package_name: package.name, package_path: package.path, spec_matcher: spec_matcher
167
167
  ).generate
168
- }
168
+ end
169
169
  end
170
170
  end
171
171
 
172
172
  def prepare_skipped_packages
173
173
  prepared_command_params
174
- .select{|cp| cp.spec_count == 0}
175
- .map{|cp| skipped_packages << cp.package_name}
174
+ .select { |cp| cp.spec_count == 0 }
175
+ .map { |cp| skipped_packages << cp.package_name }
176
176
  end
177
177
 
178
178
  def prepare_command
@@ -186,37 +186,33 @@ module SpecRunner
186
186
  end
187
187
 
188
188
  def prepare_single_package_command(package_name)
189
- selected = prepared_command_params.select{|cmd_params|
189
+ selected = prepared_command_params.select do |cmd_params|
190
190
  cmd_params.package_name == package_name
191
- }
191
+ end
192
192
  prepare_command_for_packages(selected)
193
193
  end
194
194
 
195
195
  def prepare_command_for_packages(packages_command_params)
196
- packages_command_params.select{|cmd_params|
196
+ packages_command_params.select do |cmd_params|
197
197
  cmd_params.spec_count > 0
198
- }.sort_by{|cmd_params|
198
+ end.sort_by do |cmd_params|
199
199
  - cmd_params.spec_count
200
- }.map{|cmd_params|
201
- cmd_params.command
202
- }.join(" && ")
200
+ end.map(&:command).join(' && ')
203
201
  end
204
202
 
205
203
  def display_missing_specs
206
- if !skipped_packages.empty?
204
+ unless skipped_packages.empty?
207
205
  print_message view.missing_specs_message(skipped_packages)
208
206
  end
209
207
  end
210
208
 
211
209
  def execute_command
212
210
  eval(command)
213
- if !$?.success?
214
- exit(1)
215
- end
211
+ exit(1) unless $CHILD_STATUS.success?
216
212
  end
217
213
 
218
214
  def spec_matcher
219
- input_params.spec_matcher || ""
215
+ input_params.spec_matcher || ''
220
216
  end
221
217
  end
222
218
 
@@ -226,19 +222,19 @@ module SpecRunner
226
222
  end
227
223
  end
228
224
 
229
- unless ENV["TEST_RUN"]
230
- SpecRunner.run
231
- else
232
- require "minitest/autorun"
225
+ if ENV['TEST_RUN']
226
+ require 'minitest/autorun'
233
227
  describe SpecRunner::Runner do
234
228
  before do
235
229
  @runner = SpecRunner::Runner.new({})
236
230
  end
237
231
 
238
- describe "works " do
239
- it "assert true" do
232
+ describe 'works ' do
233
+ it 'assert true' do
240
234
  assert 2 == 2
241
235
  end
242
236
  end
243
237
  end
238
+ else
239
+ SpecRunner.run
244
240
  end
@@ -1,11 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- require "bundler/setup"
3
- require "rdm"
2
+ require 'bundler/setup'
3
+ require 'rdm'
4
4
 
5
- ENV["RUBY_ENV"] ||= "development"
5
+ ENV['RUBY_ENV'] ||= 'development'
6
6
  Rdm.init(File.expand_path('../../', __FILE__))
7
7
 
8
-
9
8
  # You can add fixtures and/or initialization code here to make experimenting
10
9
  # with your gem easier. You can also use a different console, if you like.
11
10
 
@@ -13,5 +12,5 @@ Rdm.init(File.expand_path('../../', __FILE__))
13
12
  # require "pry"
14
13
  # Pry.start
15
14
 
16
- require "irb"
15
+ require 'irb'
17
16
  IRB.start
@@ -1,3 +1,3 @@
1
1
  module Rdm
2
- VERSION = "0.1.12"
2
+ VERSION = '0.1.13'.freeze
3
3
  end
@@ -19,5 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.add_development_dependency "bundler", "~> 1.3"
20
20
  spec.add_development_dependency "rake"
21
21
  spec.add_development_dependency "rspec"
22
+ spec.add_development_dependency "byebug"
23
+ spec.add_development_dependency "codecov"
22
24
  spec.add_dependency "activesupport"
25
+ spec.add_dependency "commander", "~> 4.4"
23
26
  end
@@ -1,8 +1,10 @@
1
1
  setup do
2
2
  role "example"
3
+ config_path "config"
4
+ silence_missing_package true
3
5
  end
4
6
 
5
7
  config :database
6
8
 
7
9
  package "application/web"
8
- package "domain/core"
10
+ package "domain/core"
@@ -0,0 +1,12 @@
1
+ setup do
2
+ role "production"
3
+ configs_dir "configs"
4
+ config_path ":configs_dir/:config_name/default.yml"
5
+ role_config_path ":configs_dir/:config_name/:role.yml"
6
+ package_subdir_name "package"
7
+ end
8
+
9
+ config :database
10
+ config :app
11
+
12
+ package "infrastructure/web"