Sha256: bdeed4c7a7deef2b83bd4f04e2e574578eac089ba053da1afac63a3894da8ed3

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

module Dslable
  class Args
    attr_accessor :_desc
    attr_accessor :_args_name
    attr_accessor :_klass
    attr_accessor :_required
    attr_accessor :_default_value

    def initialize
      @_desc = ""
      @_required = false
    end

    def desc(_desc)
      return if _desc.nil?
      @_desc = _desc
    end

    def args_name(_args_name)
      raise InvalidArgsError.new("args_name not allow nil") if _args_name.nil?
      raise InvalidArgsError.new("args_name not allow empty") if _args_name.empty?
      raise InvalidArgsError.new("args_name allow /^[a-z0-9_]+$/") unless _args_name =~ /^[a-z0-9_]+$/
      @_args_name = _args_name
    end

    def klass(_klass)
      raise InvalidArgsError.new("klass not allow nil") if _klass.nil?
      raise InvalidArgsError.new("klass only allow String, Array and Hash") unless [String, Hash, Array].include? (_klass)
      @_klass = _klass
    end

    def required
      @_required = true
    end

    def default_value(_default_value)
      @_default_value = _default_value
    end
  end

  class InvalidArgsError < StandardError;end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dslable-0.0.2 lib/dslable_args.rb
dslable-0.0.1 lib/dslable_args.rb