Sha256: 9927c5bafe589061c31e5cb203a6dcb693d5ccab75eb1ad964f7987a1660605d

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

module ASIR
  # !SLIDE
  # Addtional Data
  #
  # Support additional data attached to any object.
  module AdditionalData
    def _additional_data; @additional_data; end
    def additional_data
      @additional_data || EMPTY_HASH
    end
    def additional_data!
      @additional_data ||= { }
    end
    def additional_data= x
      @additional_data = x
    end
    def [] key
      @additional_data && @additional_data[key]
    end
    def []= key, value
      (@additional_data ||= { })[key] = value
    end

    def self.included target
      super
      target.extend(ModuleMethods)
    end

    module ModuleMethods
      # Provide a getter method that delegates to addtional_data[...].
      def addr_getter *names
        names.each do | name |
          name = name.to_sym
          define_method(name) { | | addtional_data[name] }
        end
      end

      # Provide getter and setter methods that delegate to addtional_data[...].
      def addr_accessor *names
        addr_getter *names
        names.each do | name |
          name = name.to_sym
          define_method(:"#{name}=") { | v | addtional_data[name] = v }
        end
      end
    end

  end
  # !SLIDE END
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
asir-1.1.12 lib/asir/additional_data.rb
asir-1.1.11 lib/asir/additional_data.rb
asir-1.1.10 lib/asir/additional_data.rb
asir-1.1.9 lib/asir/additional_data.rb
asir-1.1.8 lib/asir/additional_data.rb
asir-1.1.7 lib/asir/additional_data.rb
asir-1.1.6 lib/asir/additional_data.rb
asir-1.1.5 lib/asir/additional_data.rb
asir-1.1.4 lib/asir/additional_data.rb
asir-1.1.3 lib/asir/additional_data.rb
asir-1.1.2 lib/asir/additional_data.rb
asir-1.1.1 lib/asir/additional_data.rb
asir-1.1.0 lib/asir/additional_data.rb
asir-1.0.8 lib/asir/additional_data.rb