Sha256: 3f858f7309980e4511c7fa9f695aa9794835b8418fe7e80867d20a3d2be7767b
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
module WebammToRails module Sources module Controllers module Actions module CreateDefinition class Presenter def initialize(table_name:, crud_definition:) @table_name = table_name @crud_definition = crud_definition end def render template_path = File.expand_path('template.erb', __dir__) template_content = File.read(template_path) raw_content = ERB.new(template_content, trim_mode: '-').result(instance_eval { binding }) ::WebammToRails::Utils::FormatCode.call(raw_content) end def access_scope = :public def render? @crud_definition.actions.find { |action| action.name == 'create' }.present? end private def variable_name "@#{@table_name.singularize}" end def new_call "#{@table_name.classify}.new(#{@table_name.singularize}_params)" end def redirection_path if @crud_definition.actions.find { |action| action.name == 'index' } "#{@table_name}_path" elsif @crud_definition.actions.find { |action| action.name == 'show' } "#{@table_name.singularize}_path(#{variable_name})" else "root_path" end end end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems