Sha256: 817548ab048c4d4f126fbd7a3307d14f2684de1c1157de52873a6dcab8b4ea14

Contents?: true

Size: 838 Bytes

Versions: 21

Compression:

Stored size: 838 Bytes

Contents

module TarvitHelpers
  module NonSharedAccessors
    require 'active_support'
    extend ActiveSupport::Concern

    module ClassMethods
      def non_shared_cattr_accessor(*keys)
        keys.each do |key|
          raise "#{key} is not a Symbol" unless key.is_a?(Symbol)
          method=<<METHOD
            def #{key}
              get_non_shared(:#{ key })
            end

            def #{key}=(v)
              set_non_shared(:#{ key },v)
            end
METHOD
          eval(method)
        end
      end

      private

      def global_shared_store
        @global_shared_values ||= {}
      end

      def own_store
        global_shared_store[self] ||= {}
      end

      def get_non_shared(key)
        own_store[key]
      end

      def set_non_shared(key,value)
        own_store[key]=value
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
tarvit-helpers-0.0.23 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.22 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.21 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.20 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.19 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.18 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.17 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.16 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.15 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.14 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.13 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.12 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.11 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.10 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.9 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.8 lib/tarvit-helpers/modules/non_shared_accessors.rb
tarvit-helpers-0.0.6 lib/modules/non_shared_accessors.rb
tarvit-helpers-0.0.5 lib/modules/non_shared_accessors.rb
tarvit-helpers-0.0.4 lib/modules/non_shared_accessors.rb
tarvit-helpers-0.0.3 lib/modules/non_shared_accessors.rb