Class: Featuremap
- Inherits:
-
Object
- Object
- Featuremap
- Defined in:
- lib/featuremap.rb
Instance Attribute Summary collapse
-
#err_msg ⇒ Object
readonly
Returns the value of attribute err_msg.
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
-
#create_featuremap(p_featuremap_path) ⇒ Object
class entry point - create a mindmap for a given path.
-
#initialize(p_features_path, p_verbose = false) ⇒ Featuremap
constructor
A new instance of Featuremap.
-
#read_features(p_features_path, p_parent_node = nil) ⇒ Object
scan feature folder for feature files and subdirs.
Constructor Details
#initialize(p_features_path, p_verbose = false) ⇒ Featuremap
Returns a new instance of Featuremap.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/featuremap.rb', line 11 def initialize(p_features_path, p_verbose = false) @exit_status = 0 @err_msg = [] @log = Logger.new(STDOUT) @log.datetime_format = "%H:%M:%S" if ENV['LOG_LEVEL'] == 'debug' @log.level = Logger::DEBUG elsif ENV['LOG_LEVEL'] == 'info' @log.level = Logger::INFO else # default log level @log.level = Logger::ERROR end if p_verbose @log.level = Logger::INFO end if Dir.exists?(p_features_path) @features_path = p_features_path else @exit_status = 66 # see https://www.freebsd.org/cgi/man.cgi?query=sysexits&sektion=3 for more info @err_msg.push("can't find >>#{p_features_path}<< as feature dir") end @log.info("create a new featuremap") @mindmap = Mindmap.new(@log) end |
Instance Attribute Details
#err_msg ⇒ Object (readonly)
Returns the value of attribute err_msg.
9 10 11 |
# File 'lib/featuremap.rb', line 9 def err_msg @err_msg end |
#exit_status ⇒ Object (readonly)
Returns the value of attribute exit_status.
9 10 11 |
# File 'lib/featuremap.rb', line 9 def exit_status @exit_status end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
9 10 11 |
# File 'lib/featuremap.rb', line 9 def nodes @nodes end |
Instance Method Details
#create_featuremap(p_featuremap_path) ⇒ Object
class entry point - create a mindmap for a given path
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/featuremap.rb', line 38 def create_featuremap(p_featuremap_path) if p_featuremap_path featuremap_path = p_featuremap_path else featuremap_path = Dir.pwd + "/featuremap.mm" end while File.exists?(featuremap_path) filename_parts = featuremap_path.split(".") if filename_parts[0] =~ /-\d+$/ filename_parts = filename_parts[0].split("-") featuremap_path = "#{filename_parts[0]}-#{filename_parts[1].to_i + 1}.mm" else featuremap_path = "#{filename_parts[0]}-1.mm" end end if featuremap_path != p_featuremap_path @err_msg.push("given mindmap name is already in use, created #{featuremap_path}") end begin IO.write("#{featuremap_path}","") rescue Exception @err_msg.push("can't write to #{featuremap_path}") @log.warn @err_msg @exit_status = 74 return end read_features(@features_path) mindmap_file = File.open(featuremap_path,"w") mindmap_file.write(@mindmap.to_s) mindmap_file.close end |
#read_features(p_features_path, p_parent_node = nil) ⇒ Object
scan feature folder for feature files and subdirs
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/featuremap.rb', line 71 def read_features(p_features_path, p_parent_node = nil) # don't read features if some error happened before if @exit_status == 0 feature_node = nil begin features = Dir.entries(p_features_path) rescue Exception @err_msg.push("can't access >>#{p_features_path}<< as feature dir") @log.warn @err_msg @exit_status = 66 return end features.each do |feature_file| #ignore files starting with . if feature_file =~ /^[^\.]/ #look for features in only in .feature files if feature_file =~ /\.feature$/ feature = File.read("#{p_features_path}/#{feature_file}") feature.scan(/^\s*(Feature|Ability|Business Need):\s*(\S.*)$/) do |feature_type, feature_name| feature_node = @mindmap.add_node(feature_name, "feature", p_parent_node) end feature.scan(/^\s*(Scenario|Scenario Outline):\s*(\S.*)$/) do |scenario_type, scenario_name| case scenario_type when "Scenario Outline" then @mindmap.add_node(scenario_name, "scenario_outline", feature_node) when "Scenario" then @mindmap.add_node(scenario_name, "scenario", feature_node) end end end # look for subdirs if File.directory?("#{p_features_path}/#{feature_file}") # ignore step_definitions and support folders because those are used for code if feature_file != "step_definitions" && feature_file != "support" subdir_node = @mindmap.add_node(feature_file, "subdir", p_parent_node) read_features("#{p_features_path}/#{feature_file}", subdir_node) end end end end end end |