Sha256: f060e63f0620a15670c49efdc5e57627fe73d2c1e186e675baf6717c627ee469

Contents?: true

Size: 1017 Bytes

Versions: 10

Compression:

Stored size: 1017 Bytes

Contents

module Exlibris
  module Aleph
    # 
    # Write passed in arguments to instance attributes
    # 
    module WriteAttributes

      def initialize *args
        # Just call super w/o any args for now.  Eventually, we'll want to check the arity and adjust.
        # self.class.superclass.instance_method(:initialize).arity.eql? self.class.instance_method(:initialize).arity
        super
        write_attributes args.last unless args.last.nil?
      end

      def write_attributes attributes
        attributes.each do |attribute, value|
          write_attribute attribute, value
        end
      end

      def attributize symbol
        symbol.id2name.sub(/=$/, "").to_sym
      end
      protected :attributize

      def write_attribute attribute, value
        attribute_writer = writify attribute
        send attribute_writer, value if respond_to? attribute_writer
      end
      private :write_attribute

      def writify key
        "#{key}=".to_sym
      end
      private :writify
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
exlibris-aleph-1.1.0 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.8 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.7 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.6 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.5 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.4 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.3 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.2 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.1 lib/exlibris/aleph/write_attributes.rb
exlibris-aleph-1.0.0 lib/exlibris/aleph/write_attributes.rb