Sha256: dde2cb62553a5795cfaf8e67429728c3759a7bd6171fd7e65897f931f8d30574

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 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? %>
<% end -%>
<% attributes.select(&:attachment?).each do |attribute| -%>
  has_one_attached :<%= attribute.name %>
<% end -%>
<% attributes.select(&:attachments?).each do |attribute| -%>
  has_many_attached :<%= attribute.name %>
<% end -%>
<% if class_name == 'User' -%>
<% if doorkeeper_oauth? -%>
  has_many :access_grants, class_name: 'Doorkeeper::AccessGrant', foreign_key: :resource_owner_id, dependent: :destroy
  has_many :access_tokens, class_name: 'Doorkeeper::AccessToken', foreign_key: :resource_owner_id, dependent: :destroy
<% end -%>
<% attributes.each do |attribute| -%>
<% if attribute.name == 'email' -%>
  validates :email, presence: true, uniqueness: { case_sensitive: false }
  before_validation :downcase_email, if: :email_changed?

  def downcase_email
    self.email = email.downcase
  end
<% end -%>
<% end -%>
<% end -%>

  def list_item_as_json
    mw_list_item(text: <%= attributes.first.name %>)
  end

  def display_as_json
    [
      mw_display_text(label: 'ID', text: id.to_s),
      mw_display_text(label: 'Text', text: <%= attributes.first.name %>)
    ]
  end
end
<% end -%>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mobile_workflow-0.7.7 lib/generators/mobile_workflow/templates/model.rb.erb