This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'concurrent/atomic/atomic_reference' | |
module Dry | |
module Types | |
# Atomic types denote references in advance to target ones due to help achieve a cross-reference. | |
# | |
# @example | |
# module T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'dry/core/cache' | |
require 'dry/core/constants' | |
require 'dry/container' | |
require 'dry/types' | |
require 'dry/types/tuple' # → https://github.com/estum/dry-types-tuple | |
# External instance-level accessor wrapper in inverted control: | |
# once defined with an accessor name it could be used with different objects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The refinement module helps to inspect a composed source of meta-generated methods, | |
# which were defined via Module#module_eval or Module#class_eval methods | |
# in strings with interpolations. | |
# | |
# Unless this refinement is using, looking up for an actual source of such | |
# kind of method will result with a raw string literal with no interpolation applied. | |
# | |
# It's monkey patch the Module#module_eval and Module#class_eval methods to | |
# write a source with applied interpolation into a temporary file per method owner and | |
# substitutes an evaluted located path & lineno for the string. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Dry | |
module Types | |
# @example | |
# Types::ServiceArgs = Types.Tuple( | |
# Types::Params::Symbol, # --- positional types | |
# [Types::Params::Integer | Types::Coercible::String] # --- [type for the rest items] | |
# ) | |
# Types::ServiceArgs[['thumb', '300', '300', 'sample']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @example Simple | |
# Osascript.new(<<~SCPT.freeze).() | |
# activate application "Finder" | |
# SCPT | |
# | |
# @example JSC with args | |
# # The script takes 2 arguments: directory path & image path | |
# # to set a folder icon to the given directory. | |
# script = Osascript.new(<<-JS.freeze, lang: 'JavaScript') | |
# ObjC.import("Cocoa"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'dry/core/equalizer' | |
module Dry | |
# @api public | |
def self.Comparator(*keys, **options) | |
if keys.size == 0 && options.size > 0 | |
keys << options.dup | |
options.replace(keys[0].extract!(:immutable, :inspect, :compare)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mixin with namespaced macro to inherit view prefixes from several modules. | |
# | |
# @example Imagine legacy controllers… | |
# module V1 | |
# class BaseController < ActionController::Metal; end | |
# # => _prefixes: ['api/v1/base'] | |
# | |
# class PostsController < BaseController; end | |
# # => _prefixes: ['api/v1/base', 'api/v1/posts'] | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'concurrent/map' | |
# = Expand Constant Namespace | |
# | |
# To expand namespace in classic way it have to be included or extended | |
# to a target module or class. | |
# | |
# This module provides +expand_constant+ method to expand external module namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'concurrent/map' | |
# {include:file:concurrent/map.rb} | |
class Map < Concurrent::Map | |
HashBuilder = proc do |hsh, default = nil, default_proc = nil| | |
hsh = ::Hash[hsh] | |
if !default.nil? | |
hsh.default = default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module Dry | |
module Initializer | |
# @example | |
# class CreateOrder | |
# extend Dry::Initializer | |
# | |
# # Params and options | |
# param :customer, model: 'Customer' # use either a name |
NewerOlder