Module: LoyalCore::ActsAsHasPermalink::ClassMethods

Defined in:
lib/loyal_core/acts/has_permalink.rb

Defined Under Namespace

Modules: WithSpaceMethods

Instance Method Summary collapse

Instance Method Details



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/loyal_core/acts/has_permalink.rb', line 13

def loyal_core_acts_as_has_permalink *args
  options = args.extract_options!
  field_name = args.first || :permalink

  include WithSpaceMethods

  if options[:with_space]
    validates_format_of  field_name, :with => PERMALINK_REGEXP, :unless => :space_root?, :multiline => true
    validates_presence_of  field_name, :unless => :space_root?

    # space 格式要求正确
    validates_format_of :space, :with => PERMALINK_REGEXP, :multiline => true
    validates_uniqueness_of field_name, :uniqueness => {:scope => [:space]}
  else
    validates_format_of  field_name, :with => PERMALINK_REGEXP, :multiline => true
    validates_presence_of  field_name

    validates_uniqueness_of field_name
  end
end