Class: Adjective::CreateAdjectiveClass
- Inherits:
-
Object
- Object
- Adjective::CreateAdjectiveClass
- Defined in:
- lib/templates/create_adjective_class.rb
Instance Method Summary collapse
- #base_template ⇒ Object
- #file_class_name ⇒ Object
- #file_name ⇒ Object
- #given_modules ⇒ Object
- #inherited_classes ⇒ Object
-
#initialize(class_name, modules = []) ⇒ CreateAdjectiveClass
constructor
A new instance of CreateAdjectiveClass.
- #modules_string ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(class_name, modules = []) ⇒ CreateAdjectiveClass
Returns a new instance of CreateAdjectiveClass.
3 4 5 6 7 |
# File 'lib/templates/create_adjective_class.rb', line 3 def initialize(class_name, modules = []) @class_name = class_name @modules = modules.map{|m| m&.downcase} @module_classes = given_modules end |
Instance Method Details
#base_template ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/templates/create_adjective_class.rb', line 32 def base_template <<~TEMPLATE class {{class_name}} {{active_record_inheritance}} {{modules_string}} end TEMPLATE end |
#file_class_name ⇒ Object
9 10 11 |
# File 'lib/templates/create_adjective_class.rb', line 9 def file_class_name @class_name.capitalize end |
#file_name ⇒ Object
13 14 15 |
# File 'lib/templates/create_adjective_class.rb', line 13 def file_name @class_name.downcase + ".rb" end |
#given_modules ⇒ Object
17 18 19 20 21 |
# File 'lib/templates/create_adjective_class.rb', line 17 def given_modules @modules.map do |mod| klass = "Adjective::#{mod.capitalize}".constantize end end |
#inherited_classes ⇒ Object
27 28 29 30 |
# File 'lib/templates/create_adjective_class.rb', line 27 def inherited_classes return "< ApplicationRecord" if Adjective.configuration.use_active_record return "" end |
#modules_string ⇒ Object
23 24 25 |
# File 'lib/templates/create_adjective_class.rb', line 23 def modules_string @modules.map {|mod| " include Adjective::#{mod.capitalize}"}.join("\n") end |
#render ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/templates/create_adjective_class.rb', line 40 def render base = base_template base .gsub("{{class_name}}", file_class_name.lstrip) .gsub("{{active_record_inheritance}}", inherited_classes.lstrip) .gsub("{{modules_string}}", modules_string) end |