Module: RSS::Maker::AtomPersons

Defined in:
lib/rss/maker/atom.rb

Class Method Summary collapse

Class Method Details

.def_atom_persons(klass, name, maker_name, plural = nil) ⇒ Object



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
# File 'lib/rss/maker/atom.rb', line 10

def def_atom_persons(klass, name, maker_name, plural=nil)
  plural ||= "#{name}s"
  klass_name = Utils.to_class_name(name)
  plural_klass_name = Utils.to_class_name(plural)

  klass.class_eval(<<-EOC, __FILE__, __LINE__ + 1)
    class #{plural_klass_name} < #{plural_klass_name}Base
      class #{klass_name} < #{klass_name}Base
        def to_feed(feed, current)
          #{name} = feed.class::#{klass_name}.new
          set = setup_values(#{name})
          unless set
            raise NotSetError.new(#{maker_name.dump},
                                  not_set_required_variables)
          end
          current.#{plural} << #{name}
          set_parent(#{name}, current)
          setup_other_elements(#{name})
        end

        private
        def required_variable_names
          %w(name)
        end
      end
    end
EOC
end