Sha256: 11ac357d77c09cc6b8d761457a61cd7e2c1aaade82e5e1c77bcf5da110a86dc3
Contents?: true
Size: 1.41 KB
Versions: 1
Compression:
Stored size: 1.41 KB
Contents
require "goa_model_gen" require "erb" require "yaml" require "pathname" require "active_support/core_ext/string" module GoaModelGen class Config ATTRIBUTES = %w[ go_package swagger_yaml gofmt_disabled model_dir store_dir converter_dir validator_path ].freeze attr_accessor *ATTRIBUTES def fulfill @go_package ||= default_go_package @swagger_yaml ||= "./swagger/swagger.yaml" @gofmt_disabled ||= false @model_dir ||= "./model" @store_dir ||= "./stores" @converter_dir ||= "./converters" @validator_path ||= "gopkg.in/go-playground/validator.v9" self end def load_from(path) erb = ERB.new(File.read(path), nil, "-") erb.filename = path config = YAML.load(erb.result, path) ATTRIBUTES.each do |name| instance_variable_set("@#{name}", config[name].presence) end fulfill end def to_hash ATTRIBUTES.each_with_object({}) do |name, d| d[name] = send(name) end end def to_yaml YAML.dump(to_hash) end def default_go_package return default_go_package! rescue nil end def default_go_package! gopath = ENV['GOPATH'] || '' raise "$GOPATH not found" if gopath.empty? return Pathname.new(Dir.pwd).relative_path_from(Pathname.new(File.join(gopath, "src"))).to_s end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
goa_model_gen-0.7.0 | lib/goa_model_gen/config.rb |