Module: Tarantool::ClassAttribute

Included in:
BaseRecord
Defined in:
lib/tarantool/core-ext.rb

Instance Method Summary collapse

Instance Method Details

#t_class_attribute(*attrs) ⇒ Object

spinoff from ActiveSupport class attribute



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tarantool/core-ext.rb', line 6

def t_class_attribute(*attrs)
  attrs.each do |name|
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def self.#{name}() nil end
      def self.#{name}?() !!#{name} end

      def self.#{name}=(val)
        singleton_class.class_eval do
          begin
            if method_defined?(:"#{name}") || private_method_defined?(:"#{name}")
              remove_method(:#{name})
            end
          rescue NameError
          end
          define_method(:#{name}) { val }
        end
        val
      end
    RUBY
  end
end