Sha256: 7cd52c6a4c85471dacb62d1faf80cf7eeba6293267dcc43cf45b6853383afe06

Contents?: true

Size: 987 Bytes

Versions: 11

Compression:

Stored size: 987 Bytes

Contents

$:.unshift File.dirname __FILE__
require 'model_xml/generator'

module ModelXML

  def self.included base

    base.instance_eval do

      def model_xml *args, &block

        @model_xml_generator ||= ModelXML::Generator.new
        if block_given?
          @model_xml_generator.add_field_set(*args, &block)
        else
          @model_xml_generator.add_field_set *args
        end

      end

      # this is probably only ever required for testing
      def model_xml_reset!
        @model_xml_generator = ModelXML::Generator.new
      end

      def model_xml_generator
        @model_xml_generator
      end
    end

  end

  def to_xml options={}

    # if no generator is defined, pass straight through to the parent to_xml method, which may or may not exist
    if generator = self.class.model_xml_generator
      generator.generate_xml! self, options
    else
      super options
    end
  end

end

ActiveRecord::Base.send :include, ModelXML if defined?(ActiveRecord::Base)

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
model_xml-1.0.14 lib/model_xml.rb
model_xml-1.0.13 lib/model_xml.rb
model_xml-1.0.12 lib/model_xml.rb
model_xml-1.0.11 lib/model_xml.rb
model_xml-1.0.9 lib/model_xml.rb
model_xml-1.0.5 lib/model_xml.rb
model_xml-1.0.4 lib/model_xml.rb
model_xml-1.0.3 lib/model_xml.rb
model_xml-1.0.2 lib/model_xml.rb
model_xml-1.0.1 lib/model_xml.rb
model_xml-1.0.0 lib/model_xml.rb