Sha256: af73795453d89bcb1985e9a7e75c8ab216d72338e6e1f1a3d60d8c29e854dcd1

Contents?: true

Size: 922 Bytes

Versions: 8

Compression:

Stored size: 922 Bytes

Contents

module SAXMachine
  def self.configure(clazz)
    extended_clazz = Class.new(clazz)
    extended_clazz.send(:include, SAXMachine)

    # override create_attr to create attributes on the original class
    def extended_clazz.create_attr real_name
      superclass.send(:attr_reader, real_name) unless superclass.method_defined?(real_name)
      superclass.send(:attr_writer, real_name) unless superclass.method_defined?("#{real_name}=")
    end

    yield(extended_clazz)

    clazz.extend LightWeightSaxMachine
    clazz.sax_config = extended_clazz.sax_config

    (class << clazz;self;end).send(:define_method, :parse) do |xml_text|
      extended_clazz.parse(xml_text)
    end
  end

  module LightWeightSaxMachine
    attr_writer :sax_config

    def sax_config
      @sax_config ||= SAXConfig.new
    end

    def inherited(subclass)
      subclass.sax_config.send(:initialize_copy, self.sax_config)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sax-machine-1.2.0 lib/sax-machine/sax_configure.rb
sax-machine-1.1.1 lib/sax-machine/sax_configure.rb
sax-machine-1.1.0 lib/sax-machine/sax_configure.rb
sax-machine-1.0.3 lib/sax-machine/sax_configure.rb
sax-machine-1.0.2 lib/sax-machine/sax_configure.rb
sax-machine-1.0.1 lib/sax-machine/sax_configure.rb
sax-machine-1.0.0 lib/sax-machine/sax_configure.rb
sax-machine-0.3.0 lib/sax-machine/sax_configure.rb