In Files

  • rss-0.2.9/lib/rss/maker/base.rb

Class/Module Index [+]

Quicksearch

RSS::Maker::Base

Attributes

maker[R]

Public Class Methods

add_need_initialize_variable(variable_name, init_value=nil, &init_block) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 35
def add_need_initialize_variable(variable_name, init_value=nil,
                                 &init_block)
  init_value ||= init_block
  self::NEED_INITIALIZE_VARIABLES << [variable_name, init_value]
end
            
add_other_element(variable_name) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 31
def add_other_element(variable_name)
  self::OTHER_ELEMENTS << variable_name
end
            
def_array_element(name, plural=nil, klass_name=nil) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 41
        def def_array_element(name, plural=nil, klass_name=nil)
          include Enumerable
          extend Forwardable

          plural ||= "#{name}s"
          klass_name ||= Utils.to_class_name(name)
          def_delegators("@#{plural}", :<<, :[], :[]=, :first, :last)
          def_delegators("@#{plural}", :push, :pop, :shift, :unshift)
          def_delegators("@#{plural}", :each, :size, :empty?, :clear)

          add_need_initialize_variable(plural) {[]}

          module_eval("            def new_#{name}
              #{name} = self.class::#{klass_name}.new(@maker)
              @#{plural} << #{name}
              if block_given?
                yield #{name}
              else
                #{name}
              end
            end
            alias new_child new_#{name}

            def to_feed(*args)
              @#{plural}.each do |#{name}|
                #{name}.to_feed(*args)
              end
            end

            def replace(elements)
              @#{plural}.replace(elements.to_a)
            end
", __FILE__, __LINE__ + 1)
        end
            
def_classed_element(name, class_name=nil, attribute_name=nil) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 95
        def def_classed_element(name, class_name=nil, attribute_name=nil)
          def_classed_element_without_accessor(name, class_name)
          if attribute_name
            module_eval("              def #{name}
                if block_given?
                  yield(@#{name})
                else
                  @#{name}.#{attribute_name}
                end
              end

              def #{name}=(new_value)
                @#{name}.#{attribute_name} = new_value
              end
", __FILE__, __LINE__ + 1)
          else
            attr_reader name
          end
        end
            
def_classed_element_without_accessor(name, class_name=nil) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 77
        def def_classed_element_without_accessor(name, class_name=nil)
          class_name ||= Utils.to_class_name(name)
          add_other_element(name)
          add_need_initialize_variable(name) do |object|
            object.send("make_#{name}")
          end
          module_eval("            private
            def setup_#{name}(feed, current)
              @#{name}.to_feed(feed, current)
            end

            def make_#{name}
              self.class::#{class_name}.new(@maker)
            end
", __FILE__, __LINE__ + 1)
        end
            
def_classed_elements(name, attribute, plural_class_name=nil, plural_name=nil, new_name=nil) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 116
        def def_classed_elements(name, attribute, plural_class_name=nil,
                                 plural_name=nil, new_name=nil)
          plural_name ||= "#{name}s"
          new_name ||= name
          def_classed_element(plural_name, plural_class_name)
          local_variable_name = "_#{name}"
          new_value_variable_name = "new_value"
          additional_setup_code = nil
          if block_given?
            additional_setup_code = yield(local_variable_name,
                                          new_value_variable_name)
          end
          module_eval("            def #{name}
              #{local_variable_name} = #{plural_name}.first
              #{local_variable_name} ? #{local_variable_name}.#{attribute} : nil
            end

            def #{name}=(#{new_value_variable_name})
              #{local_variable_name} =
                #{plural_name}.first || #{plural_name}.new_#{new_name}
              #{additional_setup_code}
              #{local_variable_name}.#{attribute} = #{new_value_variable_name}
            end
", __FILE__, __LINE__ + 1)
        end
            
def_csv_element(name, type=nil) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 160
        def def_csv_element(name, type=nil)
          def_other_element_without_accessor(name)
          attr_reader(name)
          converter = ""
          if type == :integer
            converter = "{|v| Integer(v)}"
          end
          module_eval("            def #{name}=(value)
              @#{name} = Utils::CSV.parse(value)#{converter}
            end
", __FILE__, __LINE__ + 1)
        end
            
def_other_element(name) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 143
def def_other_element(name)
  attr_accessor name
  def_other_element_without_accessor(name)
end
            
def_other_element_without_accessor(name) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 148
        def def_other_element_without_accessor(name)
          add_need_initialize_variable(name)
          add_other_element(name)
          module_eval("            def setup_#{name}(feed, current)
              if !@#{name}.nil? and current.respond_to?(:#{name}=)
                current.#{name} = @#{name}
              end
            end
", __FILE__, __LINE__ + 1)
        end
            
inherited(subclass) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 26
def inherited(subclass)
  subclass.const_set(:OTHER_ELEMENTS, [])
  subclass.const_set(:NEED_INITIALIZE_VARIABLES, [])
end
            
inherited_base() click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 22
def inherited_base
  ::RSS::Maker::Base
end
            
need_initialize_variables() click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 18
def need_initialize_variables
  inherited_array_reader("NEED_INITIALIZE_VARIABLES")
end
            
new(maker) click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 176
def initialize(maker)
  @maker = maker
  @default_values_are_set = false
  initialize_variables
end
            
other_elements() click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 15
def other_elements
  inherited_array_reader("OTHER_ELEMENTS")
end
            

Public Instance Methods

have_required_values?() click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 182
def have_required_values?
  not_set_required_variables.empty?
end
            
variable_is_set?() click to toggle source
 
               # File rss-0.2.9/lib/rss/maker/base.rb, line 186
def variable_is_set?
  variables.any? {|var| not __send__(var).nil?}
end