]> nos-oignons.net Git - gestion-adh.git/blobdiff - lib/nos_oignons/member.rb
Enable Member#filename_for_id to work with strings
[gestion-adh.git] / lib / nos_oignons / member.rb
index 46fc41b3f7f89066de16b824f5d593064e1130ca..32d32f70ed500009c9b67d04b4fb8e8537e40157 100644 (file)
@@ -21,7 +21,7 @@ module NosOignons
           if File.exists?(File.join(git_path, MEMBERS_DB_DIR))
             @db_path = File.join(git_path, MEMBERS_DB_DIR)
           else
-            @db_path = File.join(File.expand_path('../wiki-ca', path), MEMBERS_DB_DIR)
+            @db_path = File.join(File.expand_path('../wiki-ca', git_path), MEMBERS_DB_DIR)
           end
         end
         @db_path
@@ -35,7 +35,12 @@ module NosOignons
       end
 
       def filename_for_id(member_id)
-        "#{NosOignons::Member.db_path}/%06d.mdwn" % member_id
+        case member_id
+        when String
+          "#{NosOignons::Member.db_path}/#{member_id}.mdwn"
+        when Integer
+          "#{NosOignons::Member.db_path}/%06d.mdwn" % member_id
+        end
       end
 
       def read_from_git(ref, file)
@@ -59,7 +64,8 @@ module NosOignons
       unless page_content.start_with?("---\n")
         raise ArgumentError.new('content is not a proper YAML document')
       end
-      data = YAML.load(page_content)
+      yaml_content = /\A---\n(.*)\n---\n/m.match(page_content)[1]
+      data = YAML.load(yaml_content)
       MEMBER_FIELDS.each do |field|
         self[field] = data[field.to_s]
       end