Sha256: ce25760794b93649196b432a229e9ac3fc10c8f9c44db1cf457577bc387874d4

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

class <%= group_class_name %> < <%= parent_class_name.classify %>
<% attributes.select {|attr| attr.reference? }.each do |attribute| -%>
  belongs_to :<%= attribute.name %>
<% end -%>

  has_and_belongs_to_many :<%= plural_user_name %>

  ROOT = 'root'
  ADMIN = 'admin'

  def self.admin_group
    find_by_<%= attributes.first.name %>(ADMIN)
  end

  def self.root_group
    find_by_<%= attributes.first.name %>(ROOT)
  end

  def admin?
    <%= attributes.first.name %> == ADMIN
  end

  def root?
    <%= attributes.first.name %> == ROOT
  end

  def self.get(id_or_<%= attributes.first.name %>_or_<%= file_name %>)
    case id_or_<%= attributes.first.name %>_or_<%= file_name %>
    when Fixnum
      find(id_or_<%= attributes.first.name %>_or_<%= file_name %>)
    when String
      find_by_<%= attributes.first.name %>(id_or_<%= attributes.first.name %>_or_<%= file_name %>)
    when Symbol
      find_by_<%= attributes.first.name %>(id_or_<%= attributes.first.name %>_or_<%= file_name %>.to_s)
    else
      id_or_<%= attributes.first.name %>_or_<%= file_name %>
    end
  end

  def to_name
    <%= group_field_name %>
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ixtlan-guard-0.7.0 lib/generators/active_record/templates/group_model.rb
ixtlan-guard-0.6.1 lib/generators/active_record/templates/group_model.rb
ixtlan-guard-0.6.0 lib/generators/active_record/templates/group_model.rb
ixtlan-guard-0.5.0 lib/generators/active_record/templates/group_model.rb
ixtlan-guard-0.4.1 lib/generators/active_record/templates/group_model.rb
ixtlan-guard-0.4.0 lib/generators/active_record/templates/group_model.rb