Sha256: 49f231a7c4ac3cb0f77bb875828fbe4e5027e21f372cf67e92727ac54bdbeff8

Contents?: true

Size: 819 Bytes

Versions: 31

Compression:

Stored size: 819 Bytes

Contents

# This extends Class to be able to use +cattr_accessor+ if active_support is not being used.
class Class
  unless respond_to?(:cattr_reader)
    def cattr_reader(sym)
      class_eval(<<-EOS, __FILE__, __LINE__ + 1)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end

        def self.#{sym}
          @@#{sym}
        end

        def #{sym}
          @@#{sym}
        end
      EOS
    end

    def cattr_writer(sym)
      class_eval(<<-EOS, __FILE__, __LINE__ + 1)
        unless defined? @@#{sym}
          @@#{sym} = nil
        end

        def self.#{sym}=(obj)
          @@#{sym} = obj
        end

        def #{sym}=(obj)
          @@#{sym} = obj
        end
      EOS
    end

    def cattr_accessor(*syms, &blk)
      cattr_reader(*syms)
      cattr_writer(*syms, &blk)
    end
  end
end

Version data entries

31 entries across 31 versions & 4 rubygems

Version Path
databasedotcom_emp-1.3.1 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom_cloudfuji-1.3.1 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.3.1 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-ejholmes-1.3.5 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-ejholmes-1.3.4 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-ejholmes-1.3.3 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-ejholmes-1.3.2 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.3.0 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.7 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.6 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.5 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.4 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.3 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.2 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.1 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.2.0 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.1.7 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.1.6 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.1.5 lib/databasedotcom/core_extensions/class_extensions.rb
databasedotcom-1.1.4 lib/databasedotcom/core_extensions/class_extensions.rb