Sha256: d4c3b6942509322204b32a522a5299489f690a408875c5216f956c422fe837d5

Contents?: true

Size: 923 Bytes

Versions: 28

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/acts_as_immutable/base_accessor'
require 'eac_ruby_utils/patches/class/common_constructor'

module EacRubyUtils
  module ActsAsImmutable
    class CommonAccessor < ::EacRubyUtils::ActsAsImmutable::BaseAccessor
      def apply(klass)
        accessor = self
        klass.send(:define_method, name) do |*args|
          case args.count
          when 0 then next accessor.immutable_value_get_filtered(self)
          when 1 then next accessor.immutable_value_set_filtered(self, args.first)
          else
            raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
          end
        end
      end

      def immutable_value_get(object)
        object.send(:immutable_values_get)[name]
      end

      def immutable_value_set(object, value)
        duplicate_object(object) { |_old_value| value }
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
eac_ruby_utils-0.124.0 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.97.2 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.123.0 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.121.0 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.120.0 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/acts_as_immutable/common_accessor.rb