notebook/app/models/attribute_field.rb
2018-08-18 16:49:17 -05:00

76 lines
1.2 KiB
Ruby

class AttributeField < ApplicationRecord
acts_as_paranoid
validates :name, presence: true
belongs_to :user
belongs_to :attribute_category
has_many :attribute_values, class_name: 'Attribute'
validates_presence_of :user_id
include HasAttributes
include Serendipitous::Concern
include Authority::Abilities
self.authorizer_name = 'AttributeAuthorizer'
attr_accessor :system
before_validation :ensure_name
scope :is_public, -> { eager_load(:universe).where('universes.privacy = ? OR attribute_fields.privacy = ?', 'public', 'public') }
def self.color
'amber'
end
def self.icon
'text_fields'
end
# Icon used for a specific attribute field
def icon
case self.field_type
when 'name'
'fingerprint'
when 'textarea'
'text_fields'
when 'universe'
'vpn_lock'
else
'text_fields'
end
end
def self.content_name
'attribute'
end
def humanize
label
end
def private?
privacy != 'public'
end
def system?
!!self.system
end
def name_field?
self.field_type == 'name'
end
def universe_field?
self.field_type == 'universe'
end
private
def ensure_name
self.name ||= "#{label}-#{Time.now.to_i}".underscore.gsub(' ', '_')
end
end