Class: Rage::CLICodeGenerator
- Inherits:
-
Thor
- Object
- Thor
- Rage::CLICodeGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/rage/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.source_root ⇒ Object
11 12 13 |
# File 'lib/rage/cli.rb', line 11 def self.source_root File.("templates", __dir__) end |
Instance Method Details
#controller(name = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rage/cli.rb', line 34 def controller(name = nil) return help("controller") if name.nil? setup unless defined?(ActiveSupport::Inflector) raise LoadError, " ActiveSupport::Inflector is required to run this command. Add the following line to your Gemfile:\n gem \"activesupport\", require: \"active_support/inflector\"\n ERR\n end\n\n # remove trailing Controller if already present\n normalized_name = name.sub(/_?controller$/i, \"\")\n @controller_name = \"\#{normalized_name.camelize}Controller\"\n file_name = \"\#{normalized_name.underscore}_controller.rb\"\n\n template(\"controller-template/controller.rb\", \"app/controllers/\#{file_name}\")\nend\n" |
#migration(name = nil) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/rage/cli.rb', line 16 def migration(name = nil) return help("migration") if name.nil? setup Rake::Task["db:new_migration"].invoke(name) end |
#model(name = nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/rage/cli.rb', line 24 def model(name = nil) return help("model") if name.nil? setup migration("create_#{name.pluralize}") @model_name = name.classify template("model-template/model.rb", "app/models/#{name.singularize.underscore}.rb") end |