Rails:访问git email配置

时间:2014-03-10 14:46:42

标签: ruby-on-rails git git-config

我们在本地环境中有一个邮件拦截器,因此电子邮件不会发送到实际的邮件地址,而是会向开发人员发送一份副本(devs@project.com)。

很酷,除了所有的开发人员收到整个团队的邮件,这可能很烦人,令人不安。

我想使用自己的电子邮件地址对每个人进行过滤。我想过使用git电子邮件地址,这是我们所有人设定的。

我的Rails代码可以访问此邮件地址吗?

否则,我将创建一个我们每个人都应该设置的.gitignored文件,但那就是更多的设置。

1 个答案:

答案 0 :(得分:0)

在此处找到解决方案:Is it possible to call Git or other command line tools from inside a Thor script?

mail = %x(git config user.email)

所以整个拦截器将是:

class DevelopmentMailInterceptor
  def self.delivering_email(message)

    git_email = %x(git config user.email)
    filter_email = !git_email.empty? git_email : 'devs@project.com'

    if Rails.env.development? && !message.to.include?(filter_email)
      message.subject = "[Local Filter] To: #{message.to} - #{message.subject}"
      message.to = filter_email 
    end

    return message
  end
end