Sha256: eb7ca3d31731c7fab82f517629f02824e0bc9449a9c1c70cf3c326206517dd4e
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true require 'active_support' module HermesMessengerOfTheGods module EndpointBuilder def self.build(name, klass, *args) klass.new(name, *args) end module Helpers extend ActiveSupport::Concern included do def endpoint @endpoint ||= self.class.build_endpoint end end class_methods do def is_valid_endpoint_creation_method(method) method.to_s =~ /(\w+)_endpoint\z/ && begin "HermesMessengerOfTheGods::Endpoints::#{::Regexp.last_match(1).camelize}".constantize rescue StandardError nil end end def method_missing(method, *args, &blk) klass = is_valid_endpoint_creation_method(method) if klass { klass: klass, args: args } else super(method, *args, &blk) end end def build_endpoint EndpointBuilder.build('default', endpoint[:klass], *endpoint[:args]) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems