Sha256: 963ac8ed53c4ad03403840d46697a1cffc50929bb7ee8d2e95336eb98f1b56f9

Contents?: true

Size: 1017 Bytes

Versions: 3

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

class Core::Repositories::<%= @scope_class %>::<%= @repository_class %> < Core::Repositories::AbstractRepository
  def initialize(params:)
    @id     = params.id
    @params = prepare! params.except(:id), sanitize: true
  end

  def call(builder: true)
<% if @resource_owner_id.present? -%>
    resource = <%= @model_class %>.find_by(id: @id, <%=@resource_owner_id%>: @params.<%=@resource_owner_id%>)
<% else -%>
    resource = <%= @model_class %>.find_by(id: @id)
<% end -%>
    return Failure '<%= @subject_class %> not found' unless resource.present?
<% if @uploaders.present? -%>
    # Remove the existing images if a new one is being uploaded
<% @uploaders.each do |uplaoder| -%>
    resource.<%=uplaoder %>.purge if @params.<%=uplaoder %>.present? && resource.<%=uplaoder %>.attached?
<% end -%>
<% end -%>
    unless resource.update(@params.to_h)
      return Failure build_errors(resource)
    end
    Success Core::Builders::<%= @subject_class %>.new(resource).build
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rider-kick-0.0.8 lib/generators/rider_kick/templates/domains/core/repositories/update.rb.tt
rider-kick-0.0.7 lib/generators/rider_kick/templates/domains/core/repositories/update.rb.tt
rider-kick-0.0.6 lib/generators/rider_kick/templates/domains/core/repositories/update.rb.tt