├── .gitignore ├── santa_logger.rb ├── config ├── smtp.yml.example └── people.yml.example ├── letter_template.erb ├── person.rb ├── email.rb ├── emailer.rb ├── README.md └── secret_santa.rb /.gitignore: -------------------------------------------------------------------------------- 1 | config/*.yml 2 | -------------------------------------------------------------------------------- /santa_logger.rb: -------------------------------------------------------------------------------- 1 | class SantaLogger 2 | 3 | attr_accessor :sending 4 | 5 | def log(message) 6 | puts "#{message}" unless REALLY_SENDING # Sshh! It's a secret! 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /config/smtp.yml.example: -------------------------------------------------------------------------------- 1 | smtp_server: smtp.gmail.com 2 | domain: gmail.com 3 | account_address: hikingfan@gmail.com 4 | account_password: sUch_a_bEeFy_paSswOrd!_iT's_niGh_ImpeNetrable_29$(@*4729!_gOod_Luck_suckErS 5 | port: 587 6 | -------------------------------------------------------------------------------- /letter_template.erb: -------------------------------------------------------------------------------- 1 | GREETINGS <%= recipient_name.upcase %>, 2 | 3 | [INITIALIZING CHRISTMAS MERRIMENT ROUTINES...] 4 | 5 | SANTABOT 5000 HAS BEEN ACTIVATED. YOU HAVE BEEN CHOSEN AS A SECRET SANTA. 6 | YOUR TARGET IS AS FOLLOWS: 7 | 8 | <%= target_name.upcase %> 9 | 10 | THIS INFORMATION HAS BEEN KEPT SECRET FROM ALL HUMANS BUT YOU. 11 | 12 | YOU KNOW WHAT TO DO. 13 | 14 | --SANTABOT 5000 15 | -------------------------------------------------------------------------------- /person.rb: -------------------------------------------------------------------------------- 1 | class Person 2 | attr_accessor :name, :group, :email, :santa 3 | 4 | def initialize(attrs) 5 | self.name = attrs["name"] 6 | self.group = attrs["group"] 7 | self.email = attrs["email"] 8 | end 9 | 10 | def can_be_santa_of?(other) 11 | group != other.group 12 | end 13 | 14 | def can_swap_santas_with?(other) 15 | santa.can_be_santa_of?(other) && other.santa.can_be_santa_of?(self) 16 | end 17 | 18 | def to_s 19 | "#{name} (#{group})" 20 | end 21 | 22 | def with_santa 23 | "#{self} - santa: #{santa}" 24 | end 25 | 26 | end 27 | -------------------------------------------------------------------------------- /email.rb: -------------------------------------------------------------------------------- 1 | require 'time' 2 | 3 | class Email 4 | attr_accessor :from_address, :to_address, :subject, :body 5 | 6 | def initialize(to_address, subject, body) 7 | self.to_address = to_address 8 | self.subject = subject 9 | self.body = body 10 | end 11 | 12 | def headers 13 | raise "Must set `from_address` before getting headers!" unless from_address 14 | <