Skip to content

Commit

Permalink
Update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 8, 2025
1 parent ab4ac00 commit e70096e
Show file tree
Hide file tree
Showing 45 changed files with 212 additions and 528 deletions.
44 changes: 11 additions & 33 deletions core/lib/rom/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ def [](value = Undefined)
# @return [TrueClass,FalseClass]
#
# @api public
def primary_key?
meta[:primary_key].equal?(true)
end
def primary_key? = meta[:primary_key].equal?(true)

# Return true if this attribute type is a foreign key
#
Expand All @@ -106,9 +104,7 @@ def primary_key?
# @return [TrueClass,FalseClass]
#
# @api public
def foreign_key?
meta[:foreign_key].equal?(true)
end
def foreign_key? = meta[:foreign_key].equal?(true)

# Return true if this attribute has a configured alias
#
Expand All @@ -129,9 +125,7 @@ def foreign_key?
# @return [TrueClass,FalseClass]
#
# @api public
def aliased?
!self.alias.nil?
end
def aliased? = !self.alias.nil?

# Return source relation of this attribute type
#
Expand All @@ -152,9 +146,7 @@ def aliased?
# @return [Symbol, Relation::Name]
#
# @api public
def source
meta[:source]
end
def source = meta[:source]

# Return target relation of this attribute type
#
Expand All @@ -175,9 +167,7 @@ def source
# @return [NilClass, Symbol, Relation::Name]
#
# @api public
def target
meta[:target]
end
def target = meta[:target]

# Return tuple key
#
Expand All @@ -200,9 +190,7 @@ def target
# @return [Symbol]
#
# @api public
def key
self.alias || name
end
def key = self.alias || name

# Return new attribute type with provided alias
#
Expand Down Expand Up @@ -230,9 +218,7 @@ def key
# @return [Attribute]
#
# @api public
def aliased(name)
with(alias: name)
end
def aliased(name) = with(alias: name)
alias_method :as, :aliased

# Return new attribute type with an alias using provided prefix
Expand Down Expand Up @@ -277,9 +263,7 @@ def prefixed(prefix = source.dataset)
# correctly in places like auto-mapping.
#
# @api public
def wrapped?
meta[:wrapped].equal?(true)
end
def wrapped? = meta[:wrapped].equal?(true)

# Return attribute type wrapped for the specified relation name
#
Expand Down Expand Up @@ -338,27 +322,21 @@ def eql?(other)
# @return [TrueClass, FalseClass]
#
# @api private
def read?
!meta[:read].nil?
end
def read? = !meta[:read].nil?

# Return read type
#
# @return [Dry::Types::Type]
#
# @api private
def to_read_type
read? ? meta[:read] : type
end
def to_read_type = read? ? meta[:read] : type

# Return write type
#
# @return [Dry::Types::Type]
#
# @api private
def to_write_type
type
end
def to_write_type = type

# Return nullable attribute
#
Expand Down
24 changes: 6 additions & 18 deletions core/lib/rom/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,18 @@ def initialize(cache, namespace)
end

# @api private
def [](key)
cache[[namespace, key].hash]
end
def [](key) = cache[[namespace, key].hash]

# @api private
def fetch_or_store(*args, &)
cache.fetch_or_store([namespace, args].hash, &)
end

# @api private
def size
cache.size
end
def size = cache.size

# @api private
def inspect
%(#<#{self.class} size=#{size}>)
end
def inspect = %(#<#{self.class} size=#{size}>)
end

# @api private
Expand All @@ -50,19 +44,13 @@ def initialize
@namespaced = {}
end

def [](key)
cache[key]
end
def [](key) = objects[key]

# @api private
def fetch_or_store(*args, &)
objects.fetch_or_store(args.hash, &)
end
def fetch_or_store(*args, &) = objects.fetch_or_store(args.hash, &)

# @api private
def size
objects.size
end
def size = objects.size

# @api private
def namespaced(namespace)
Expand Down
44 changes: 11 additions & 33 deletions core/lib/rom/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,14 @@ def curry(*args)
# @return [Command::Graph]
#
# @api public
def combine(*others)
Graph.new(self, others)
end
def combine(*others) = Graph.new(self, others)

# Check if this command is curried
#
# @return [TrueClass, FalseClass]
#
# @api public
def curried?
!curry_args.empty?
end
def curried? = !curry_args.empty?

# Return a new command with appended before hooks
#
Expand Down Expand Up @@ -367,18 +363,14 @@ def after(*hooks)
# @return [Array]
#
# @api public
def before_hooks
options[:before]
end
def before_hooks = options[:before]

# List of after hooks
#
# @return [Array]
#
# @api public
def after_hooks
options[:after]
end
def after_hooks = options[:after]

# Return a new command with other source relation
#
Expand All @@ -394,54 +386,42 @@ def new(new_relation)
# Check if this command has any hooks
#
# @api private
def hooks?
!before_hooks.empty? || !after_hooks.empty?
end
def hooks? = !before_hooks.empty? || !after_hooks.empty?

# Check if this command is lazy
#
# @return [false]
#
# @api private
def lazy?
false
end
def lazy? = false

# Check if this command is a graph
#
# @return [false]
#
# @api private
def graph?
false
end
def graph? = false

# Check if this command returns a single tuple
#
# @return [TrueClass,FalseClass]
#
# @api private
def one?
result.equal?(:one)
end
def one? = result.equal?(:one)

# Check if this command returns many tuples
#
# @return [TrueClass,FalseClass]
#
# @api private
def many?
result.equal?(:many)
end
def many? = result.equal?(:many)

# Check if this command is restrictible through relation
#
# @return [TrueClass,FalseClass]
#
# @api private
def restrictible?
self.class.restrictable.equal?(true)
end
def restrictible? = self.class.restrictable.equal?(true)

# Yields tuples for insertion or return an enumerator
#
Expand All @@ -463,9 +443,7 @@ def map_input_tuples(tuples, &mapper)
# @return [Class]
#
# @api private
def composite_class
Command::Composite
end
def composite_class = Command::Composite

# Apply provided hooks
#
Expand Down
8 changes: 2 additions & 6 deletions core/lib/rom/command_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ def visit_relation(node, parent_relation = nil)
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity

# @api private
def visit_attribute(*_args)
nil
end
def visit_attribute(*_args) = nil

# Build a command object for a specific relation
#
Expand Down Expand Up @@ -228,9 +226,7 @@ def register_command(rel_name, type, rel_meta, parent_relation = nil)
# @return [Symbol]
#
# @api private
def result
meta.fetch(:result, :one)
end
def result = meta.fetch(:result, :one)

# Sets up `associates` plugin for a given command class and relation
#
Expand Down
12 changes: 3 additions & 9 deletions core/lib/rom/command_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ def initialize(command, root = Inflector.singularize(command.name.relation).to_s
end

# @api private
def call(input)
command.call(root => input)
end
def call(input) = command.call(root => input)

# @api private
def >>(other)
self.class.new(command >> other)
end
def >>(other) = self.class.new(command >> other)

# @api private
def restrictible?
command.restrictible?
end
def restrictible? = command.restrictible?
end
end
8 changes: 2 additions & 6 deletions core/lib/rom/command_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class CommandRegistry < Registry
option :compiler, optional: true

# @api private
def self.element_not_found_error
CommandNotFoundError
end
def self.element_not_found_error = CommandNotFoundError

# Return a command from the registry
#
Expand Down Expand Up @@ -86,9 +84,7 @@ def [](*args)
# @return [CommandRegistry]
#
# @api public
def map_with(mapper_name)
with(mapper: mappers[mapper_name])
end
def map_with(mapper_name) = with(mapper: mappers[mapper_name])

# @api private
def set_compiler(compiler) # rubocop:disable Naming/AccessorMethodName
Expand Down
Loading

0 comments on commit e70096e

Please sign in to comment.