Sha256: 584db24ff41ca1a76e98bb4385edf479fe01b9ca135324fe7c08bb57d22d32ce

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

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

3 entries across 3 versions & 1 rubygems

Version Path
danica-2.7.4 lib/danica/dsl/builder.rb
danica-2.7.3 lib/danica/dsl/builder.rb
danica-2.7.2 lib/danica/dsl/builder.rb