Sha256: 5de53d947f14bc0dde6e991eddedbdb4a7b4bd2adc262fe46e09c46e80c3b743

Contents?: true

Size: 1019 Bytes

Versions: 25

Compression:

Stored size: 1019 Bytes

Contents

module Exlibris
  module Primo
    # 
    # 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

25 entries across 25 versions & 1 rubygems

Version Path
exlibris-primo-2.1.1 lib/exlibris/primo/write_attributes.rb
exlibris-primo-2.1.0 lib/exlibris/primo/write_attributes.rb
exlibris-primo-2.0.0 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.9 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.8 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.7 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.6 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.5 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.4 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.3 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.2 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.1 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.1.0 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.11 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.10 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.9 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.8 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.7 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.6 lib/exlibris/primo/write_attributes.rb
exlibris-primo-1.0.5 lib/exlibris/primo/write_attributes.rb