code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def instrument(&) notifications.instrument( self.class.adapter, name: name.relation, **notification_payload(self), & ) end
Execute a block using instrumentation @api public
instrument
ruby
rom-rb/rom
core/lib/rom/plugins/relation/instrumentation.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/plugins/relation/instrumentation.rb
MIT
def timestamps(*names) options = plugin_options(:timestamps) options[:attributes] = names unless names.empty? self end
Sets non-default timestamp attributes @example schema do use :timestamps timestamps :create_on, :updated_on end @api public
timestamps
ruby
rom-rb/rom
core/lib/rom/plugins/schema/timestamps.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/plugins/schema/timestamps.rb
MIT
def to_transproc compose(t(:identity)) do |ops| combined = header.combined ops << t(:combine, combined.map(&method(:combined_args))) if combined.any? ops << header.preprocessed.map { |attr| visit(attr, true) } ops << t(:map_array, row_proc) if row_proc ops << header.postprocessed.map { |attr| visit(attr, true) } end end
Coerce mapper header to a transproc data mapping function @return [Transproc::Function] @api private rubocop:disable Metrics/AbcSize
to_transproc
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit(attribute, *args) type = attribute.class.name.split('::').last.downcase send("visit_#{type}", attribute, *args) end
Visit an attribute from the header This forwards to a specialized visitor based on the attribute type @param [Header::Attribute] attribute @param [Array] args Allows to send `preprocess: true` @api private
visit
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_attribute(attribute) coercer = attribute.meta[:coercer] if attribute.union? compose do |ops| ops << t(:inject_union_value, attribute.name, attribute.key, coercer) ops << t(:reject_keys, attribute.key) unless header.copy_keys end elsif coercer t(:map_value, attribute.name, t(:bind, mapper, coercer)) elsif attribute.typed? t(:map_value, attribute.name, t(:"to_#{attribute.type}")) end end
Visit plain attribute It will call block transformation if it's used If it's a typed attribute a coercion transformation is added @param [Header::Attribute] attribute @api private rubocop:disable Metrics/AbcSize
visit_attribute
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_hash(attribute) with_row_proc(attribute) do |row_proc| t(:map_value, attribute.name, row_proc) end end
rubocop:enable Metrics/AbcSize Visit hash attribute @param [Header::Attribute::Hash] attribute @api private
visit_hash
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_array(attribute) with_row_proc(attribute) do |row_proc| t(:map_value, attribute.name, t(:map_array, row_proc)) end end
Visit array attribute @param [Header::Attribute::Array] attribute @api private
visit_array
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_wrap(attribute) name = attribute.name keys = attribute.tuple_keys compose do |ops| ops << t(:nest, name, keys) ops << visit_hash(attribute) end end
Visit wrapped hash attribute :nest transformation is added to handle wrapping @param [Header::Attribute::Wrap] attribute @api private
visit_wrap
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_unwrap(attribute) name = attribute.name keys = attribute.pop_keys compose do |ops| ops << visit_hash(attribute) ops << t(:unwrap, name, keys) end end
Visit unwrap attribute :unwrap transformation is added to handle unwrapping @param [Header::Attributes::Unwrap] attribute @api private
visit_unwrap
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_group(attribute, preprocess = false) # rubocop:disable Style/OptionalBooleanParameter if preprocess name = attribute.name header = attribute.header keys = attribute.tuple_keys others = header.preprocessed compose do |ops| ops << t(:group, name, keys) ops << t(:map_array, t(:map_value, name, t(:filter_empty))) ops << others.map { |attr| t(:map_array, t(:map_value, name, visit(attr, true))) } end else visit_array(attribute) end end
Visit group hash attribute :group transformation is added to handle grouping during preprocessing. Otherwise we simply use array visitor for the attribute. @param [Header::Attribute::Group] attribute @param [Boolean] preprocess true if we are building a relation preprocessing function that is applied to the whole relation @api private
visit_group
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_ungroup(attribute, preprocess = false) # rubocop:disable Style/OptionalBooleanParameter if preprocess name = attribute.name header = attribute.header keys = attribute.pop_keys others = header.postprocessed compose do |ops| ops << others.map { |attr| t(:map_array, t(:map_value, name, visit(attr, true))) } ops << t(:ungroup, name, keys) end else visit_array(attribute) end end
Visit ungroup attribute :ungroup transforation is added to handle ungrouping during preprocessing. Otherwise we simply use array visitor for the attribute. @param [Header::Attribute::Ungroup] attribute @param [Boolean] preprocess true if we are building a relation preprocessing function that is applied to the whole relation @api private
visit_ungroup
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_fold(attribute, preprocess = false) # rubocop:disable Style/OptionalBooleanParameter if preprocess name = attribute.name keys = attribute.tuple_keys compose do |ops| ops << t(:group, name, keys) ops << t(:map_array, t(:map_value, name, t(:filter_empty))) ops << t(:map_array, t(:fold, name, keys.first)) end end end
Visit fold hash attribute :fold transformation is added to handle folding during preprocessing. @param [Header::Attribute::Fold] attribute @param [Boolean] preprocess true if we are building a relation preprocessing function that is applied to the whole relation @api private
visit_fold
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_unfold(attribute, preprocess = false) # rubocop:disable Style/OptionalBooleanParameter return unless preprocess name = attribute.name header = attribute.header keys = attribute.pop_keys key = keys.first others = header.postprocessed compose do |ops| ops << others.map { |attr| t(:map_array, t(:map_value, name, visit(attr, true))) } ops << t(:map_array, t(:map_value, name, t(:insert_key, key))) ops << t(:map_array, t(:reject_keys, [key] - [name])) ops << t(:ungroup, name, [key]) end end
Visit unfold hash attribute :unfold transformation is added to handle unfolding during preprocessing. @param [Header::Attribute::Unfold] attribute @param [Boolean] preprocess true if we are building a relation preprocessing function that is applied to the whole relation @api private rubocop:disable Metrics/AbcSize
visit_unfold
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def visit_exclude(attribute) t(:reject_keys, [attribute.name]) end
rubocop:enable Metrics/AbcSize Visit excluded attribute @param [Header::Attribute::Exclude] attribute @api private
visit_exclude
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def initialize_row_proc @row_proc = compose { |ops| alias_handler = header.copy_keys ? :copy_keys : :rename_keys process_header_keys(ops) ops << t(alias_handler, mapping) if header.aliased? ops << header.map { |attr| visit(attr) } ops << t(:constructor_inject, model) if model } end
Build row_proc This transproc function is applied to each row in a dataset @api private
initialize_row_proc
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def with_row_proc(attribute) row_proc = row_proc_from(attribute) yield(row_proc) if row_proc end
Yield row proc for a given attribute if any @param [Header::Attribute] attribute @api private
with_row_proc
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def row_proc_from(attribute) new(mapper, attribute.header).row_proc end
Build a row_proc from a given attribute This is used by embedded attribute visitors @api private
row_proc_from
ruby
rom-rb/rom
core/lib/rom/processor/transproc.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/processor/transproc.rb
MIT
def dataset(&block) if defined?(@dataset) @dataset else @dataset = block || DEFAULT_DATASET_PROC end end
Set or get custom dataset block This block will be evaluated when a relation is instantiated and registered in a relation registry. @example class Users < ROM::Relation[:memory] dataset { sort_by(:id) } end @api public
dataset
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def schema(dataset = nil, as: nil, infer: false, &) if defined?(@schema) && !block_given? && !infer @schema elsif block_given? || infer raise MissingSchemaClassError, self unless schema_class ds_name = dataset || schema_opts.fetch(:dataset, default_name.dataset) relation = as || schema_opts.fetch(:relation, ds_name) raise InvalidRelationName, relation if invalid_relation_name?(relation) @relation_name = Name[relation, ds_name] @schema_proc = proc do |*args, &inner_block| schema_dsl.new( relation_name, schema_class: schema_class, attr_class: schema_attr_class, inferrer: schema_inferrer.with(enabled: infer), & ).call(*args, &inner_block) end end end
Specify canonical schema for a relation With a schema defined commands will set up a type-safe input handler automatically @example class Users < ROM::Relation[:sql] schema do attribute :id, Types::Serial attribute :name, Types::String end end # access schema from a finalized relation users.schema @return [Schema] @param [Symbol] dataset An optional dataset name @param [Boolean] infer Whether to do an automatic schema inferring @api public rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
schema
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def set_schema!(schema) @schema = schema end
rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity Assign a schema to a relation class @param [Schema] schema @return [Schema] @api private
set_schema!
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def relation_name raise MissingSchemaError, self unless defined?(@relation_name) @relation_name end
@!attribute [r] relation_name @return [Name] Qualified relation name
relation_name
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def view(*args, &block) if args.size == 1 && block.arity.positive? raise ArgumentError, 'schema attribute names must be provided as the second argument' end name, new_schema_fn, relation_block = if args.size == 1 ViewDSL.new(*args, schema, &block).call else [*args, block] end schemas[name] = if args.size == 2 -> _ { schema.project(*args[1]) } else new_schema_fn end if relation_block.arity.positive? auto_curry_guard do define_method(name, &relation_block) auto_curry(name) do schemas[name].(self) end end else define_method(name) do schemas[name].(instance_exec(&relation_block)) end end name end
Define a relation view with a specific schema This method should only be used in cases where a given adapter doesn't support automatic schema projection at run-time. **It's not needed in rom-sql** @overload view(name, schema, &block) @example View with the canonical schema class Users < ROM::Relation[:sql] view(:listing, schema) do order(:name) end end @example View with a projected schema class Users < ROM::Relation[:sql] view(:listing, schema.project(:id, :name)) do order(:name) end end @overload view(name, &block) @example View with the canonical schema and arguments class Users < ROM::Relation[:sql] view(:by_name) do |name| where(name: name) end end @example View with projected schema and arguments class Users < ROM::Relation[:sql] view(:by_name) do schema { project(:id, :name) } relation { |name| where(name: name) } end end @example View with a schema extended with foreign attributes class Users < ROM::Relation[:sql] view(:index) do schema { append(relations[:tasks][:title]) } relation { |name| where(name: name) } end end @return [Symbol] view method name @api public rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
view
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def forward(*methods) methods.each do |method| class_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{method}(...) # def super_query(...) new(dataset.__send__(:#{method}, ...)) # new(dataset.__send__(:super_query, ...)) end # end RUBY end end
rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity Dynamically define a method that will forward to the dataset and wrap response in the relation itself @example class SomeAdapterRelation < ROM::Relation forward :super_query end @api public
forward
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def use(plugin, **options) ROM.plugin_registry[:relation].fetch(plugin, adapter).apply_to(self, **options) end
Include a registered plugin in this relation class @param [Symbol] plugin @param [Hash] options @option options [Symbol] :adapter (:default) first adapter to check for plugin @api public
use
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def mapper_registry(opts = EMPTY_HASH) adapter_ns = ROM.adapters[adapter] compiler = if adapter_ns&.const_defined?(:MapperCompiler) adapter_ns.const_get(:MapperCompiler) else MapperCompiler end MapperRegistry.new({}, compiler: compiler.new(**opts), **opts) end
Build default mapper registry @return [MapperRegistry] @api private
mapper_registry
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def default_name Name[Inflector.underscore(name).tr('/', '_').to_sym] end
Return default relation name used in schemas @return [Name] @api private
default_name
ruby
rom-rb/rom
core/lib/rom/relation/class_interface.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/class_interface.rb
MIT
def combine_with(*others) self.class.new(root, nodes + others) end
Combine this graph with more nodes @param [Array<Relation>] others A list of relations @return [Graph] @api public
combine_with
ruby
rom-rb/rom
core/lib/rom/relation/combined.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/combined.rb
MIT
def combine(*args) self.class.new(root, nodes + root.combine(*args).nodes) end
Combine with other relations @see Relation#combine @return [Combined] @api public
combine
ruby
rom-rb/rom
core/lib/rom/relation/combined.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/combined.rb
MIT
def call(*args) left = root.with(auto_map: false, auto_struct: false).call(*args) right = if left.empty? nodes.map { |node| Loaded.new(node, EMPTY_ARRAY) } else nodes.map { |node| node.call(left) } end if auto_map? Loaded.new(self, mapper.([left, right])) else Loaded.new(self, [left, right]) end end
Materialize combined relation @return [Loaded] @api public
call
ruby
rom-rb/rom
core/lib/rom/relation/combined.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/combined.rb
MIT
def node(name, &) if name.is_a?(Symbol) && !nodes.map { |n| n.name.key }.include?(name) raise ArgumentError, "#{name.inspect} is not a valid aggregate node name" end new_nodes = nodes.map { |node| case name when Symbol name == node.name.key ? yield(node) : node when Hash other, *rest = name.flatten(1) if other == node.name.key nodes.detect { |n| n.name.key == other }.node(*rest, &) else node end else node end } with_nodes(new_nodes) end
Return a new combined relation with adjusted node returned from a block @example with a node identifier combine(:tasks).node(:tasks) { |tasks| tasks.prioritized } @example with a nested path combine(tasks: :tags).node(tasks: :tags) { |tags| tags.where(name: 'red') } @param [Symbol] name The node relation name @yieldparam [Relation] relation The relation node @yieldreturn [Relation] The new relation node @return [Relation] @api public rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
node
ruby
rom-rb/rom
core/lib/rom/relation/combined.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/combined.rb
MIT
def command(type, mapper: nil, use: EMPTY_ARRAY, plugins_options: EMPTY_HASH, **opts) base_command = if commands.key?(type) commands[type] else commands[type, adapter, to_ast, use, plugins_options, opts] end command = if mapper base_command >> mappers[mapper] elsif auto_map? base_command >> self.mapper else base_command end if command.restrictible? command.new(self) else command end end
Return a command for the relation This method can either return an existing custom command identified by `type` param, or generate a command dynamically based on relation AST. @example build a simple :create command users.command(:create) @example build a command which returns multiple results users.command(:create, result: many) @example build a command which uses a specific plugin users.command(:create, use: :timestamps) @example build a command which sends results through a custom mapper users.command(:create, mapper: :my_mapper_identifier) @example return an existing custom command users.command(:my_custom_command_identifier) @param type [Symbol] The command type (:create, :update or :delete) @param opts [Hash] Additional options @option opts [Symbol] :mapper (nil) An optional mapper applied to the command result @option opts [Array<Symbol>] :use ([]) A list of command plugins @option opts [Symbol] :result (:one) Set how many results the command should return. Can be `:one` or `:many` @return [ROM::Command] @api public
command
ruby
rom-rb/rom
core/lib/rom/relation/commands.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/commands.rb
MIT
def call(*args) relation = left.call(*args) response = right.call(relation) if response.is_a?(Loaded) response else relation.new(response) end end
Call the pipeline by passing results from left to right Optional args are passed to the left object @return [Loaded] @api public
call
ruby
rom-rb/rom
core/lib/rom/relation/composite.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/composite.rb
MIT
def call(*args) all_args = curry_args + args if all_args.empty? raise ArgumentError, "curried #{relation.class}##{view} relation was called without any arguments" end if args.empty? self elsif arity == all_args.size Loaded.new(relation.__send__(view, *all_args)) else __new__(relation, curry_args: all_args) end end
Load relation if args match the arity @return [Loaded,Curried] @api public
call
ruby
rom-rb/rom
core/lib/rom/relation/curried.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/curried.rb
MIT
def to_a raise( ArgumentError, "#{relation.class}##{view} arity is #{arity} " \ "(#{curry_args.size} args given)" ) end
Relations are coercible to an array but a curried relation cannot be coerced When something tries to do this, an exception will be raised @raise ArgumentError @api public
to_a
ruby
rom-rb/rom
core/lib/rom/relation/curried.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/curried.rb
MIT
def map_with(*names, **opts) names.reduce(self.class.new(root.with(opts), nodes)) { |a, e| a >> mappers[e] } end
Map graph tuples via custom mappers @see Relation#map_with @return [Relation::Composite] @api public
map_with
ruby
rom-rb/rom
core/lib/rom/relation/graph.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/graph.rb
MIT
def map_to(klass) self.class.new(root.map_to(klass), nodes) end
Map graph tuples to custom objects @see Relation#map_to @return [Graph] @api public
map_to
ruby
rom-rb/rom
core/lib/rom/relation/graph.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/graph.rb
MIT
def each(&) return to_enum unless block_given? collection.each(&) end
Yield relation tuples @yield [Hash] @api public
each
ruby
rom-rb/rom
core/lib/rom/relation/loaded.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/loaded.rb
MIT
def one if collection.count > 1 raise( TupleCountMismatchError, 'The relation consists of more than one tuple' ) else collection.first end end
Returns a single tuple from the relation if there is one. @raise [ROM::TupleCountMismatchError] if the relation contains more than one tuple @api public
one
ruby
rom-rb/rom
core/lib/rom/relation/loaded.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/loaded.rb
MIT
def one! one || raise( TupleCountMismatchError, 'The relation does not contain any tuples' ) end
Like [one], but additionally raises an error if the relation is empty. @raise [ROM::TupleCountMismatchError] if the relation does not contain exactly one tuple @api public
one!
ruby
rom-rb/rom
core/lib/rom/relation/loaded.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/loaded.rb
MIT
def each(&) return to_enum unless block_given? to_a.each(&) end
Yield relation tuples @yield [Hash,Object] @api public
each
ruby
rom-rb/rom
core/lib/rom/relation/materializable.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/materializable.rb
MIT
def to_s if aliased? "#{relation} on #{dataset} as #{aliaz}" elsif relation == dataset relation.to_s else "#{relation} on #{dataset}" end end
Return relation name @return [String] @api private
to_s
ruby
rom-rb/rom
core/lib/rom/relation/name.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/name.rb
MIT
def schema(&) @new_schema = -> relations { @schema.with(relations: relations).instance_exec(&) } end
Define a schema for a relation view @return [Proc] @see Relation::ClassInterface.view @api public
schema
ruby
rom-rb/rom
core/lib/rom/relation/view_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/view_dsl.rb
MIT
def relation(&) @relation_block = proc(&) end
Define a relation block for a relation view @return [Proc] @see Relation::ClassInterface.view @api public
relation
ruby
rom-rb/rom
core/lib/rom/relation/view_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/view_dsl.rb
MIT
def wrap(*args) self.class.new(root, nodes + root.wrap(*args).nodes) end
Wrap more relations @see Relation#wrap @return [Wrap] @api public
wrap
ruby
rom-rb/rom
core/lib/rom/relation/wrap.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/wrap.rb
MIT
def call(*args) if auto_map? Loaded.new(self, mapper.(relation.with(auto_map: false, auto_struct: false))) else Loaded.new(self, relation.(*args)) end end
Materialize a wrap @see Relation#call @return [Loaded] @api public
call
ruby
rom-rb/rom
core/lib/rom/relation/wrap.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/relation/wrap.rb
MIT
def one_to_many(target, **options) if options[:through] many_to_many(target, **options) else add(::ROM::Associations::Definitions::OneToMany.new(source, target, **options)) end end
Establish a one-to-many association @example using relation identifier has_many :tasks @example setting custom foreign key name has_many :tasks, foreign_key: :assignee_id @example with a :through option # this establishes many-to-many association has_many :tasks, through: :users_tasks @example using a custom view which overrides default one has_many :posts, view: :published, override: true @example using aliased association with a custom view has_many :posts, as: :published_posts, view: :published @example using custom target relation has_many :user_posts, relation: :posts @example using custom target relation and an alias has_many :user_posts, relation: :posts, as: :published, view: :published @param [Symbol] target The target relation identifier @param [Hash] options A hash with additional options @return [Associations::OneToMany] @see #many_to_many @api public
one_to_many
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def one_to_one(target, **options) if options[:through] one_to_one_through(target, **options) else add(::ROM::Associations::Definitions::OneToOne.new(source, target, **options)) end end
Establish a one-to-one association @example using relation identifier one_to_one :addresses, as: :address @example with an intermediate join relation one_to_one :tasks, as: :priority_task, through: :assignments @param [Symbol] target The target relation identifier @param [Hash] options A hash with additional options @return [Associations::OneToOne] @see #belongs_to @api public
one_to_one
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def one_to_one_through(target, **options) add(::ROM::Associations::Definitions::OneToOneThrough.new(source, target, **options)) end
Establish a one-to-one association with a :through option @example one_to_one_through :users, as: :author, through: :users_posts @return [Associations::OneToOneThrough] @api public
one_to_one_through
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def many_to_many(target, **options) add(::ROM::Associations::Definitions::ManyToMany.new(source, target, **options)) end
Establish a many-to-many association @example using relation identifier many_to_many :tasks, through: :users_tasks @param [Symbol] target The target relation identifier @param [Hash] options A hash with additional options @return [Associations::ManyToMany] @see #one_to_many @api public
many_to_many
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def many_to_one(target, **options) add(::ROM::Associations::Definitions::ManyToOne.new(source, target, **options)) end
Establish a many-to-one association @example using relation identifier many_to_one :users, as: :author @param [Symbol] target The target relation identifier @param [Hash] options A hash with additional options @return [Associations::ManyToOne] @see #one_to_many @api public
many_to_one
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def belongs_to(target, **options) many_to_one(dataset_name(target), as: target, **options) end
Shortcut for many_to_one which sets alias automatically @example with an alias (relation identifier is inferred via pluralization) belongs_to :user @example with an explicit alias belongs_to :users, as: :author @see #many_to_one @return [Associations::ManyToOne] @api public
belongs_to
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def has_one(target, **options) one_to_one(dataset_name(target), as: target, **options) end
Shortcut for one_to_one which sets alias automatically @example with an alias (relation identifier is inferred via pluralization) has_one :address @example with an explicit alias and a custom view has_one :posts, as: :priority_post, view: :prioritized @see #one_to_one @return [Associations::OneToOne] @api public
has_one
ruby
rom-rb/rom
core/lib/rom/schema/associations_dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/associations_dsl.rb
MIT
def attribute(name, type_or_options, options = EMPTY_HASH) if attributes.key?(name) ::Kernel.raise ::ROM::AttributeAlreadyDefinedError, "Attribute #{name.inspect} already defined" end attributes[name] = build_attribute_info(name, type_or_options, options) end
Defines a relation attribute with its type and options. When only options are given, type is left as nil. It makes sense when it is used alongside an schema inferrer, which will populate the type. @see Relation.schema @api public
attribute
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def associations(&) @associations_dsl = AssociationsDSL.new(relation, &) end
Define associations for a relation @example class Users < ROM::Relation[:sql] schema(infer: true) do associations do has_many :tasks has_many :posts has_many :posts, as: :priority_posts, view: :prioritized belongs_to :account end end end class Posts < ROM::Relation[:sql] schema(infer: true) do associations do belongs_to :users, as: :author end end view(:prioritized) do where { priority <= 3 } end end @return [AssociationDSL] @api public
associations
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def build_attribute_info(name, type_or_options, options = EMPTY_HASH) type, options = if type_or_options.is_a?(::Hash) [nil, type_or_options] else [build_type(type_or_options, options), options] end Schema.build_attribute_info( type, **options, name: name ) end
Builds a representation of the information needed to create an attribute. It returns a hash with `:type` and `:options` keys. @return [Hash] @see [Schema.build_attribute_info] @api private
build_attribute_info
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def build_type(type, options = EMPTY_HASH) if options[:read] type.meta(source: relation, read: options[:read]) elsif type.optional? && type.meta[:read] type.meta(source: relation, read: type.meta[:read].optional) else type.meta(source: relation) end.meta(Attribute::META_OPTIONS.map { |opt| [opt, options[opt]] if options.key?(opt) }.compact.to_h) end
Builds a type instance from base type and meta options @return [Dry::Types::Type] Type instance @api private rubocop:disable Metrics/AbcSize
build_type
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def primary_key(*names) names.each do |name| attributes[name][:type] = attributes[name][:type].meta(primary_key: true) end self end
rubocop:enable Metrics/AbcSize Specify which key(s) should be the primary key @api public
primary_key
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def use(plugin_name, options = ::ROM::EMPTY_HASH) plugin = ::ROM.plugin_registry[:schema].fetch(plugin_name, adapter) app_plugin(plugin, options) end
Enables for the schema @param [Symbol] plugin_name Plugin name @param [Hash] options Plugin options @api public
use
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def opts opts = { attributes: attributes.values, inferrer: inferrer, attr_class: attr_class } if associations_dsl { **opts, associations: associations_dsl.call } else opts end end
Return schema opts @return [Hash] @api private
opts
ruby
rom-rb/rom
core/lib/rom/schema/dsl.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/dsl.rb
MIT
def merge_attributes(defined, inferred) type_lookup = lambda do |attrs, name| attrs.find { |a| a.name == name }.type end defined_with_type, defined_names = defined.each_with_object([[], []]) do |attr, (attrs, names)| attrs << if attr.type.nil? attr.class.new( type_lookup.(inferred, attr.name), **attr.options ) else attr end names << attr.name end defined_with_type + inferred.reject do |attr| defined_names.include?(attr.name) end end
@api private rubocop:disable Metrics/AbcSize
merge_attributes
ruby
rom-rb/rom
core/lib/rom/schema/inferrer.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/schema/inferrer.rb
MIT
def load_entities(entity) Dir[globs[entity]].map do |file| require file klass_name = case namespace when String AutoRegistrationStrategies::CustomNamespace.new( namespace: namespace, file: file, directory: directory ).call when TrueClass AutoRegistrationStrategies::WithNamespace.new( file: file, directory: directory ).call when FalseClass AutoRegistrationStrategies::NoNamespace.new( file: file, directory: directory, entity: component_dirs.fetch(entity) ).call end Inflector.constantize(klass_name) end end
Load given component files @api private
load_entities
ruby
rom-rb/rom
core/lib/rom/setup/auto_registration.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/auto_registration.rb
MIT
def run! mappers = load_mappers relations = load_relations(mappers) commands = load_commands(relations) container = Container.new(gateways, relations, mappers, commands) container.freeze container end
Run the finalization process This creates relations, mappers and commands @return [Container] @api private
run!
ruby
rom-rb/rom
core/lib/rom/setup/finalize.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize.rb
MIT
def load_relations(mappers) global_plugins = plugins.select { |p| p.type == :relation || p.type == :schema } FinalizeRelations.new( gateways, relation_classes, mappers: mappers, plugins: global_plugins, notifications: notifications ).run! end
Build entire relation registry from all known relation subclasses This includes both classes created via DSL and explicit definitions @api private
load_relations
ruby
rom-rb/rom
core/lib/rom/setup/finalize.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize.rb
MIT
def load_commands(relations) FinalizeCommands.new(relations, gateways, command_classes, notifications).run! end
Build entire command registries This includes both classes created via DSL and explicit definitions @api private
load_commands
ruby
rom-rb/rom
core/lib/rom/setup/finalize.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize.rb
MIT
def initialize(relations, gateways, command_classes, notifications) @relations = relations @gateways = gateways @command_classes = command_classes @notifications = notifications end
Build command registry hash for provided relations @param [RelationRegistry] relations registry @param [Hash] gateways @param [Array] command_classes a list of command subclasses @api private
initialize
ruby
rom-rb/rom
core/lib/rom/setup/finalize/finalize_commands.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize/finalize_commands.rb
MIT
def run! commands = @command_classes.map do |klass| relation = @relations[klass.relation] gateway = @gateways[relation.gateway] notifications.trigger( 'configuration.commands.class.before_build', command: klass, gateway: gateway, dataset: relation.dataset, adapter: relation.adapter ) klass.extend_for_relation(relation) if klass.restrictable klass.build(relation) end registry = Registry.new compiler = CommandCompiler.new(@gateways, @relations, registry, notifications) @relations.each do |(name, relation)| rel_commands = commands.select { |c| c.relation.name == relation.name } rel_commands.each do |command| identifier = command.class.register_as || command.class.default_name relation.commands.elements[identifier] = command end relation.commands.set_compiler(compiler) relation.commands.set_mappers(relation.mappers) registry.elements[name] = relation.commands end registry end
@return [Hash] @api private rubocop:disable Metrics/AbcSize, Metrics/MethodLength
run!
ruby
rom-rb/rom
core/lib/rom/setup/finalize/finalize_commands.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize/finalize_commands.rb
MIT
def initialize(gateways, relation_classes, notifications:, mappers: nil, plugins: EMPTY_ARRAY) @gateways = gateways @relation_classes = relation_classes @mappers = mappers @plugins = plugins @notifications = notifications end
Build relation registry of specified descendant classes This is used by the setup @param [Hash] gateways @param [Array] relation_classes a list of relation descendants @api private
initialize
ruby
rom-rb/rom
core/lib/rom/setup/finalize/finalize_relations.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize/finalize_relations.rb
MIT
def run! relation_registry = RelationRegistry.new do |registry, relations| registry_readers = RegistryReaders.new(relation_names) @relation_classes.each do |klass| unless klass.adapter raise MissingAdapterIdentifierError, "Relation class +#{klass}+ is missing the adapter identifier" end key = klass.relation_name.to_sym if registry.key?(key) raise RelationAlreadyDefinedError, "Relation with name #{key.inspect} registered more than once" end klass.use(:registry_reader, readers: registry_readers) notifications.trigger( 'configuration.relations.class.ready', relation: klass, adapter: klass.adapter ) relations[key] = build_relation(klass, registry) end registry.each_value do |relation| notifications.trigger( 'configuration.relations.object.registered', relation: relation, registry: registry ) end end notifications.trigger( 'configuration.relations.registry.created', registry: relation_registry ) relation_registry end
@return [Hash] @api private rubocop:disable Metrics/AbcSize, Metrics/MethodLength
run!
ruby
rom-rb/rom
core/lib/rom/setup/finalize/finalize_relations.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize/finalize_relations.rb
MIT
def build_relation(klass, registry) # TODO: raise a meaningful error here and add spec covering the case # where klass' gateway points to non-existant repo gateway = @gateways.fetch(klass.gateway) plugins = schema_plugins schema = klass.schema_proc.call do plugins.each { |plugin| app_plugin(plugin) } end klass.set_schema!(schema) if klass.schema.nil? notifications.trigger( 'configuration.relations.schema.allocated', schema: schema, gateway: gateway, registry: registry ) relation_plugins.each do |plugin| plugin.apply_to(klass) end notifications.trigger( 'configuration.relations.schema.set', schema: schema, relation: klass, registry: registry, adapter: klass.adapter ) rel_key = schema.name.to_sym dataset = gateway.dataset(schema.name.dataset).instance_exec(klass, &klass.dataset) notifications.trigger( 'configuration.relations.dataset.allocated', dataset: dataset, relation: klass, adapter: klass.adapter ) options = { __registry__: registry, mappers: mapper_registry(rel_key, klass), schema: schema, **plugin_options } klass.new(dataset, **options) end
rubocop:enable Metrics/AbcSize, Metrics/MethodLength @return [ROM::Relation] @api private rubocop:disable Metrics/MethodLength, Metrics/AbcSize
build_relation
ruby
rom-rb/rom
core/lib/rom/setup/finalize/finalize_relations.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize/finalize_relations.rb
MIT
def mapper_registry(rel_key, rel_class) registry = rel_class.mapper_registry(cache: @mappers.cache) if @mappers.key?(rel_key) registry.merge(@mappers[rel_key]) else registry end end
rubocop:enable Metrics/MethodLength, Metrics/AbcSize @api private
mapper_registry
ruby
rom-rb/rom
core/lib/rom/setup/finalize/finalize_relations.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/setup/finalize/finalize_relations.rb
MIT
def config @config ||= Config.new end
Return config instance @return [Config] @api private
config
ruby
rom-rb/rom
core/lib/rom/support/configurable.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/configurable.rb
MIT
def configure yield(config) self end
Yield config instance @return [self] @api public
configure
ruby
rom-rb/rom
core/lib/rom/support/configurable.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/configurable.rb
MIT
def subscribe(event_id, query = EMPTY_HASH, &block) listeners[event_id] << [block, query] self end
Subscribe to events. If the query parameter is provided, filters events by payload. @param [String] event_id The event key @param [Hash] query An optional event filter @yield [block] The callback @return [Object] self @api public
subscribe
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def trigger(event_id, payload = EMPTY_HASH) event = events[event_id] listeners[event.id].each do |(listener, query)| event.payload(payload).trigger(listener, query) end end
Trigger an event @param [String] event_id The event key @param [Hash] payload An optional payload @api public
trigger
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def initialize(id, payload = EMPTY_HASH) @id = id @payload = payload end
Initialize a new event @param [Symbol] id The event identifier @param [Hash] payload Optional payload @return [Event] @api private
initialize
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def payload(data = nil) if data self.class.new(id, @payload.merge(data)) else @payload end end
Get or set a payload @overload @return [Hash] payload @overload payload(data) @param [Hash] data A new payload @return [Event] A copy of the event with the provided payload @api public
payload
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def trigger(listener, query = EMPTY_HASH) listener.(self) if trigger?(query) end
Trigger the event @param [#call] listener @param [Hash] query @api private
trigger
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def register_event(id, info = EMPTY_HASH) Notifications.events[id] = Event.new(id, info) end
Register an event @param [String] id A unique event key @param [Hash] info @api public
register_event
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def subscribe(event_id, query = EMPTY_HASH, &block) Notifications.listeners[event_id] << [block, query] end
Subscribe to events @param [String] event_id The event key @param [Hash] query An optional event filter @return [Object] self @api public
subscribe
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def initialize(id, events: EMPTY_HASH, listeners: LISTENERS_HASH.dup) @id = id @listeners = listeners @events = events end
Initialize a new event bus @param [Symbol] id The bus identifier @param [Hash] events A hash with events @param [Hash] listeners A hash with listeners @api public
initialize
ruby
rom-rb/rom
core/lib/rom/support/notifications.rb
https://github.com/rom-rb/rom/blob/master/core/lib/rom/support/notifications.rb
MIT
def define_attribute(id, opts, meta = {}) type = define_type(id, **meta) ROM::Attribute.new(type, **opts) end
@todo Use this method consistently in all the test suite
define_attribute
ruby
rom-rb/rom
core/spec/support/schema.rb
https://github.com/rom-rb/rom/blob/master/core/spec/support/schema.rb
MIT
def initialize(*, **) super @relations = {} end
Initializes a new repository object @api private
initialize
ruby
rom-rb/rom
repository/lib/rom/repository.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository.rb
MIT
def inspect %(#<#{self.class} struct_namespace=#{struct_namespace} auto_struct=#{auto_struct}>) end
Return a string representation of a repository object @return [String] @api public
inspect
ruby
rom-rb/rom
repository/lib/rom/repository.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository.rb
MIT
def session session = Session.new(self) yield(session) transaction { session.commit! } end
Start a session for multiple changesets TODO: this is partly done, needs tweaks in changesets so that we can gather command results and return them in a nice way @!visibility private @api public
session
ruby
rom-rb/rom
repository/lib/rom/repository.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository.rb
MIT
def new(container = nil, root: Undefined, **options) container ||= options.fetch(:container) unless self < relation_reader include relation_reader.new( relations: container.relations.elements.keys, cache: container.cache, root: root ) end super(**options, container: container) end
Initialize a new repository object, establishing configured relation proxies from the passed container @overload new(container, **options) Initialize with container as leading parameter @param [ROM::Container] container Finalized rom container @param [Hash] options Repository options @option options [Module] :struct_namespace Custom struct namespace @option options [Boolean] :auto_struct Enable/Disable auto-struct mapping @overload new(**options) Inititalize with container as option @param [Hash] options Repository options @option options [ROM::Container] :container Finalized rom container @option options [Module] :struct_namespace Custom struct namespace @option options [Boolean] :auto_struct Enable/Disable auto-struct mapping @api public
new
ruby
rom-rb/rom
repository/lib/rom/repository/class_interface.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository/class_interface.rb
MIT
def inherited(klass) super return if self === Repository # rubocop:disable Style/CaseEquality klass.extend(::Dry::Core::Cache) klass.commands(*commands) end
Inherits configured relations and commands @api private
inherited
ruby
rom-rb/rom
repository/lib/rom/repository/class_interface.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository/class_interface.rb
MIT
def commands(*names, mapper: nil, use: nil, plugins_options: EMPTY_HASH, **opts) if names.any? || opts.any? @commands = names + opts.to_a @commands.each do |spec| type, *view = Array(spec).flatten if view.empty? define_command_method( type, mapper: mapper, use: use, plugins_options: plugins_options ) else define_restricted_command_method( type, view, mapper: mapper, use: use, plugins_options: plugins_options ) end end else @commands ||= [] end end
Defines command methods on a root repository @example class UserRepo < ROM::Repository[:users] commands :create, update: :by_pk, delete: :by_pk end # with custom command plugin class UserRepo < ROM::Repository[:users] commands :create, use: :my_command_plugin end # with custom mapper class UserRepo < ROM::Repository[:users] commands :create, mapper: :my_custom_mapper end @param [Array<Symbol>] names A list of command names @option :mapper [Symbol] An optional mapper identifier @option :use [Symbol] An optional command plugin identifier @return [Array<Symbol>] A list of defined command names @api public rubocop:disable Metrics/MethodLength
commands
ruby
rom-rb/rom
repository/lib/rom/repository/class_interface.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository/class_interface.rb
MIT
def use(plugin, **options) ROM.plugin_registry[:repository].fetch(plugin).apply_to(self, **options) end
rubocop:enable Metrics/MethodLength @api public
use
ruby
rom-rb/rom
repository/lib/rom/repository/class_interface.rb
https://github.com/rom-rb/rom/blob/master/repository/lib/rom/repository/class_interface.rb
MIT
def where(job_class_name: nil, queue_name: nil, worker_id: nil, recurring_task_id: nil, finished_at: nil) # Remove nil arguments to avoid overriding parameters when concatenating +where+ clauses arguments = { job_class_name: job_class_name, queue_name: queue_name&.to_s, worker_id: worker_id, recurring_task_id: recurring_task_id, finished_at: finished_at }.compact clone_with **arguments end
Returns a +ActiveJob::JobsRelation+ with the configured filtering options. === Options * <tt>:job_class_name</tt> - To only include the jobs of a given class. Depending on the configured queue adapter, this will perform the filtering in memory, which could introduce performance concerns for large sets of jobs. * <tt>:queue_name</tt> - To only include the jobs in the provided queue. * <tt>:worker_id</tt> - To only include the jobs processed by the provided worker. * <tt>:recurring_task_id</tt> - To only include the jobs corresponding to runs of a recurring task. * <tt>:finished_at</tt> - (Range) To only include the jobs finished between the provided range
where
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def offset(offset) clone_with offset_value: offset end
Sets an offset for the jobs-fetching query. The first position is 0.
offset
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def limit(limit) clone_with limit_value: limit end
Sets the max number of jobs to fetch in the query.
limit
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def count if loaded? || filtering_needed? to_a.length else query_count end end
Returns the number of jobs in the relation. When filtering jobs, if the adapter doesn't support the filter(s) directly, this will load all the jobs in memory to filter them.
count
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def retry_all ensure_failed_status queue_adapter.retry_all_jobs(self) nil end
Retry all the jobs in the queue. This operation is only valid for sets of failed jobs. It will raise an error +ActiveJob::Errors::InvalidOperation+ otherwise.
retry_all
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def retry_job(job) ensure_failed_status queue_adapter.retry_job(job, self) end
Retry the provided job. This operation is only valid for sets of failed jobs. It will raise an error +ActiveJob::Errors::InvalidOperation+ otherwise.
retry_job
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def discard_all queue_adapter.discard_all_jobs(self) nil end
Discard all the jobs in the relation.
discard_all
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def dispatch_job(job) raise ActiveJob::Errors::InvalidOperation, "This operation can only be performed on blocked or scheduled jobs, but this job is #{job.status}" unless job.blocked? || job.scheduled? queue_adapter.dispatch_job(job, self) end
Dispatch the provided job. This operation is only valid for blocked or scheduled jobs. It will raise an error +ActiveJob::Errors::InvalidOperation+ otherwise.
dispatch_job
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def find_by_id(job_id) queue_adapter.find_job(job_id, self) end
Find a job by id. Returns nil when not found.
find_by_id
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def find_by_id!(job_id) queue_adapter.find_job(job_id, self) or raise ActiveJob::Errors::JobNotFoundError.new(job_id, self) end
Find a job by id. Raises +ActiveJob::Errors::JobNotFoundError+ when not found.
find_by_id!
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def filter(jobs) jobs.filter { |job| satisfy_filter?(job) } end
Filtering for not natively supported filters is performed in memory
filter
ruby
rails/mission_control-jobs
lib/active_job/jobs_relation.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/jobs_relation.rb
MIT
def jobs ActiveJob::JobsRelation.new(queue_adapter: queue_adapter).pending.where(queue_name: name) end
Return an +ActiveJob::JobsRelation+ with the pending jobs in the queue.
jobs
ruby
rails/mission_control-jobs
lib/active_job/queue.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/active_job/queue.rb
MIT