From 4c730203fde2eb1d6fdcbe11542c6730d11124ae Mon Sep 17 00:00:00 2001 From: Lunar Date: Sun, 2 Jun 2013 11:19:11 +0200 Subject: [PATCH] Rename Subscription to Member --- features/step_definitions/git.rb | 6 +-- .../{subscriptions.rb => members.rb} | 26 ++++++------ features/support/fixtures.rb | 12 +++--- lib/nos_oignons.rb | 18 ++++----- .../{subscriptions.rb => member.rb} | 40 +++++++++---------- 5 files changed, 51 insertions(+), 51 deletions(-) rename features/step_definitions/{subscriptions.rb => members.rb} (78%) rename lib/nos_oignons/{subscriptions.rb => member.rb} (50%) diff --git a/features/step_definitions/git.rb b/features/step_definitions/git.rb index 062181f..8c00ff4 100644 --- a/features/step_definitions/git.rb +++ b/features/step_definitions/git.rb @@ -14,9 +14,9 @@ Given /^un clone du Git contenant les adhésions$/ do 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"' diff --git a/features/step_definitions/subscriptions.rb b/features/step_definitions/members.rb similarity index 78% rename from features/step_definitions/subscriptions.rb rename to features/step_definitions/members.rb index dd18151..8bb0330 100644 --- a/features/step_definitions/subscriptions.rb +++ b/features/step_definitions/members.rb @@ -19,8 +19,8 @@ Given /^(?:une base )?avec (\w+)(, à jour de cotisation| qui n'a pas payé sa c 'membership_fee_paid_on' => paid_on } create_dir 'Membres' - file = subscription_filename_for_id(new_id) - write_file file, render_subscription_file(data) + file = member_filename_for_id(new_id) + write_file file, render_member_file(data) end Given /^une nouvelle adhésion de (\w+)$/ do |name| @@ -30,29 +30,29 @@ Given /^une nouvelle adhésion de (\w+)$/ do |name| '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) + 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 = subscription_filename_for_id(new_id) - write_file @file, render_subscription_file(EXTRA_SUBSCRIPTION) + @file = member_filename_for_id(new_id) + write_file @file, render_member_file(EXTRA_MEMBER) end When /^j'ajoute une fiche vide$/ do - @file = subscription_filename_for_id(new_id) + @file = member_filename_for_id(new_id) write_file @file, '' end When /^j'ajoute une fiche sans YAML$/ do - @file = subscription_filename_for_id(new_id) + @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 = subscription_filename_for_id(new_id) + @file = member_filename_for_id(new_id) write_file @file, <<-EOF.gsub(/^ /, '') --- [This is missing a closing bracket @@ -61,7 +61,7 @@ When /^j'ajoute une fiche avec du mauvais YAML$/ do end When /^j'ajoute une fiche sans email$/ do - @file = subscription_filename_for_id(new_id) + @file = member_filename_for_id(new_id) write_file @file, <<-EOF.gsub(/^ /, '') --- name: J. Example @@ -74,7 +74,7 @@ When /^j'ajoute une fiche sans email$/ do end When /^j'ajoute une fiche sans nom$/ do - @file = subscription_filename_for_id(new_id) + @file = member_filename_for_id(new_id) write_file @file, <<-EOF.gsub(/^ /, '') --- email: joe@example.org @@ -87,7 +87,7 @@ When /^j'ajoute une fiche sans nom$/ do end When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date| - @file = subscription_filename_for_id(new_id) + @file = member_filename_for_id(new_id) write_file @file, <<-EOF.gsub(/^ /, '') --- name: J. Example @@ -101,7 +101,7 @@ When /^j'ajoute une fiche avec comme date de cotisation "([^"]*)"$/ do |date| end When /^je supprime le nom sur une fiche existante$/ do - @file = subscription_filename_for_id(1) + @file = member_filename_for_id(1) run_simple "sed -e '/^name:/d' -i #{@file}" end diff --git a/features/support/fixtures.rb b/features/support/fixtures.rb index 0fa06c0..d9d91de 100644 --- a/features/support/fixtures.rb +++ b/features/support/fixtures.rb @@ -4,7 +4,7 @@ require 'erb' require 'ostruct' require 'yaml' -BASE_SUBSCRIPTIONS = YAML.load(< address: | @@ -61,12 +61,12 @@ membership_fee_paid_on: <%= membership_fee_paid_on %> <%= 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 diff --git a/lib/nos_oignons.rb b/lib/nos_oignons.rb index d377775..694a87b 100644 --- a/lib/nos_oignons.rb +++ b/lib/nos_oignons.rb @@ -2,15 +2,15 @@ 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 @@ -18,7 +18,7 @@ module NosOignons 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) @@ -34,10 +34,10 @@ module NosOignons 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 @@ -51,9 +51,9 @@ module NosOignons 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 diff --git a/lib/nos_oignons/subscriptions.rb b/lib/nos_oignons/member.rb similarity index 50% rename from lib/nos_oignons/subscriptions.rb rename to lib/nos_oignons/member.rb index de4ddf0..9787a63 100644 --- a/lib/nos_oignons/subscriptions.rb +++ b/lib/nos_oignons/member.rb @@ -2,53 +2,53 @@ 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] + MEMBERS_ROOT = 'Membres' + MEMBER_FIELDS = [:name, :address, :email, :membership_fee_paid_on] + MEMBER_MANDATORY_FIELDS = [:name, :email] - class Subscription < Struct.new(*SUBSCRIPTION_FIELDS) + class Member < Struct.new(*MEMBER_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) + 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(subscription_id) - "Membres/%06d.mdwn" % subscription_id + 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| - subscription_id = File.basename(file).gsub(/\.mdwn$/, '') - Subscription.new(subscription_id, f.read) + member_id = File.basename(file).gsub(/\.mdwn$/, '') + Member.new(member_id, f.read) end end end - attr_reader :subscription_id + attr_reader :member_id - def initialize(subscription_id, page_content=nil) - unless subscription_id =~ /\A\d{6}\z/ - raise ArgumentError.new('bad subscription id format') + def initialize(member_id, page_content=nil) + unless member_id =~ /\A\d{6}\z/ + raise ArgumentError.new('bad member id format') end - @subscription_id = subscription_id + @member_id = member_id unless page_content - page_content = File.open(Subscription.filename_for_id(subscription_id)).read + 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) - SUBSCRIPTION_FIELDS.each do |field| + MEMBER_FIELDS.each do |field| self[field] = data[field.to_s] end # Immutability for the win - SUBSCRIPTION_FIELDS.each do |field| + MEMBER_FIELDS.each do |field| instance_eval{ undef :"#{field}=" } end - SUBSCRIPTION_MANDATORY_FIELDS.each do |sym| + 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) -- 2.39.5