Class: GoonModelGen::Config
- Inherits:
-
Object
- Object
- GoonModelGen::Config
- Defined in:
- lib/goon_model_gen/config.rb
Constant Summary collapse
- ATTRIBUTES =
%w[ gofmt_disabled base_package_path model_dir model_package_path validation_dir validation_package_path store_dir store_package_path converter_dir converter_package_path goa_gen_dir goa_gen_package_path structs_gen_dir structs_json_path validator_package_path version_comment package_alias_map ].freeze
Instance Method Summary collapse
- #default_go_package ⇒ Object
- #default_go_package! ⇒ Object
- #fulfill ⇒ Object
- #join_paths(path1, path2) ⇒ Object
- #load_from(path) ⇒ Object
- #to_hash ⇒ Object
- #to_yaml ⇒ Object
Instance Method Details
#default_go_package ⇒ Object
79 80 81 82 83 |
# File 'lib/goon_model_gen/config.rb', line 79 def default_go_package return default_go_package! rescue nil end |
#default_go_package! ⇒ Object
85 86 87 |
# File 'lib/goon_model_gen/config.rb', line 85 def default_go_package! return Pathname.new(Dir.pwd).relative_path_from(Pathname.new(File.join(Golang.gopath, "src"))).to_s end |
#fulfill ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/goon_model_gen/config.rb', line 35 def fulfill @gofmt_disabled ||= false @model_dir ||= "./model" @store_dir ||= "./stores" @validation_dir ||= "./validation" @converter_dir ||= "./converters" @goa_gen_dir ||= "./gen" @base_package_path ||= default_go_package @model_package_path ||= join_paths(@base_package_path, @model_dir) @store_package_path ||= join_paths(@base_package_path, @store_dir) @validation_package_path ||= join_paths(@base_package_path, @validation_dir) @converter_package_path ||= join_paths(@base_package_path, @converter_dir) @goa_gen_package_path ||= join_paths(@base_package_path, @goa_gen_dir) @structs_gen_dir ||= "./cmd/structs" @structs_json_path ||= "./structs.json" @version_comment ||= false @package_alias_map ||= {} @package_alias_map = PACKAGE_ALIAS_MAP.merge(@package_alias_map) @package_alias_map.default_proc = proc{|hash,key| key.to_s} self end |
#join_paths(path1, path2) ⇒ Object
89 90 91 |
# File 'lib/goon_model_gen/config.rb', line 89 def join_paths(path1, path2) Pathname.new(path1).join(Pathname.new(path2)).to_s end |
#load_from(path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/goon_model_gen/config.rb', line 57 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 |
#to_hash ⇒ Object
69 70 71 72 73 |
# File 'lib/goon_model_gen/config.rb', line 69 def to_hash ATTRIBUTES.each_with_object({}) do |name, d| d[name] = send(name) end end |
#to_yaml ⇒ Object
75 76 77 |
# File 'lib/goon_model_gen/config.rb', line 75 def to_yaml YAML.dump(to_hash) end |