Module: Vimo::SystemName::ClassMethods

Defined in:
app/models/vimo/system_name.rb

Instance Method Summary collapse

Instance Method Details

#has_system_name(opts = {}) ⇒ Object



22
23
24
25
26
# File 'app/models/vimo/system_name.rb', line 22

def has_system_name(opts = {})
  attr_protected :system_name if opts.delete(:protected)
  self._system_human_name = opts.delete(:human_name) || :name
  validates_system_name(opts)
end

#validates_system_name(opts = {}) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/models/vimo/system_name.rb', line 13

def validates_system_name(opts = {})
  validates :system_name, presence: true, format: { with: /\A\w[\w\-\/]+\z/ }
  validates :name, presence: true

  if opts[:uniqueness_scope]
    validates :system_name, uniqueness: opts[:uniqueness_scope] == true ? true : { scope: opts[:uniqueness_scope] }
  end
end