Module: Util
- Included in:
- CommandRouter, Resource, Service
- Defined in:
- lib/util.rb
Defined Under Namespace
Classes: Config
Constant Summary collapse
- CONFIG_DIR =
'.spring-gen'
Instance Method Summary collapse
- #config ⇒ Object
- #content_root ⇒ Object
-
#licence ⇒ Object
TODO this only works if user has a valid username in git.
- #user_email ⇒ Object
- #user_name ⇒ Object
Instance Method Details
#config ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/util.rb', line 23 def config return @config if @config config_hash = YAML.load_file("#{content_root}/#{CONFIG_DIR}/service.yml") @config = Config.new(config_hash['service_name'], config_hash['repository_technique'], config_hash['group_id'], config_hash['artifact_id']) end |
#content_root ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/util.rb', line 9 def content_root return @root_dir if @root_dir search_dir = Dir.pwd while search_dir && !Dir.exist?("#{search_dir}/#{CONFIG_DIR}") parent = File.dirname(search_dir) # project_root wird entweder der Root-pfad oder false. Wenn es false # wird, bricht die Schleife ab. Vgl. Rails search_dir = (parent != search_dir) && parent end project_root = search_dir if Dir.exist? "#{search_dir}/#{CONFIG_DIR}" raise 'you are not within a service directory.' unless project_root @root_dir = Pathname.new(File.realpath project_root) end |
#licence ⇒ Object
TODO this only works if user has a valid username in git.
33 34 35 36 37 38 39 40 41 |
# File 'lib/util.rb', line 33 def licence return @licence if @licence content = File.foreach("#{content_root}/#{CONFIG_DIR}/licence.erb") .map { |line| "* #{line}"} .join content = "/*\n#{content}\n*/" @licence = ERB.new(content).result binding end |
#user_email ⇒ Object
49 50 51 52 53 |
# File 'lib/util.rb', line 49 def user_email return @user_email if @user_email g = Git.open(content_root) @user_email = g.config['user.email'] end |
#user_name ⇒ Object
43 44 45 46 47 |
# File 'lib/util.rb', line 43 def user_name return @user_name if @user_name g = Git.open(content_root) @user_name = g.config['user.name'] end |