Sha256: 53a82557fc6c3498941f2a42d6228791e52e38bb62dc3c5b46ac9a5579158898

Contents?: true

Size: 760 Bytes

Versions: 2

Compression:

Stored size: 760 Bytes

Contents

# frozen_string_literal: true

module Danica
  module DSL
    class Builder
      attr_reader :method, :claz, :base

      def initialize(method, claz = nil, base = nil)
        @method = method
        @claz = claz
        @base = base
      end

      def build
        DSL.register_class(method, clazz)
      end

      private

      def clazz
        @clazz ||= build_clazz
      end

      def build_clazz
        return clazz_from_method unless claz
        return claz if claz.is_a? Class

        clazz_from_string
      end

      def clazz_from_method
        [base.to_s, method.to_s.camelize].compact.join('::').constantize
      end

      def clazz_from_string
        [base, claz.to_s].compact.join('::').constantize
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danica-2.7.7 lib/danica/dsl/builder.rb
danica-2.7.6 lib/danica/dsl/builder.rb