whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [whimsy] branch master updated: Add ICLAFiles.Dir? and matchStem
Date Sat, 30 Nov 2019 00:44:45 GMT
This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 4a387f3  Add ICLAFiles.Dir? and matchStem
4a387f3 is described below

commit 4a387f37bb4fdb6299fa4bf61fcf8e413d12fe1a
Author: Sebb <sebb@apache.org>
AuthorDate: Sat Nov 30 00:44:36 2019 +0000

    Add ICLAFiles.Dir? and matchStem
    
    No longer need test checkout of icla files
---
 lib/spec/lib/icla_spec.rb          | 38 +++++++++++++++++++++++++++++++++++++-
 lib/test/svn/iclas.txt             |  1 +
 lib/test/svn/iclas/ab/icla.pdf     |  0
 lib/test/svn/iclas/ab/icla.pdf.asc |  0
 lib/test/svn/iclas/abc.pdf         |  0
 lib/test/svn/iclas/abcd.pdf        |  0
 lib/test/svn/iclas/abcd/icla.pdf   |  0
 lib/test/svn/iclas/abcd/icla2.pdf  |  0
 lib/test/svn/iclas/abcde/icla.pdf  |  0
 lib/whimsy/asf/documents.rb        | 20 ++++++++++++++++++--
 10 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/lib/spec/lib/icla_spec.rb b/lib/spec/lib/icla_spec.rb
index da0f1ef..372f248 100644
--- a/lib/spec/lib/icla_spec.rb
+++ b/lib/spec/lib/icla_spec.rb
@@ -6,11 +6,47 @@ require 'whimsy/asf'
 
 set_root # need access to listing file
 
-set_svn 'iclas' # only works with test data as real entry names should not be published
 # Test data:
 # ab/        abc.pdf    abcd/      abcd.pdf   abcde/
 
 describe ASF::ICLAFiles do
+  describe "ASF::ICLAFiles.listnames" do
+    it "should return 6 files" do
+      res = ASF::ICLAFiles.listnames
+      expect(res.length).to equal(6)
+    end
+  end
+
+  describe "ASF::ICLAFiles.matchStem" do
+    it "should return [abcd.pdf] for abcd" do
+      res = ASF::ICLAFiles.matchStem('abcd')
+      expect(res).to eq(['abcd.pdf'])
+    end
+    it "should return [abcd.pdf] for abc" do
+      res = ASF::ICLAFiles.matchStem('abc')
+      expect(res).to eq(['abc.pdf', 'abc.pdf.asc'])
+    end
+  end
+
+  describe "ASF::ICLAFiles.Dir?" do
+    it "should return true for ab" do
+      res = ASF::ICLAFiles.Dir?('ab')
+      expect(res).to eq(true)
+    end
+    it "should return false for abc" do
+      res = ASF::ICLAFiles.Dir?('abc')
+      expect(res).to eq(false)
+    end
+    it "should return true for abcd" do
+      res = ASF::ICLAFiles.Dir?('abcd')
+      expect(res).to eq(true)
+    end
+    it "should return true for abcde" do
+      res = ASF::ICLAFiles.Dir?('abcde')
+      expect(res).to eq(true)
+    end
+  end
+
   describe "ASF::ICLAFiles.match_claRef" do
     it "should return nil for 'xyz'" do
       res = ASF::ICLAFiles.match_claRef('xyz')
diff --git a/lib/test/svn/iclas.txt b/lib/test/svn/iclas.txt
index 69cdc0d..af1e71b 100644
--- a/lib/test/svn/iclas.txt
+++ b/lib/test/svn/iclas.txt
@@ -1,6 +1,7 @@
 0
 ab/
 abc.pdf
+abc.pdf.asc
 abcd/
 abcd.pdf
 abcde/
diff --git a/lib/test/svn/iclas/ab/icla.pdf b/lib/test/svn/iclas/ab/icla.pdf
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/test/svn/iclas/ab/icla.pdf.asc b/lib/test/svn/iclas/ab/icla.pdf.asc
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/test/svn/iclas/abc.pdf b/lib/test/svn/iclas/abc.pdf
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/test/svn/iclas/abcd.pdf b/lib/test/svn/iclas/abcd.pdf
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/test/svn/iclas/abcd/icla.pdf b/lib/test/svn/iclas/abcd/icla.pdf
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/test/svn/iclas/abcd/icla2.pdf b/lib/test/svn/iclas/abcd/icla2.pdf
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/test/svn/iclas/abcde/icla.pdf b/lib/test/svn/iclas/abcde/icla.pdf
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/whimsy/asf/documents.rb b/lib/whimsy/asf/documents.rb
index c18d10e..531d8b6 100644
--- a/lib/whimsy/asf/documents.rb
+++ b/lib/whimsy/asf/documents.rb
@@ -41,15 +41,31 @@ module ASF
   # Common class for access to documents/iclas/ directory
   class ICLAFiles
     @@tag = nil # probably worth caching iclas
+    @@list = nil # this list includes trailing '/' so can detect directories correctly
+
     # search icla files to find match with claRef
+    # matches if the input matches the full name of a file or directory or 
+    # it matches with an extension
     # Returns the basename or nil if no match
     def self.match_claRef(claRef)
       # Match either full name (e.g. directory) or stem (e.g. name.pdf)
-      file = listnames.select{|l| l == claRef || l.start_with?("#{claRef}.") }.first
+      file = listnames.select{|l| l.chomp('/') == claRef || l.start_with?("#{claRef}.") }.map
{|m| m.chomp('/')}.first
+    end
+
+    # is the name a directory?
+    def self.Dir?(name)
+      @@list.include? name + '/'
+    end
+
+    # return a list of names matching stem.*
+    def self.matchStem(stem)
+    listnames.select{|l| ! l.end_with?('/') && l.start_with?("#{stem}.")}
     end
 
+    # This returns the list of names in the top-level directory
+    # directory names are terminated by '/'
     def self.listnames
-      @@tag, list = ASF::SVN.getlisting('iclas', @@tag)
+      @@tag, list = ASF::SVN.getlisting('iclas', @@tag, false)
       if list
         @@list = list
       end


Mime
View raw message