Class: SkillBench::Rails::SkillTemplates
- Inherits:
-
Object
- Object
- SkillBench::Rails::SkillTemplates
- Defined in:
- lib/skill_bench/rails/skill_templates.rb
Overview
Generates Rails-specific skill templates
Class Method Summary collapse
-
.active_record_model(name) ⇒ String
Generate an ActiveRecord model template.
-
.camelize(name) ⇒ String
Convert a snake_case or kebab-case name to CamelCase.
-
.concern(name) ⇒ String
Generate a concern template.
-
.service_object(name) ⇒ String
Generate a service object template.
Class Method Details
.active_record_model(name) ⇒ String
Generate an ActiveRecord model template
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/skill_bench/rails/skill_templates.rb', line 83 def self.active_record_model(name) class_name = camelize(name) <<~RUBY # frozen_string_literal: true class #{class_name} < ApplicationRecord # Validations validates :name, presence: true # Associations # belongs_to :user # has_many :items # Scopes # scope :active, -> { where(active: true) } # Instance methods # def some_method # ... # end # Class methods # def self.some_class_method # ... # end end RUBY end |
.camelize(name) ⇒ String
Convert a snake_case or kebab-case name to CamelCase.
Replaces ActiveSupport's String#camelize for the scaffold inputs used
here: it splits on _ and - separators, upcases the first letter of
each segment, and preserves any segment that is already CamelCase.
19 20 21 |
# File 'lib/skill_bench/rails/skill_templates.rb', line 19 def self.camelize(name) name.split(/[-_]/).map { |segment| segment.empty? ? segment : segment[0].upcase + segment[1..] }.join end |
.concern(name) ⇒ String
Generate a concern template
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/skill_bench/rails/skill_templates.rb', line 59 def self.concern(name) module_name = camelize(name) <<~RUBY # frozen_string_literal: true module #{module_name} extend ActiveSupport::Concern included do # Add class methods, associations, validations here end class_methods do # Add class methods here end # Add instance methods here end RUBY end |
.service_object(name) ⇒ String
Generate a service object template
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/skill_bench/rails/skill_templates.rb', line 26 def self.service_object(name) class_name = camelize(name) <<~RUBY # frozen_string_literal: true module SkillBench module Skills class #{class_name} # Initialize with required parameters # @param args [Hash] Keyword arguments for the service def initialize(**args) # Set instance variables from args end # Execute the service # @return [Hash] Result with :success and :response keys def call # Implement service logic here { success: true, response: { message: 'Not implemented' } } rescue StandardError => e Rails.logger.error(e.message) Rails.logger.error(e.backtrace.first(5).join("\n")) { success: false, response: { error: { message: e.message } } } end end end end RUBY end |