run_simple 'git clone --quiet main clone'
cd 'clone'
create_dir 'Membres'
- BASE_SUBSCRIPTIONS.each_pair do |number, data|
- file = subscription_filename_for_id(number)
- write_file file, render_subscription_file(data)
+ BASE_MEMBERS.each_pair do |number, data|
+ file = member_filename_for_id(number)
+ write_file file, render_member_file(data)
run_simple "git add #{file}"
end
run_simple 'git commit --quiet -m "Initial data set from fixtures"'
--- /dev/null
+#-*- coding: utf-8 -*-
+
+Given /une base de membres vide$/ do
+ create_dir 'Membres'
+end
+
+Given /^(?:une base )?avec (\w+)(, à jour de cotisation| qui n'a pas payé sa cotisation cette année)$/ do |name, uptodate|
+ case uptodate
+ when ', à jour de cotisation'
+ # ± 1 month ago
+ paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
+ else
+ # ± 15 months ago
+ paid_on = (Time.now - 3600*24*30*15).strftime('%Y-%m-%d')
+ end
+ data = { 'name' => name,
+ 'address' => "At #{name}",
+ 'email' => "#{name.downcase}@example.org",
+ 'membership_fee_paid_on' => paid_on
+ }
+ create_dir 'Membres'
+ file = member_filename_for_id(new_id)
+ write_file file, render_member_file(data)
+end
+
+Given /^une nouvelle adhésion de (\w+)$/ do |name|
+ data = { 'name' => name,
+ 'address' => "At #{name}",
+ 'email' => "#{name.downcase}@example.org",
+ 'membership_fee_paid_on' => Time.now.strftime('%Y-%m-%d')
+ }
+ create_dir 'Membres'
+ file = member_filename_for_id(new_id)
+ write_file file, render_member_file(data)
+end
+
+When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
+ @file = member_filename_for_id(new_id)
+ write_file @file, render_member_file(EXTRA_MEMBER)
+end
+
+When /^j'ajoute une fiche vide$/ do
+ @file = member_filename_for_id(new_id)
+ write_file @file, ''
+end
+
+When /^j'ajoute une fiche sans YAML$/ do
+ @file = member_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ Ceci est une fiche sans YAML.
+ EOF
+end
+
+When /^j'ajoute une fiche avec du mauvais YAML$/ do
+ @file = member_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ [This is missing a closing bracket
+ ---
+ EOF
+end
+
+When /^j'ajoute une fiche sans email$/ do
+ @file = member_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ name: J. Example
+ address: |
+ 21 Jump Street
+ 42000 Synthé
+ membership_fee_paid_on: 2013-02-20
+ ---
+ EOF
+end
+
+When /^j'ajoute une fiche sans nom$/ do
+ @file = member_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ email: joe@example.org
+ address: |
+ 21 Jump Street
+ 42000 Synthé
+ membership_fee_paid_on: 2013-02-20
+ ---
+ EOF
+end
+
+When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date|
+ @file = member_filename_for_id(new_id)
+ write_file @file, <<-EOF.gsub(/^ /, '')
+ ---
+ name: J. Example
+ email: joe@example.org
+ address: |
+ 21 Jump Street
+ 42000 Synthé
+ membership_fee_paid_on: #{date}
+ ---
+ EOF
+end
+
+When /^je supprime le nom sur une fiche existante$/ do
+ @file = member_filename_for_id(1)
+ run_simple "sed -e '/^name:/d' -i #{@file}"
+end
+
+When /^j'ajoute un fichier hors de la base des adhérents$/ do
+ @file = 'test'
+ write_file @file, 'Test content.'
+end
+++ /dev/null
-#-*- coding: utf-8 -*-
-
-Given /une base de membres vide$/ do
- create_dir 'Membres'
-end
-
-Given /^(?:une base )?avec (\w+)(, à jour de cotisation| qui n'a pas payé sa cotisation cette année)$/ do |name, uptodate|
- case uptodate
- when ', à jour de cotisation'
- # ± 1 month ago
- paid_on = (Time.now - 3600*24*30).strftime('%Y-%m-%d')
- else
- # ± 15 months ago
- paid_on = (Time.now - 3600*24*30*15).strftime('%Y-%m-%d')
- end
- data = { 'name' => name,
- 'address' => "At #{name}",
- 'email' => "#{name.downcase}@example.org",
- 'membership_fee_paid_on' => paid_on
- }
- create_dir 'Membres'
- file = subscription_filename_for_id(new_id)
- write_file file, render_subscription_file(data)
-end
-
-Given /^une nouvelle adhésion de (\w+)$/ do |name|
- data = { 'name' => name,
- 'address' => "At #{name}",
- 'email' => "#{name.downcase}@example.org",
- 'membership_fee_paid_on' => Time.now.strftime('%Y-%m-%d')
- }
- create_dir 'Membres'
- file = subscription_filename_for_id(new_id)
- write_file file, render_subscription_file(data)
-end
-
-When /^j'ajoute une fiche correcte pour une nouvelle adhésion$/ do
- @file = subscription_filename_for_id(new_id)
- write_file @file, render_subscription_file(EXTRA_SUBSCRIPTION)
-end
-
-When /^j'ajoute une fiche vide$/ do
- @file = subscription_filename_for_id(new_id)
- write_file @file, ''
-end
-
-When /^j'ajoute une fiche sans YAML$/ do
- @file = subscription_filename_for_id(new_id)
- write_file @file, <<-EOF.gsub(/^ /, '')
- Ceci est une fiche sans YAML.
- EOF
-end
-
-When /^j'ajoute une fiche avec du mauvais YAML$/ do
- @file = subscription_filename_for_id(new_id)
- write_file @file, <<-EOF.gsub(/^ /, '')
- ---
- [This is missing a closing bracket
- ---
- EOF
-end
-
-When /^j'ajoute une fiche sans email$/ do
- @file = subscription_filename_for_id(new_id)
- write_file @file, <<-EOF.gsub(/^ /, '')
- ---
- name: J. Example
- address: |
- 21 Jump Street
- 42000 Synthé
- membership_fee_paid_on: 2013-02-20
- ---
- EOF
-end
-
-When /^j'ajoute une fiche sans nom$/ do
- @file = subscription_filename_for_id(new_id)
- write_file @file, <<-EOF.gsub(/^ /, '')
- ---
- email: joe@example.org
- address: |
- 21 Jump Street
- 42000 Synthé
- membership_fee_paid_on: 2013-02-20
- ---
- EOF
-end
-
-When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date|
- @file = subscription_filename_for_id(new_id)
- write_file @file, <<-EOF.gsub(/^ /, '')
- ---
- name: J. Example
- email: joe@example.org
- address: |
- 21 Jump Street
- 42000 Synthé
- membership_fee_paid_on: #{date}
- ---
- EOF
-end
-
-When /^je supprime le nom sur une fiche existante$/ do
- @file = subscription_filename_for_id(1)
- run_simple "sed -e '/^name:/d' -i #{@file}"
-end
-
-When /^j'ajoute un fichier hors de la base des adhérents$/ do
- @file = 'test'
- write_file @file, 'Test content.'
-end
require 'ostruct'
require 'yaml'
-BASE_SUBSCRIPTIONS = YAML.load(<<END_OF_YAML)
+BASE_MEMBERS = YAML.load(<<END_OF_YAML)
000001:
name: Matthieu Simon-Blavier
address: |
Et il n'est pas à jour de cotisation.
END_OF_YAML
-EXTRA_SUBSCRIPTION = YAML.load(<<END_OF_YAML)
+EXTRA_MEMBER = YAML.load(<<END_OF_YAML)
name: Franck Rohard
address: |
SOCIETE FRANCAISE DU RADIOTELEPHONE - SFR
Il vient de `whois sfr.fr`.
END_OF_YAML
-SUBSCRIPTION_FILE_TEMPLATE = <<'END_OF_TEMPLATE'
+MEMBER_FILE_TEMPLATE = <<'END_OF_TEMPLATE'
---
name: <%= name %>
address: |
<%= notes %>
END_OF_TEMPLATE
-def subscription_filename_for_id(id)
+def member_filename_for_id(id)
"Membres/%06d.mdwn" % id
end
-def render_subscription_file(locals)
- ERB.new(SUBSCRIPTION_FILE_TEMPLATE).result(OpenStruct.new(locals).instance_eval { binding })
+def render_member_file(locals)
+ ERB.new(MEMBER_FILE_TEMPLATE).result(OpenStruct.new(locals).instance_eval { binding })
end
def new_id
require 'nos_oignons/git'
require 'nos_oignons/mailman'
-require 'nos_oignons/subscriptions'
+require 'nos_oignons/member'
module NosOignons
# The following class methods are all meant to be called as command-line scripts
class << self
def list_emails!
- NosOignons::Subscription.all.each do |subscription|
- if subscription.up_to_date?
- puts subscription.email
+ NosOignons::Member.all.each do |member|
+ if member.up_to_date?
+ puts member.email
end
end
end
MEMBER_MAILING_LIST = 'ag'
def update_ag_subscribers!
current_emails = NosOignons::Mailman.list_members(MEMBER_MAILING_LIST)
- uptodate_emails = NosOignons::Subscription.all.select(&:up_to_date?).collect(&:email)
+ uptodate_emails = NosOignons::Member.all.select(&:up_to_date?).collect(&:email)
NosOignons::Mailman.add_members(MEMBER_MAILING_LIST, uptodate_emails - current_emails)
NosOignons::Mailman.remove_members(MEMBER_MAILING_LIST, current_emails - uptodate_emails)
IO.popen(['git', 'diff-index', '--cached', '--name-status', against]) do |io|
NosOignons::Git.handle_modified_files(io) do |file|
- next unless file.start_with?("#{NosOignons::SUBSCRIPTIONS_ROOT}/")
+ next unless file.start_with?("#{NosOignons::MEMBERS_ROOT}/")
begin
# Use empty ref to get the index
- NosOignons::Subscription.read_from_git('', file)
+ NosOignons::Member.read_from_git('', file)
rescue ArgumentError
$stderr.puts "Désolé : #{file} n'a pas le bon format !"
exit 1
old_value, new_value, ref_name = ref_line.rstrip.split(' ', 3)
IO.popen(['git', 'diff', '--name-status', "#{old_value}..#{new_value}"]) do |io|
NosOignons::Git.handle_modified_files(io) do |file|
- next unless file.start_with?("#{NosOignons::SUBSCRIPTIONS_ROOT}/")
+ next unless file.start_with?("#{NosOignons::MEMBERS_ROOT}/")
begin
- NosOignons::Subscription.read_from_git(new_value, file)
+ NosOignons::Member.read_from_git(new_value, file)
rescue ArgumentError
$stderr.puts "Désolé : #{file} n'a pas le bon format !"
exit 1
--- /dev/null
+require 'safe_yaml'
+SafeYAML::OPTIONS[:default_mode] = :safe
+
+module NosOignons
+ MEMBERS_ROOT = 'Membres'
+ MEMBER_FIELDS = [:name, :address, :email, :membership_fee_paid_on]
+ MEMBER_MANDATORY_FIELDS = [:name, :email]
+
+ class Member < Struct.new(*MEMBER_FIELDS)
+ class << self
+ def all
+ Dir.glob("#{MEMBERS_ROOT}/*.mdwn").sort.collect do |file|
+ member_id = File.basename(file).gsub(/\.mdwn$/, '')
+ Member.new(member_id)
+ end
+ end
+
+ def filename_for_id(member_id)
+ "Membres/%06d.mdwn" % member_id
+ end
+
+ def read_from_git(ref, file)
+ IO.popen(['git', 'show', "#{ref}:#{file}"]) do |f|
+ member_id = File.basename(file).gsub(/\.mdwn$/, '')
+ Member.new(member_id, f.read)
+ end
+ end
+ end
+
+ attr_reader :member_id
+
+ def initialize(member_id, page_content=nil)
+ unless member_id =~ /\A\d{6}\z/
+ raise ArgumentError.new('bad member id format')
+ end
+ @member_id = member_id
+ unless page_content
+ page_content = File.open(Member.filename_for_id(member_id)).read
+ end
+ unless page_content.start_with?("---\n")
+ raise ArgumentError.new('content is not a proper YAML document')
+ end
+ data = YAML.load(page_content)
+ MEMBER_FIELDS.each do |field|
+ self[field] = data[field.to_s]
+ end
+ # Immutability for the win
+ MEMBER_FIELDS.each do |field|
+ instance_eval{ undef :"#{field}=" }
+ end
+ MEMBER_MANDATORY_FIELDS.each do |sym|
+ raise ArgumentError.new('missing mandatory fields') unless self[sym]
+ end
+ if membership_fee_paid_on && !membership_fee_paid_on.is_a?(Date)
+ raise ArgumentError.new('membership_fee_paid_on is not a date')
+ end
+ end
+
+ def up_to_date?
+ now = Time.now
+ last_year = Time.new(now.year - 1, now.month, now.day).to_date
+ membership_fee_paid_on && last_year < membership_fee_paid_on
+ end
+ end
+end
+++ /dev/null
-require 'safe_yaml'
-SafeYAML::OPTIONS[:default_mode] = :safe
-
-module NosOignons
- SUBSCRIPTIONS_ROOT = 'Membres'
- SUBSCRIPTION_FIELDS = [:name, :address, :email, :membership_fee_paid_on]
- SUBSCRIPTION_MANDATORY_FIELDS = [:name, :email]
-
- class Subscription < Struct.new(*SUBSCRIPTION_FIELDS)
- class << self
- def all
- Dir.glob("#{SUBSCRIPTIONS_ROOT}/*.mdwn").sort.collect do |file|
- subscription_id = File.basename(file).gsub(/\.mdwn$/, '')
- Subscription.new(subscription_id)
- end
- end
-
- def filename_for_id(subscription_id)
- "Membres/%06d.mdwn" % subscription_id
- end
-
- def read_from_git(ref, file)
- IO.popen(['git', 'show', "#{ref}:#{file}"]) do |f|
- subscription_id = File.basename(file).gsub(/\.mdwn$/, '')
- Subscription.new(subscription_id, f.read)
- end
- end
- end
-
- attr_reader :subscription_id
-
- def initialize(subscription_id, page_content=nil)
- unless subscription_id =~ /\A\d{6}\z/
- raise ArgumentError.new('bad subscription id format')
- end
- @subscription_id = subscription_id
- unless page_content
- page_content = File.open(Subscription.filename_for_id(subscription_id)).read
- end
- unless page_content.start_with?("---\n")
- raise ArgumentError.new('content is not a proper YAML document')
- end
- data = YAML.load(page_content)
- SUBSCRIPTION_FIELDS.each do |field|
- self[field] = data[field.to_s]
- end
- # Immutability for the win
- SUBSCRIPTION_FIELDS.each do |field|
- instance_eval{ undef :"#{field}=" }
- end
- SUBSCRIPTION_MANDATORY_FIELDS.each do |sym|
- raise ArgumentError.new('missing mandatory fields') unless self[sym]
- end
- if membership_fee_paid_on && !membership_fee_paid_on.is_a?(Date)
- raise ArgumentError.new('membership_fee_paid_on is not a date')
- end
- end
-
- def up_to_date?
- now = Time.now
- last_year = Time.new(now.year - 1, now.month, now.day).to_date
- membership_fee_paid_on && last_year < membership_fee_paid_on
- end
- end
-end