Sha256: 5fddb815469bd1f0ea5807da43d40681dd968df19c8a4eb162d2b4560bcc4a5a

Contents?: true

Size: 759 Bytes

Versions: 1

Compression:

Stored size: 759 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

1 entries across 1 versions & 1 rubygems

Version Path
danica-2.7.5 lib/danica/dsl/builder.rb