Sha256: e1685407fd22a288fcdb6fefaa2a831c02c9674e32676f21e9f8c3db67d53db7

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# Model <%= class_name %> defines ... TODO:
#
<% module_namespacing do -%>
class <%= class_name %> < <%= parent_class_name.classify %>
<% if attributes.any?(&:reference?) -%>

<% attributes.select(&:reference?).each do |attribute| -%>
  belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.respond_to?(:polymorphic?) and attribute.polymorphic? %><%= ', required: true' if  attribute.respond_to?(:required?) and attribute.required? %>
<% end -%>
<% end -%>
<% if attributes.first.respond_to?(:token) and attributes.any?(&:token?) -%>

<% attributes.select(&:token?).each do |attribute| -%>
  has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
<% end -%>
<% end -%>
<% if (attributes.any?(&:password_digest?) rescue false) -%>

  has_secure_password
<% end -%>
<% if attribute = attributes.detect{|a| a.name == 'position'} || attributes.detect{|a| a.name == 'name'} || attributes.detect{|a| a.name == 'title'} || attributes.first -%>

  scope :ordered, -> { order(:<%=attribute.name %>) }
<% end -%>

end
<% end -%>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_record_model_and_rspec_enhanced_templates-1.4 lib/templates/active_record/model/model.rb
active_record_model_and_rspec_enhanced_templates-1.3 lib/templates/active_record/model/model.rb
active_record_model_and_rspec_enhanced_templates-1.2 lib/templates/active_record/model/model.rb
active_record_model_and_rspec_enhanced_templates-1.1.3 lib/templates/active_record/model/model.rb