Sha256: 690c16834665e5faf30c55e627b33ac12dc14f9d60386d2e0d0dbb8a26f5425e

Contents?: true

Size: 1.44 KB

Versions: 3

Compression:

Stored size: 1.44 KB

Contents

<% module_namespacing do -%>
class <%= resource.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 <%= resource.human_name %>'
  end
<% else -%>
  def to_s
    '<%= resource.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

3 entries across 3 versions & 1 rubygems

Version Path
effective_developer-0.2.1 lib/scaffolds/models/model.rb
effective_developer-0.2 lib/scaffolds/models/model.rb
effective_developer-0.1.1 lib/scaffolds/models/model.rb