Sha256: 7c090510a55d65c2d17b58773941bf08269850fcd6cdf1da85e7909cc45e7812

Contents?: true

Size: 822 Bytes

Versions: 3

Compression:

Stored size: 822 Bytes

Contents

module Chozo
  # @author Jamie Winsor <jamie@vialstudios.com>
  class CleanRoomBase
    class << self
      # Create a DSL writer function that will assign the a given value
      # to the real object of this clean room.
      #
      # @param [Symbol] attribute
      def dsl_attr_writer(attribute)
        class_eval do
          define_method(attribute) do |value|
            set_attribute(attribute, value)
          end
        end
      end
    end

    def initialize(real_model)
      @real_model = real_model
      @noisy      = real_model.class.noisy_clean_room
    end

    private

      attr_reader :noisy
      attr_reader :real_model

      def set_attribute(name, value)
        real_model.send("#{name}=", value)
      end

      def method_missing(*args)
        noisy ? super : nil
      end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chozo-0.6.1 lib/chozo/clean_room_base.rb
chozo-0.6.0 lib/chozo/clean_room_base.rb
chozo-0.5.0 lib/chozo/clean_room_base.rb