Class: TsykvasRailsTemplate::Generators::ConceptGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- TsykvasRailsTemplate::Generators::ConceptGenerator
- Defined in:
- lib/generators/tsykvas_rails_template/concept/concept_generator.rb
Constant Summary collapse
- VALID_CONCEPT_NAME =
%r{\A[A-Za-z][A-Za-z0-9]*(?:(?:::|/)[A-Za-z][A-Za-z0-9]*)*\z}
Instance Method Summary collapse
- #announce_next_steps ⇒ Object
- #generate_components ⇒ Object
- #generate_controller ⇒ Object
- #generate_operations ⇒ Object
- #validate_concept_name ⇒ Object
Instance Method Details
#announce_next_steps ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/generators/tsykvas_rails_template/concept/concept_generator.rb', line 79 def announce_next_steps say "" say " Concept #{class_name} scaffolded.", :green say " - operations: app/concepts/#{path}/operation/" say " - components: app/concepts/#{path}/component/" say " - controller: app/controllers/#{controller_file_path}.rb" if [:controller] say " Add routes for #{plural_var.tr("_", " ")} in config/routes.rb." say " Implement the policy at app/policies/#{singular_var}_policy.rb." say "" end |
#generate_components ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/generators/tsykvas_rails_template/concept/concept_generator.rb', line 63 def generate_components component_actions.each do |action| template "component/#{action}.rb.tt", "app/concepts/#{path}/component/#{action}.rb" template "component/#{action}.html.slim.tt", "app/concepts/#{path}/component/#{action}.html.slim" end end |
#generate_controller ⇒ Object
72 73 74 75 76 77 |
# File 'lib/generators/tsykvas_rails_template/concept/concept_generator.rb', line 72 def generate_controller return unless [:controller] template "controller.rb.tt", "app/controllers/#{controller_file_path}.rb" end |
#generate_operations ⇒ Object
56 57 58 59 60 61 |
# File 'lib/generators/tsykvas_rails_template/concept/concept_generator.rb', line 56 def generate_operations actions.each do |action| template "operation/#{action}.rb.tt", "app/concepts/#{path}/operation/#{action}.rb" end end |
#validate_concept_name ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/generators/tsykvas_rails_template/concept/concept_generator.rb', line 35 def validate_concept_name name = concept_name.to_s.strip if name.empty? raise ::Thor::Error, "concept name is required (e.g. 'Crm::Property' or 'crm/property')" end if name.start_with?("::") || name.start_with?("/") raise ::Thor::Error, "concept name '#{name}' must not start with '::' or '/'" end return if name.match?(VALID_CONCEPT_NAME) raise ::Thor::Error, "concept name '#{name}' has invalid characters " \ "(allowed: letters, digits, '::' or '/' separators; " \ "each segment must start with a letter)" end |