~ubuntu-branches/ubuntu/vivid/ruby-sequel/vivid

« back to all changes in this revision

Viewing changes to lib/sequel/model/plugins.rb

  • Committer: Package Import Robot
  • Author(s): Dmitry Borodaenko, Dmitry Borodaenko, Cédric Boutillier
  • Date: 2013-08-10 18:38:17 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20130810183817-iqanz804j32i5myi
Tags: 4.1.1-1
[ Dmitry Borodaenko ]
* New upstream release.
* Standards-Version upgraded to 3.9.4 (no changes).
* Added Build-Depend on ruby-sqlite3.

[ Cédric Boutillier ]
* debian/control: remove obsolete DM-Upload-Allowed flag.
* use canonical URI in Vcs-* fields.
* debian/copyright: use DEP5 copyright-format/1.0 official URL for Format
  field.
* Update debian/watch. Thanks Bart Martens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
  #   already loaded by an ancestor class), before including/extending
10
10
  #   any modules, with the arguments
11
11
  #   and block provided to the call to Model.plugin.
 
12
  # * A module inside the plugin module named ClassMethods,
 
13
  #   which will extend the model class.
12
14
  # * A module inside the plugin module named InstanceMethods,
13
15
  #   which will be included in the model class.
14
 
  # * A module inside the plugin module named ClassMethods,
15
 
  #   which will extend the model class.
16
16
  # * A module inside the plugin module named DatasetMethods,
17
17
  #   which will extend the model's dataset.
18
18
  # * A singleton method named configure, which takes a model, 
20
20
  #   every time the Model.plugin method is called, after including/extending
21
21
  #   any modules.
22
22
  module Plugins
 
23
    # In the given module +mod+, define methods that are call the same method
 
24
    # on the dataset.  This is designed for plugins to define dataset methods
 
25
    # inside ClassMethods that call the implementations in DatasetMethods.
 
26
    def self.def_dataset_methods(mod, meths)
 
27
      Array(meths).each do |meth|
 
28
        mod.class_eval("def #{meth}(*args, &block); dataset.#{meth}(*args, &block) end", __FILE__, __LINE__)
 
29
      end
 
30
    end
 
31
 
 
32
    # Add method to +mod+ that overrides inherited_instance_variables to include the
 
33
    # values in this hash.
 
34
    def self.inherited_instance_variables(mod, hash)
 
35
      mod.send(:define_method, :inherited_instance_variables) do ||
 
36
        super().merge!(hash)
 
37
      end
 
38
    end
 
39
 
 
40
    # Add method to +mod+ that overrides set_dataset to call the method afterward.
 
41
    def self.after_set_dataset(mod, meth)
 
42
      mod.send(:define_method, :set_dataset) do |*a|
 
43
        r = super(*a)
 
44
        send(meth)
 
45
        r
 
46
      end
 
47
    end
23
48
  end
24
49
end