riveter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +17 -0
  7. data/Gemfile +4 -0
  8. data/Gemfile.lock +147 -0
  9. data/LICENSE.txt +23 -0
  10. data/README.md +77 -0
  11. data/Rakefile +7 -0
  12. data/app/helpers/riveter/command_form_helper.rb +15 -0
  13. data/app/helpers/riveter/enquiry_form_helper.rb +16 -0
  14. data/app/helpers/riveter/query_filter_form_helper.rb +16 -0
  15. data/config/locales/forms.en.yml +25 -0
  16. data/config/locales/validators.en.yml +26 -0
  17. data/init.rb +25 -0
  18. data/lib/generators/erb/TODO +1 -0
  19. data/lib/generators/haml/command_controller/USAGE +0 -0
  20. data/lib/generators/haml/command_controller/command_controller_generator.rb +56 -0
  21. data/lib/generators/haml/command_controller/templates/new.html.haml +26 -0
  22. data/lib/generators/haml/enquiry_controller/USAGE +0 -0
  23. data/lib/generators/haml/enquiry_controller/enquiry_controller_generator.rb +56 -0
  24. data/lib/generators/haml/enquiry_controller/templates/index.html.haml +57 -0
  25. data/lib/generators/riveter/command/USAGE +0 -0
  26. data/lib/generators/riveter/command/command_generator.rb +55 -0
  27. data/lib/generators/riveter/command/templates/command.rb +40 -0
  28. data/lib/generators/riveter/command/templates/commands.en.yml +57 -0
  29. data/lib/generators/riveter/command/templates/module.rb +4 -0
  30. data/lib/generators/riveter/command_controller/USAGE +0 -0
  31. data/lib/generators/riveter/command_controller/command_controller_generator.rb +40 -0
  32. data/lib/generators/riveter/command_controller/templates/command_controller.rb +18 -0
  33. data/lib/generators/riveter/command_controller/templates/module.rb +4 -0
  34. data/lib/generators/riveter/enquiry/USAGE +0 -0
  35. data/lib/generators/riveter/enquiry/enquiry_generator.rb +29 -0
  36. data/lib/generators/riveter/enquiry/templates/enquiry.rb +11 -0
  37. data/lib/generators/riveter/enquiry/templates/module.rb +4 -0
  38. data/lib/generators/riveter/enquiry_controller/USAGE +0 -0
  39. data/lib/generators/riveter/enquiry_controller/enquiry_controller_generator.rb +34 -0
  40. data/lib/generators/riveter/enquiry_controller/templates/enquiry_controller.rb +9 -0
  41. data/lib/generators/riveter/enquiry_controller/templates/module.rb +4 -0
  42. data/lib/generators/riveter/enum/USAGE +41 -0
  43. data/lib/generators/riveter/enum/enum_generator.rb +51 -0
  44. data/lib/generators/riveter/enum/templates/enum.rb +17 -0
  45. data/lib/generators/riveter/enum/templates/enums.en.yml +35 -0
  46. data/lib/generators/riveter/enum/templates/module.rb +4 -0
  47. data/lib/generators/riveter/install/USAGE +0 -0
  48. data/lib/generators/riveter/install/install_generator.rb +14 -0
  49. data/lib/generators/riveter/presenter/USAGE +0 -0
  50. data/lib/generators/riveter/presenter/presenter_generator.rb +20 -0
  51. data/lib/generators/riveter/presenter/templates/module.rb +4 -0
  52. data/lib/generators/riveter/presenter/templates/presenter.rb +7 -0
  53. data/lib/generators/riveter/query/USAGE +22 -0
  54. data/lib/generators/riveter/query/query_generator.rb +20 -0
  55. data/lib/generators/riveter/query/templates/module.rb +4 -0
  56. data/lib/generators/riveter/query/templates/query.rb +31 -0
  57. data/lib/generators/riveter/query_filter/USAGE +0 -0
  58. data/lib/generators/riveter/query_filter/query_filter_generator.rb +52 -0
  59. data/lib/generators/riveter/query_filter/templates/module.rb +4 -0
  60. data/lib/generators/riveter/query_filter/templates/query_filter.rb +40 -0
  61. data/lib/generators/riveter/query_filter/templates/query_filters.en.yml +49 -0
  62. data/lib/generators/riveter/service/USAGE +0 -0
  63. data/lib/generators/riveter/service/service_generator.rb +20 -0
  64. data/lib/generators/riveter/service/templates/module.rb +4 -0
  65. data/lib/generators/riveter/service/templates/service.rb +12 -0
  66. data/lib/generators/riveter/worker/USAGE +0 -0
  67. data/lib/generators/riveter/worker/templates/module.rb +4 -0
  68. data/lib/generators/riveter/worker/templates/worker.rb +7 -0
  69. data/lib/generators/riveter/worker/worker_generator.rb +20 -0
  70. data/lib/generators/rspec/command/USAGE +0 -0
  71. data/lib/generators/rspec/command/command_generator.rb +11 -0
  72. data/lib/generators/rspec/command/templates/command_spec.rb +8 -0
  73. data/lib/generators/rspec/command_controller/USAGE +0 -0
  74. data/lib/generators/rspec/command_controller/command_controller_generator.rb +21 -0
  75. data/lib/generators/rspec/command_controller/templates/command_controller_spec.rb +70 -0
  76. data/lib/generators/rspec/enquiry/USAGE +0 -0
  77. data/lib/generators/rspec/enquiry/enquiry_generator.rb +11 -0
  78. data/lib/generators/rspec/enquiry/templates/enquiry_spec.rb +69 -0
  79. data/lib/generators/rspec/enquiry_controller/USAGE +0 -0
  80. data/lib/generators/rspec/enquiry_controller/enquiry_controller_generator.rb +16 -0
  81. data/lib/generators/rspec/enquiry_controller/templates/enquiry_controller_spec.rb +32 -0
  82. data/lib/generators/rspec/enum/USAGE +0 -0
  83. data/lib/generators/rspec/enum/enum_generator.rb +11 -0
  84. data/lib/generators/rspec/enum/templates/enum_spec.rb +8 -0
  85. data/lib/generators/rspec/presenter/USAGE +0 -0
  86. data/lib/generators/rspec/presenter/presenter_generator.rb +11 -0
  87. data/lib/generators/rspec/presenter/templates/presenter_spec.rb +8 -0
  88. data/lib/generators/rspec/query/USAGE +0 -0
  89. data/lib/generators/rspec/query/query_generator.rb +11 -0
  90. data/lib/generators/rspec/query/templates/query_spec.rb +41 -0
  91. data/lib/generators/rspec/query_filter/USAGE +0 -0
  92. data/lib/generators/rspec/query_filter/query_filter_generator.rb +11 -0
  93. data/lib/generators/rspec/query_filter/templates/query_filter_spec.rb +8 -0
  94. data/lib/generators/rspec/service/USAGE +0 -0
  95. data/lib/generators/rspec/service/service_generator.rb +11 -0
  96. data/lib/generators/rspec/service/templates/service_spec.rb +8 -0
  97. data/lib/generators/rspec/worker/USAGE +0 -0
  98. data/lib/generators/rspec/worker/templates/worker_spec.rb +8 -0
  99. data/lib/generators/rspec/worker/worker_generator.rb +11 -0
  100. data/lib/generators/test_unit/TODO +1 -0
  101. data/lib/riveter/associated_type_registry.rb +63 -0
  102. data/lib/riveter/attribute_default_values.rb +67 -0
  103. data/lib/riveter/attributes.rb +443 -0
  104. data/lib/riveter/booleaness_validator.rb +20 -0
  105. data/lib/riveter/command.rb +59 -0
  106. data/lib/riveter/command_controller.rb +93 -0
  107. data/lib/riveter/command_routes.rb +73 -0
  108. data/lib/riveter/core_extensions.rb +246 -0
  109. data/lib/riveter/email_validator.rb +20 -0
  110. data/lib/riveter/enquiry.rb +137 -0
  111. data/lib/riveter/enquiry_controller.rb +80 -0
  112. data/lib/riveter/enquiry_routes.rb +69 -0
  113. data/lib/riveter/enumerated.rb +107 -0
  114. data/lib/riveter/errors.rb +11 -0
  115. data/lib/riveter/form_builder_extensions.rb +21 -0
  116. data/lib/riveter/hash_with_dependency.rb +12 -0
  117. data/lib/riveter/presenter.rb +73 -0
  118. data/lib/riveter/query.rb +45 -0
  119. data/lib/riveter/query_filter.rb +22 -0
  120. data/lib/riveter/rails/engine.rb +6 -0
  121. data/lib/riveter/rails/railtie.rb +50 -0
  122. data/lib/riveter/service.rb +45 -0
  123. data/lib/riveter/spec_helper.rb +55 -0
  124. data/lib/riveter/tasks/.keep +0 -0
  125. data/lib/riveter/version.rb +3 -0
  126. data/lib/riveter/worker.rb +20 -0
  127. data/lib/riveter.rb +47 -0
  128. data/riveter.gemspec +40 -0
  129. data/spec/examples/attribute_examples.rb +57 -0
  130. data/spec/generators/haml/command_controller/command_controller_generator_spec.rb +34 -0
  131. data/spec/generators/haml/enquiry_controller/enquiry_controller_generator_spec.rb +34 -0
  132. data/spec/generators/riveter/command/command_generator_spec.rb +58 -0
  133. data/spec/generators/riveter/command_controller/command_controller_generator_spec.rb +0 -0
  134. data/spec/generators/riveter/enquiry/enquiry_generator_spec.rb +0 -0
  135. data/spec/generators/riveter/query_filter/query_filter_generator_spec.rb +58 -0
  136. data/spec/riveter/associated_type_registry_spec.rb +158 -0
  137. data/spec/riveter/attribute_default_value_spec.rb +69 -0
  138. data/spec/riveter/attributes_spec.rb +228 -0
  139. data/spec/riveter/command_controller_spec.rb +116 -0
  140. data/spec/riveter/command_routes_spec.rb +116 -0
  141. data/spec/riveter/command_spec.rb +66 -0
  142. data/spec/riveter/core_extensions_spec.rb +209 -0
  143. data/spec/riveter/enquiry_controller_spec.rb +128 -0
  144. data/spec/riveter/enquiry_routes_spec.rb +101 -0
  145. data/spec/riveter/enquiry_spec.rb +299 -0
  146. data/spec/riveter/enumerated_spec.rb +47 -0
  147. data/spec/riveter/form_builder_extensions_spec.rb +28 -0
  148. data/spec/riveter/presenter_spec.rb +131 -0
  149. data/spec/riveter/query_filter_spec.rb +19 -0
  150. data/spec/riveter/query_spec.rb +72 -0
  151. data/spec/riveter/service_spec.rb +49 -0
  152. data/spec/riveter/spec_helper_spec.rb +21 -0
  153. data/spec/riveter/worker_spec.rb +11 -0
  154. data/spec/spec_helper.rb +54 -0
  155. data/spec/support/test_associated_class.rb +2 -0
  156. data/spec/support/test_class_with_attributes.rb +17 -0
  157. data/spec/support/test_command.rb +4 -0
  158. data/spec/support/test_command_controller.rb +12 -0
  159. data/spec/support/test_command_routes.rb +3 -0
  160. data/spec/support/test_enquiry.rb +7 -0
  161. data/spec/support/test_enquiry_controller.rb +12 -0
  162. data/spec/support/test_enquiry_routes.rb +3 -0
  163. data/spec/support/test_enum.rb +8 -0
  164. data/spec/support/test_form_builder.rb +3 -0
  165. data/spec/support/test_model.rb +2 -0
  166. data/spec/support/test_model_with_attribute_default_values.rb +29 -0
  167. data/spec/support/test_presenter.rb +2 -0
  168. data/spec/support/test_query.rb +5 -0
  169. data/spec/support/test_query_filter.rb +4 -0
  170. data/spec/support/test_service.rb +7 -0
  171. data/spec/support/validate_booleaness_of_matcher.rb +17 -0
  172. data/spec/support/validate_timeliness_of_matcher.rb +17 -0
  173. data/spec/support/validator_detector.rb +48 -0
  174. metadata +487 -0
@@ -0,0 +1,55 @@
1
+ module Riveter
2
+ module Generators
3
+ class CommandGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ check_class_collision :suffix => 'Command'
7
+
8
+ argument :command_attributes,
9
+ :type => :array,
10
+ :default => [],
11
+ :banner => "[name[:type[:required]] name[:type[:required]]]"
12
+
13
+ class_option :command_controller, :type => :boolean, :default => true
14
+ hook_for :command_controller, :type => :boolean
15
+
16
+ def initialize(args, *options)
17
+ super
18
+ parse_command_attributes!
19
+ end
20
+
21
+ def create_command_file
22
+ template 'command.rb', File.join('app/commands', class_path, "#{file_name}_command.rb")
23
+ end
24
+
25
+ def create_module_file
26
+ return if regular_class_path.empty?
27
+ template 'module.rb', File.join('app/commands', "#{class_path.join('/')}.rb") if behavior == :invoke
28
+ end
29
+
30
+ def create_locale_file
31
+ template 'commands.en.yml', File.join('config/locales', 'commands.en.yml') unless locale_file_exists?
32
+ end
33
+
34
+ hook_for :test_framework, :as => :command
35
+
36
+ protected
37
+
38
+ def parse_command_attributes!
39
+ self.command_attributes = (command_attributes || []).map do |attribute|
40
+ # expected in the form "name", "name:type" or "name:type:required"
41
+ parts = attribute.split(':')
42
+ OpenStruct.new(
43
+ :name => parts.first.underscore,
44
+ :type => ((parts.length > 1) ? parts[1] : 'string'),
45
+ :inject_options => ((parts.length == 3 && parts[2] == 'required') ? ', :required => true' : '')
46
+ )
47
+ end
48
+ end
49
+
50
+ def locale_file_exists?
51
+ File.exists?(File.join(destination_root, 'config', 'locales', 'commands.en.yml'))
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,40 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Command < Riveter::Command::Base
3
+ <% if command_attributes.any? %>
4
+ <% command_attributes.each do |attribute| -%>
5
+ attr_<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
6
+ <% end -%>
7
+ <% else -%>
8
+
9
+ #
10
+ # define command attributes
11
+ #
12
+ # E.g.
13
+ #
14
+ # attr_string :name[, options]
15
+ #
16
+ # options include:
17
+ # :required => true|false # default is false
18
+ # :default => 'a value' # default is nil
19
+ # :validate => true|false # default is true
20
+ #
21
+ # supported attributes:
22
+ #
23
+ # attr_string
24
+ # attr_text
25
+ # attr_integer
26
+ # attr_decimal
27
+ # attr_date
28
+ # attr_time
29
+ # attr_boolean
30
+ # attr_enum
31
+ # attr_array
32
+ # attr_hash
33
+ # attr_model
34
+ #
35
+ <% end -%>
36
+
37
+ # optionally, define additional validations
38
+
39
+ end
40
+ <% end -%>
@@ -0,0 +1,57 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+
24
+ # shared attribute translations (NB: across all objects!)
25
+ attributes:
26
+
27
+ #
28
+ # E.g. shared "name" attribute
29
+ #
30
+
31
+ name: Name
32
+
33
+ # translations for commands
34
+ commands:
35
+
36
+ models:
37
+
38
+ #
39
+ # E.g. for ExampleCommand as follows
40
+ #
41
+ example: Example Command Name
42
+
43
+ attributes:
44
+
45
+ #
46
+ # E.g. for attributes of the ExampleCommand as follows
47
+ #
48
+ example:
49
+ active_only: Active items only?
50
+
51
+ notices:
52
+
53
+ #
54
+ # E.g. for success notices of the ExampleCommand as follows
55
+ #
56
+ example:
57
+ success: Successfully executed example.
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
File without changes
@@ -0,0 +1,40 @@
1
+ module Riveter
2
+ module Generators
3
+ class CommandControllerGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ check_class_collision :suffix => 'CommandController'
7
+
8
+ argument :new_action,
9
+ :type => :string,
10
+ :default => 'new',
11
+ :banner => 'new_action'
12
+
13
+ argument :create_action,
14
+ :type => :string,
15
+ :default => 'create',
16
+ :banner => 'create_action'
17
+
18
+ def create_command_controller_file
19
+ template 'command_controller.rb', File.join('app/controllers', class_path, "#{file_name}_command_controller.rb")
20
+ end
21
+
22
+ def create_module_file
23
+ return if regular_class_path.empty?
24
+ template 'module.rb', File.join('app/controllers', "#{class_path.join('/')}.rb") if behavior == :invoke
25
+ end
26
+
27
+ def add_command_route
28
+ route "command :#{class_name.underscore}#{additional_args}"
29
+ end
30
+
31
+ hook_for :template_engine
32
+ hook_for :test_framework, :as => :command_controller
33
+
34
+ def additional_args
35
+ ((new_action == 'new') ? '' : ", :new_action => :#{new_action}") +
36
+ ((create_action == 'create') ? '' : ", :create_action => :#{create_action}")
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,18 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>CommandController < ApplicationController
3
+ include Riveter::CommandController
4
+
5
+ # register as controller for specified command
6
+ command_controller_for <%= class_name %>Command<%= additional_args %>
7
+
8
+ def on_success(command, result)
9
+ # TODO: provide path for redirect
10
+ respond_to do |format|
11
+ format.html { redirect_to '/', :notice => <%= class_name %>Command.success_notice }
12
+ format.json { render :status => :completed }
13
+ format.js
14
+ end
15
+ end
16
+
17
+ end
18
+ <% end -%>
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
File without changes
@@ -0,0 +1,29 @@
1
+ module Riveter
2
+ module Generators
3
+ class EnquiryGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ class_option :enquiry_controller, :type => :boolean, :default => true
7
+ hook_for :enquiry_controller, :type => :boolean
8
+
9
+ class_option :query, :type => :boolean, :default => true
10
+ hook_for :query, :type => :boolean
11
+
12
+ class_option :query_filter, :type => :boolean, :default => true
13
+ hook_for :query_filter, :type => :boolean
14
+
15
+ check_class_collision :suffix => 'Enquiry'
16
+
17
+ def create_enquiry_file
18
+ template 'enquiry.rb', File.join('app/enquiries', class_path, "#{file_name}_enquiry.rb")
19
+ end
20
+
21
+ def create_module_file
22
+ return if regular_class_path.empty?
23
+ template 'module.rb', File.join('app/enquiries', "#{class_path.join('/')}.rb") if behavior == :invoke
24
+ end
25
+
26
+ hook_for :test_framework, :as => :enquiry
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Enquiry < Riveter::Enquiry::Base
3
+
4
+ # define filter to use
5
+ filter_with <%= class_name %>QueryFilter
6
+
7
+ # define query to use
8
+ query_with <%= class_name %>Query
9
+
10
+ end
11
+ <% end -%>
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
File without changes
@@ -0,0 +1,34 @@
1
+ module Riveter
2
+ module Generators
3
+ class EnquiryControllerGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ check_class_collision :suffix => 'EnquiryController'
7
+
8
+ argument :action_name,
9
+ :type => :string,
10
+ :default => 'index',
11
+ :banner => 'action_name'
12
+
13
+ def create_enquiry_controller_file
14
+ template 'enquiry_controller.rb', File.join('app/controllers', class_path, "#{file_name}_enquiry_controller.rb")
15
+ end
16
+
17
+ def create_module_file
18
+ return if regular_class_path.empty?
19
+ template 'module.rb', File.join('app/controllers', "#{class_path.join('/')}.rb") if behavior == :invoke
20
+ end
21
+
22
+ def add_enquiry_route
23
+ route "enquiry :#{class_name.underscore}#{additional_args}"
24
+ end
25
+
26
+ hook_for :template_engine
27
+ hook_for :test_framework, :as => :enquiry_controller
28
+
29
+ def additional_args
30
+ (action_name == 'index') ? '' : ", :action => :#{action_name}"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>EnquiryController < ApplicationController
3
+ include Riveter::EnquiryController
4
+
5
+ # register as controller for specified enquiry
6
+ enquiry_controller_for <%= class_name %>Enquiry<%= additional_args %>
7
+
8
+ end
9
+ <% end -%>
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
@@ -0,0 +1,41 @@
1
+ Description:
2
+ Stubs out a enumeration module. Pass the enumeration name, either CamelCased or
3
+ under_scored, and an optional list of member value pairs as arguments.
4
+ "Enum" will be appended to the name of the module.
5
+
6
+ Member pairs are member:value arguments specifying the members and optionally their values.
7
+ If the value part is omitted, an integer value will be assigned, based on the members position
8
+ in the list of member arguments
9
+
10
+ You don't have to think up every member up front, but it helps to
11
+ sketch out a few so you can start working with the enumeration immediately.
12
+
13
+ This generator invokes your configured test framework which defaults to TestUnit
14
+
15
+ If you pass a namespaced enumeration name (e.g. admin/account_type or Admin::AccountType)
16
+ then the generator will create a module (e.g. admin_account_type)
17
+
18
+ Examples:
19
+ `rails generate riveter:enum account_type`
20
+
21
+ Creates an enumeration module
22
+
23
+ Enum: app/enums/account_type_enum.rb
24
+
25
+ `rails generate riveter:enum admin/account_type`
26
+
27
+ Creates an enumeration module within the admin namespace
28
+
29
+ Enum: app/enums/admin/account_type_enum.rb
30
+
31
+ `rails generate riveter:enum account_type local foreign`
32
+
33
+ Creates an enumeration module, with "Local" and "Foreign" as members with default integer values
34
+
35
+ Enum: app/enums/account_type_enum.rb
36
+
37
+ `rails generate riveter:enum account_type local:1 foreign:2`
38
+
39
+ Creates an enumeration module, with "Local" and "Foreign" as members with the values 1 and 2 respectively
40
+
41
+ Enum: app/enums/account_type_enum.rb
@@ -0,0 +1,51 @@
1
+ module Riveter
2
+ module Generators
3
+ class EnumGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ check_class_collision :suffix => 'Enum'
7
+
8
+ argument :enum_members,
9
+ :type => :array,
10
+ :default => [],
11
+ :banner => "[name[:value] name[:value]]"
12
+
13
+ def initialize(args, *options)
14
+ super
15
+ parse_enum_members!
16
+ end
17
+
18
+ def create_enum_file
19
+ template 'enum.rb', File.join('app/enums', class_path, "#{file_name}.rb")
20
+ end
21
+
22
+ def create_module_file
23
+ return if regular_class_path.empty?
24
+ template 'module.rb', File.join('app/enums', "#{class_path.join('/')}.rb") if behavior == :invoke
25
+ end
26
+
27
+ def create_locale_file
28
+ template 'enums.en.yml', File.join('config/locales', 'enums.en.yml') unless locale_file_exists?
29
+ end
30
+
31
+ hook_for :test_framework, :as => :enum
32
+
33
+ protected
34
+
35
+ def parse_enum_members!
36
+ self.enum_members = (enum_members || []).map do |member|
37
+ # expected in the form "name:value" or "name"
38
+ parts = member.split(':')
39
+ OpenStruct.new(
40
+ :name => parts.first.titleize,
41
+ :value => (parts.length > 1 ? parts.last : nil)
42
+ )
43
+ end
44
+ end
45
+
46
+ def locale_file_exists?
47
+ File.exists?(File.join(destination_root, 'config', 'locales', 'enums.en.yml'))
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,17 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_name %>Enum
3
+ <% if enum_members.any? -%>
4
+ <% enum_members.each_with_index do |member, index| -%>
5
+ <%= member.name %> = <%= member.value || ((index + 1) * 10) %>
6
+ <% end -%>
7
+ <% else -%>
8
+ # TODO: define constants for each member of the enumeration
9
+ <% end -%>
10
+
11
+ # include the enumerated module
12
+ include Riveter::Enumerated
13
+
14
+ # NOTE: any constants defined here onwards will be ignored
15
+
16
+ end
17
+ <% end -%>
@@ -0,0 +1,35 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+
24
+ # translations for enums
25
+ enums:
26
+
27
+ # shared members can be defined here
28
+
29
+ #
30
+ # e.g. for the display name and members ExampleEnum::Member1 and ExampleEnum::Member2 as follows
31
+ #
32
+ example:
33
+ human: An Example Enumeration
34
+ member1: Member 1
35
+ member2: Member 2
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
File without changes
@@ -0,0 +1,14 @@
1
+ module Riveter
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ # TODO
7
+
8
+ # insert require into the spec helper file
9
+ # auto_load paths for concerns
10
+ # copy locale files
11
+
12
+ end
13
+ end
14
+ end
File without changes
@@ -0,0 +1,20 @@
1
+ module Riveter
2
+ module Generators
3
+ class PresenterGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ check_class_collision :suffix => 'Presenter'
7
+
8
+ def create_presenter_file
9
+ template 'presenter.rb', File.join('app/presenters', class_path, "#{file_name}_presenter.rb")
10
+ end
11
+
12
+ def create_module_file
13
+ return if regular_class_path.empty?
14
+ template 'module.rb', File.join('app/presenters', "#{class_path.join('/')}.rb") if behavior == :invoke
15
+ end
16
+
17
+ hook_for :test_framework, :as => :presenter
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Presenter < Riveter::Presenter::Base
3
+
4
+ # TODO
5
+
6
+ end
7
+ <% end -%>
@@ -0,0 +1,22 @@
1
+ Description:
2
+ Stubs out a new query. Pass the model name, either CamelCased or
3
+ under_scored as the model to base the query on.
4
+ "Query" will be appended to the name of the query class.
5
+
6
+ This generator invokes your configured test framework which defaults to TestUnit
7
+
8
+ If you pass a namespaced model name (e.g. admin/account or Admin::Account)
9
+ then the generator will create a module (e.g. admin_account)
10
+
11
+ Examples:
12
+ `rails generate riveter:query portfolio`
13
+
14
+ Creates a query class based off of the Portfolio model
15
+
16
+ Query: app/queries/portfolio_query.rb
17
+
18
+ `rails generate riveter:query admin/account`
19
+
20
+ Creates a query class based off of the Admin::Account model
21
+
22
+ Query: app/queries/admin/account_query.rb
@@ -0,0 +1,20 @@
1
+ module Riveter
2
+ module Generators
3
+ class QueryGenerator < ::Rails::Generators::NamedBase
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ check_class_collision :suffix => 'Query'
7
+
8
+ def create_query_file
9
+ template 'query.rb', File.join('app/queries', class_path, "#{file_name}_query.rb")
10
+ end
11
+
12
+ def create_module_file
13
+ return if regular_class_path.empty?
14
+ template 'module.rb', File.join('app/queries', "#{class_path.join('/')}.rb") if behavior == :invoke
15
+ end
16
+
17
+ hook_for :test_framework, :as => :query
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ <% module_namespacing do -%>
2
+ module <%= class_path.map(&:camelize).join('::') %>
3
+ end
4
+ <% end -%>
@@ -0,0 +1,31 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %>Query < Riveter::Query::Base
3
+
4
+ # TODO: optionally provide methods here for additional
5
+ # results such as summaries, aggregated data or other
6
+ # associated data
7
+
8
+ protected
9
+
10
+ def build_relation(filter)
11
+ # start with a relation
12
+ relation = <%= class_name %>.all
13
+
14
+ #
15
+ # TODO: apply conditions etc to the query using the filter
16
+ #
17
+ # E.g.
18
+ #
19
+ # :.name filter
20
+ #
21
+ # relation = relation.where?(filter.name_like.present?, 'name LIKE ?', filter.name_like)
22
+ #
23
+ # :. page filter
24
+ # relation.page(filter.page)
25
+ #
26
+
27
+ relation
28
+ end
29
+
30
+ end
31
+ <% end -%>
File without changes