Sha256: 20c5d840cf6fb23161d17450ddb36f2cfb5473fccad191c17a83102d0f017598

Contents?: true

Size: 803 Bytes

Versions: 3

Compression:

Stored size: 803 Bytes

Contents

class <%= class_name %> < ApplicationRecord

<%- flag_attrs.each do |attr| -%>
  include DoesFlag[<%= attr.name(:symbol) %>, default: <%= attr.default %>]
<%- end -%>
<% has_manys.each do |model| -%>
  has_many <%= model.name(:symbols) %>
<% end -%>
<% belongs_tos.each do |model| -%>
  belongs_to <%= model.name(:symbol) %>, optional: true
<% end -%>
<%- if defaults.any? -%>

  has_defaults(<%= defaults %>)
<%- end -%>
<%- model.attrs.select(&:assignable_values).each do |attr|  -%>

  assignable_values_for :<%= attr.name(:variable).sub /_id$/, '' %>, <%= attr.options.slice(:allow_blank, :default) %> do
    <%= attr.assignable_values %>
  end
<%- end -%>

  def to_s
<% if model.label_attr? -%>
    <%= model.label_attr.name %>.to_s
<% else -%>
    "<%= model.name %>##{id}"
<% end -%>
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
katapult-0.5.0 lib/generators/katapult/model/templates/model.rb
katapult-0.4.1 lib/generators/katapult/model/templates/model.rb
katapult-0.4.0 lib/generators/katapult/model/templates/model.rb