Module: Sequel::Plugins

Defined in:
lib/sequel/model/plugins.rb,
lib/sequel/plugins/list.rb,
lib/sequel/plugins/tree.rb,
lib/sequel/plugins/dirty.rb,
lib/sequel/plugins/touch.rb,
lib/sequel/plugins/pg_row.rb,
lib/sequel/plugins/schema.rb,
lib/sequel/plugins/caching.rb,
lib/sequel/plugins/scissors.rb,
lib/sequel/plugins/sharding.rb,
lib/sequel/plugins/rcte_tree.rb,
lib/sequel/plugins/eager_each.rb,
lib/sequel/plugins/subclasses.rb,
lib/sequel/plugins/timestamps.rb,
lib/sequel/plugins/composition.rb,
lib/sequel/plugins/active_model.rb,
lib/sequel/plugins/split_values.rb,
lib/sequel/plugins/static_cache.rb,
lib/sequel/plugins/table_select.rb,
lib/sequel/plugins/column_select.rb,
lib/sequel/plugins/serialization.rb,
lib/sequel/plugins/csv_serializer.rb,
lib/sequel/plugins/error_splitter.rb,
lib/sequel/plugins/force_encoding.rb,
lib/sequel/plugins/instance_hooks.rb,
lib/sequel/plugins/update_refresh.rb,
lib/sequel/plugins/xml_serializer.rb,
lib/sequel/plugins/association_pks.rb,
lib/sequel/plugins/boolean_readers.rb,
lib/sequel/plugins/defaults_setter.rb,
lib/sequel/plugins/json_serializer.rb,
lib/sequel/plugins/lazy_attributes.rb,
lib/sequel/plugins/string_stripper.rb,
lib/sequel/plugins/accessed_columns.rb,
lib/sequel/plugins/after_initialize.rb,
lib/sequel/plugins/auto_validations.rb,
lib/sequel/plugins/column_conflicts.rb,
lib/sequel/plugins/instance_filters.rb,
lib/sequel/plugins/inverted_subsets.rb,
lib/sequel/plugins/typecast_on_load.rb,
lib/sequel/plugins/unlimited_update.rb,
lib/sequel/plugins/update_or_create.rb,
lib/sequel/plugins/input_transformer.rb,
lib/sequel/plugins/many_through_many.rb,
lib/sequel/plugins/nested_attributes.rb,
lib/sequel/plugins/blacklist_security.rb,
lib/sequel/plugins/hook_class_methods.rb,
lib/sequel/plugins/optimistic_locking.rb,
lib/sequel/plugins/update_primary_key.rb,
lib/sequel/plugins/validation_helpers.rb,
lib/sequel/plugins/association_proxies.rb,
lib/sequel/plugins/pg_typecast_on_load.rb,
lib/sequel/plugins/prepared_statements.rb,
lib/sequel/plugins/skip_create_refresh.rb,
lib/sequel/plugins/validate_associated.rb,
lib/sequel/plugins/dataset_associations.rb,
lib/sequel/plugins/singular_table_names.rb,
lib/sequel/plugins/delay_add_association.rb,
lib/sequel/plugins/many_to_one_pk_lookup.rb,
lib/sequel/plugins/pg_array_associations.rb,
lib/sequel/plugins/constraint_validations.rb,
lib/sequel/plugins/modification_detection.rb,
lib/sequel/plugins/tactical_eager_loading.rb,
lib/sequel/plugins/class_table_inheritance.rb,
lib/sequel/plugins/insert_returning_select.rb,
lib/sequel/plugins/association_dependencies.rb,
lib/sequel/plugins/mssql_optimistic_locking.rb,
lib/sequel/plugins/prepared_statements_safe.rb,
lib/sequel/plugins/single_table_inheritance.rb,
lib/sequel/plugins/validation_class_methods.rb,
lib/sequel/plugins/association_autoreloading.rb,
lib/sequel/plugins/prepared_statements_with_pk.rb,
lib/sequel/plugins/prepared_statements_associations.rb,
lib/sequel/plugins/serialization_modification_detection.rb

Overview

Empty namespace that plugins should use to store themselves, so they can be loaded via Model.plugin.

Plugins should be modules with one of the following conditions:

  • A singleton method named apply, which takes a model, additional arguments, and an optional block. This is called the first time the plugin is loaded for this model (unless it was already loaded by an ancestor class), before including/extending any modules, with the arguments and block provided to the call to Model.plugin.

  • A module inside the plugin module named ClassMethods, which will extend the model class.

  • A module inside the plugin module named InstanceMethods, which will be included in the model class.

  • A module inside the plugin module named DatasetMethods, which will extend the model’s dataset.

  • A singleton method named configure, which takes a model, additional arguments, and an optional block. This is called every time the Model.plugin method is called, after including/extending any modules.

Defined Under Namespace

Modules: AccessedColumns, ActiveModel, AfterInitialize, AssociationAutoreloading, AssociationDependencies, AssociationPks, AssociationProxies, AutoValidations, BlacklistSecurity, BooleanReaders, Caching, ClassTableInheritance, ColumnConflicts, ColumnSelect, Composition, ConstraintValidations, CsvSerializer, DatasetAssociations, DefaultsSetter, DelayAddAssociation, Dirty, EagerEach, ErrorSplitter, ForceEncoding, HookClassMethods, InputTransformer, InsertReturningSelect, InstanceFilters, InstanceHooks, InvertedSubsets, JsonSerializer, LazyAttributes, List, ManyThroughMany, ManyToOnePkLookup, ModificationDetection, MssqlOptimisticLocking, NestedAttributes, OptimisticLocking, PgArrayAssociations, PgRow, PgTypecastOnLoad, PreparedStatements, PreparedStatementsAssociations, PreparedStatementsSafe, PreparedStatementsWithPk, RcteTree, Schema, Scissors, Serialization, SerializationModificationDetection, Sharding, SingleTableInheritance, SingularTableNames, SkipCreateRefresh, SplitValues, StaticCache, StringStripper, Subclasses, TableSelect, TacticalEagerLoading, Timestamps, Touch, Tree, TypecastOnLoad, UnlimitedUpdate, UpdateOrCreate, UpdatePrimaryKey, UpdateRefresh, ValidateAssociated, ValidationClassMethods, ValidationHelpers, XmlSerializer

Class Method Summary collapse

Class Method Details

.after_set_dataset(mod, meth) ⇒ Object

Add method to mod that overrides set_dataset to call the method afterward.



41
42
43
44
45
46
47
# File 'lib/sequel/model/plugins.rb', line 41

def self.after_set_dataset(mod, meth)
  mod.send(:define_method, :set_dataset) do |*a|
    r = super(*a)
    send(meth)
    r
  end
end

.def_dataset_methods(mod, meths) ⇒ Object

In the given module mod, define methods that are call the same method on the dataset. This is designed for plugins to define dataset methods inside ClassMethods that call the implementations in DatasetMethods.



26
27
28
29
30
# File 'lib/sequel/model/plugins.rb', line 26

def self.def_dataset_methods(mod, meths)
  Array(meths).each do |meth|
    mod.class_eval("def #{meth}(*args, &block); dataset.#{meth}(*args, &block) end", __FILE__, __LINE__)
  end
end

.inherited_instance_variables(mod, hash) ⇒ Object

Add method to mod that overrides inherited_instance_variables to include the values in this hash.



34
35
36
37
38
# File 'lib/sequel/model/plugins.rb', line 34

def self.inherited_instance_variables(mod, hash)
  mod.send(:define_method, :inherited_instance_variables) do ||
    super().merge!(hash)
  end
end