Sha256: 50041c08067f6ce07de35facebb2dbeecbb7fea5bcd3dbddd65a09338274e9c7

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# encoding: utf-8
require 'active_support/inflector'

module Dslable
  class Dsl
    attr_accessor :_gem_name
    attr_accessor :_gem_desc
    attr_accessor :_bin_name
    attr_accessor :fields

    def initialize
      @fields = []
    end

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

    def gem_desc(_gem_desc)
      raise InvalidDslError.new("gem_desc not allow nil") if _gem_desc.nil?
      raise InvalidDslError.new("gem_desc not allow empty") if _gem_desc.empty?
      @_gem_desc = _gem_desc
    end

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

    def field(_field_name)
      raise InvalidDslError.new("field name not allow nil") if _field_name.nil?
      raise InvalidDslError.new("field name not allow empty") if _field_name.empty?
      _field = Field.new
      _field.field_name _field_name
      yield _field
      @fields << _field
    end

    def camelized_gem_name
      _gem_name.camelize
    end
  end

  class InvalidDslError < StandardError;end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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