Sha256: b14e97f3af4b516286fa08dfda1c6af282391d672bea91c956e076beae19ba8a

Contents?: true

Size: 990 Bytes

Versions: 21

Compression:

Stored size: 990 Bytes

Contents

# The meta_def extension is designed for backwards compatibility
# with older Sequel code that uses the meta_def method on
# Database, Dataset, and Model classes and/or instances.  It is
# not recommended for usage in new code.  To load this extension:
#
#   Sequel.extension :meta_def

module Sequel
  # Contains meta_def method for adding methods to objects via blocks.
  # Only recommended for backwards compatibility with existing code.
  module Metaprogramming
    # Define a method with the given name and block body on the receiver.
    #
    #   ds = DB[:items]
    #   ds.meta_def(:x){42}
    #   ds.x # => 42
    def meta_def(name, &block)
      (class << self; self end).send(:define_method, name, &block)
    end
  end

  Database.extend Metaprogramming
  Database.send(:include, Metaprogramming)
  Dataset.extend Metaprogramming
  Dataset.send(:include, Metaprogramming)
  if defined?(Model)
    Model.extend Metaprogramming
    Model.send(:include, Metaprogramming)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
sequel-4.13.0 lib/sequel/extensions/meta_def.rb
sequel-4.12.0 lib/sequel/extensions/meta_def.rb
sequel-4.11.0 lib/sequel/extensions/meta_def.rb
sequel-4.10.0 lib/sequel/extensions/meta_def.rb
sequel-4.9.0 lib/sequel/extensions/meta_def.rb
sequel-4.8.0 lib/sequel/extensions/meta_def.rb
sequel-4.7.0 lib/sequel/extensions/meta_def.rb
sequel-4.6.0 lib/sequel/extensions/meta_def.rb
sequel-4.5.0 lib/sequel/extensions/meta_def.rb
sequel-4.4.0 lib/sequel/extensions/meta_def.rb
sequel-4.3.0 lib/sequel/extensions/meta_def.rb
sequel-4.2.0 lib/sequel/extensions/meta_def.rb
sequel-4.1.1 lib/sequel/extensions/meta_def.rb
sequel-4.1.0 lib/sequel/extensions/meta_def.rb
sequel-4.0.0 lib/sequel/extensions/meta_def.rb
sequel-3.48.0 lib/sequel/extensions/meta_def.rb
sequel-3.47.0 lib/sequel/extensions/meta_def.rb
sequel-3.46.0 lib/sequel/extensions/meta_def.rb
sequel-3.45.0 lib/sequel/extensions/meta_def.rb
sequel-3.44.0 lib/sequel/extensions/meta_def.rb