Sha256: f69d79a132612d198374336f51c86d4de2ab510a5a03a4945ff2f0e2916bada0

Contents?: true

Size: 807 Bytes

Versions: 2

Compression:

Stored size: 807 Bytes

Contents

module Dirty
  module Attributes

    def self.included(base)
      base.extend ClassMethods
      base.send :include, InstanceMethods
      base.send :include, MethodMap
    end

    module ClassMethods
      def attrs(*names)
        @attrs = names.collect(&:to_s)
      end

      def attributes
        @attrs
      end
    end

    module InstanceMethods
      attr_reader :attributes

      def initialize
        @attributes = DirtyIndifferentHashy.new({}, true, self.class.attributes).tap do |hashy|
          dirty_map! hashy
          clean_up!
        end
      end

      def attributes=(other)
        attributes.replace other
      rescue IndexError => e
        e.message.match /"(.*)"/
        raise NoMethodError, "undefined method `#{$1}=' for #{self.inspect}"
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dirty_hashy-0.2.1 lib/dirty/attributes.rb
dirty_hashy-0.2.0 lib/dirty/attributes.rb