Sha256: 1c50ea254129bc7206d22214718fb90bdc39e2c8e1a3b7d6f5bfcd6090bde27f
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
class Role < ActiveRecord::Base belongs_to :user belongs_to :project validates :user_id, presence: true validates :project, presence: true validates :name, presence: true, inclusion: {in: Houston.config.project_roles, message: "\"%{value}\" is unknown. It must be #{Houston.config.project_roles.to_sentence(last_word_connector: ", or ")}"} Houston.config.project_roles.each do |role| method_name = role.downcase.gsub(' ', '_') class_eval <<-RUBY def #{method_name}? name == "#{role}" end def self.#{method_name.pluralize} where(name: "#{role}") end RUBY end class << self def participants where arel_table[:name].not_eq("Follower") end def to_users User.where(id: all.select(:user_id)) end def to_projects Project.where(id: all.select(:project_id)) end def for_user(user_or_id) user_id = user_or_id.is_a?(User) ? user_or_id.id : user_or_id where user_id: user_id end def for_project(project_or_id) project_id = project_or_id.is_a?(Project) ? project_or_id.id : project_or_id where project_id: project_id end def any? count > 0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
houston-core-0.5.0.beta1 | app/models/role.rb |