class Embryo::RubyTemplate::Controller
Public Class Methods
new(model, action_templates)
click to toggle source
# File lib/rails-embryo/ruby_template/controller.rb, line 5 def initialize(model, action_templates) @model = model @action_templates = action_templates end
Public Instance Methods
path()
click to toggle source
# File lib/rails-embryo/ruby_template/controller.rb, line 10 def path "app/controllers/#{@model.plural_path}_controller.rb" end
Protected Instance Methods
code()
click to toggle source
# File lib/rails-embryo/ruby_template/controller.rb, line 16 def code [ "class #{@model.plural_class_name}Controller < ApplicationController", indent("before_action :find_#{@model.singular}, only: [:show, :update, :destroy]"), *indented_action_methods, indent_section("private"), indent_section(finder_method), indent_section(params_method), "end" ] end
finder_method()
click to toggle source
# File lib/rails-embryo/ruby_template/controller.rb, line 34 def finder_method method_code "find_#{@model.singular}", "@#{@model.singular} = #{@model.class_name}.find params[:id]" end
indented_action_methods()
click to toggle source
# File lib/rails-embryo/ruby_template/controller.rb, line 28 def indented_action_methods @action_templates.map do |action| indent_section action.controller_method_code end end
params_method()
click to toggle source
# File lib/rails-embryo/ruby_template/controller.rb, line 39 def params_method method_code "#{@model.singular}_params", "params.fetch(:#{@model.singular})" end