Module: RSS::BaseDublinCoreModel

Included in:
DublinCoreModel
Defined in:
lib/rss/dublincore.rb

Instance Method Summary collapse

Instance Method Details

#append_features(klass) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rss/dublincore.rb', line 8

def append_features(klass)
  super

  return if klass.instance_of?(Module)
  DublinCoreModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
    plural = plural_name || "#{name}s"
    full_name = "#{DC_PREFIX}_#{name}"
    full_plural_name = "#{DC_PREFIX}_#{plural}"
    klass_name = "DublinCore#{Utils.to_class_name(name)}"
    klass.install_must_call_validator(DC_PREFIX, DC_URI)
    klass.install_have_children_element(name, DC_URI, "*",
                                        full_name, full_plural_name)
    klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
      remove_method :#{full_name}
      remove_method :#{full_name}=
      remove_method :set_#{full_name}

      def #{full_name}
        @#{full_name}.first and @#{full_name}.first.value
      end

      def #{full_name}=(new_value)
        @#{full_name}[0] = Utils.new_with_value_if_need(#{klass_name}, new_value)
      end
      alias set_#{full_name} #{full_name}=
    EOC
  end
  klass.module_eval(<<-EOC, *get_file_and_line_from_caller(0))
    if method_defined?(:date)
      alias date_without_#{DC_PREFIX}_date= date=

      def date=(value)
        self.date_without_#{DC_PREFIX}_date = value
        self.#{DC_PREFIX}_date = value
      end
    else
      alias date #{DC_PREFIX}_date
      alias date= #{DC_PREFIX}_date=
    end

    # For backward compatibility
    alias #{DC_PREFIX}_rightses #{DC_PREFIX}_rights_list
  EOC
end