Sha256: 0a10223832a2eefeb276e4132431d4f8f6409c8a8637e3c640ddeed39b296a3e

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
<% attributes.select(&:reference?).each do |attribute| -%>
  belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
<% end -%>
<% if attributes.all? { |attribute| attribute.respond_to?(:token?) } -%>
<% attributes.select(&:token?).each do |attribute| -%>
  has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
<% end -%>
<% end -%>
<% if attributes.any?(&:password_digest?) -%>
  has_secure_password
<% end -%>

  # Attributes
<% attributes.each do |attribute| -%>
  # <%= attribute.name.ljust(max_attribute_name_length) %> :<%= attribute.type %>
<% end -%>
<% if archived_attribute.present? -%>

  scope :<%= plural_table_name %>, -> { where(archived: false) }
  scope :archived, -> { where(archived: true) }
<% end -%>

<% attributes.each do |attribute| -%>
  validates :<%= attribute.name %>, presence: true
<% end -%>

<% if to_s_attribute.present? -%>
  def to_s
    <%= to_s_attribute.name %> || 'New <%= human_name %>'
  end
<% else -%>
  def to_s
    '<%= human_name %>'
  end
<% end -%>
<% if archived_attribute.present? -%>

  def destroy
    update_column(:archived, true) # This intentionally skips validation
  end

  def unarchive
    update_column(:archived, false) # This intentionally skips validation
  end
<% end -%>

end
<% end -%>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
effective_developer-0.0.10 lib/scaffolds/models/model.rb