Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OSS is great but not special

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
makicamel
December 21, 2019

OSS is great but not special

いつもの開発のようにOSS開発をしよう at TokyoGirls.rb Meetup vol.2

makicamel

December 21, 2019

Transcript

70 slides
  1. Devise class AddUnconfirmedEmailToUser < ActiveRecord::Migration[5.2] def change add_column :users, :unconfirmed_email,

    :string end end # config/initializer/devise.rb config.reconfirmable = true •ઐ༻ͷΧϥϜ௥Ճ •ઃఆ
  2. module Devise::Models::Confirmable extend ActiveSupport::Concern included do before_create :generate_confirmation_token, if: :confirmation_required?

    after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification? if defined?(ActiveRecord) && self < ActiveRecord::Base # ActiveRecord after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification? after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required? else # Mongoid # ... end before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change? end ࠶֬ೝ͕ඞཁͩͬͨΒ Devise ϝʔϧͷมߋΛԆظ͢Δ ϝʔϧૹ৴ ৗʹfalse
  3. DeviseTokenAuth module DeviseTokenAuth::Concerns::User extend ActiveSupport::Concern included do # don't use

    default devise email validation def email_required?; false; end def email_changed?; false; end def will_save_change_to_email?; false; end # ... MZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUIc(JU)VC
 IUUQTHJUIVCDPNMZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUICMPC BGDCBEFCEBFFFBQQNPEFMTEFWJTF@UPLFO@BVUIDPODFSOTVTFSSC
  4. module Devise::Models::Confirmable extend ActiveSupport::Concern included do before_create :generate_confirmation_token, if: :confirmation_required?

    after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification? if defined?(ActiveRecord) && self < ActiveRecord::Base # ActiveRecord after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification? after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required? else # Mongoid # ... end before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change? end Devise don’t use default devise email validation
  5. Ͳ͏ͯ͠ΦʔόʔϥΠυͯ͠Δͷʁ module DeviseTokenAuth::Concerns::User extend ActiveSupport::Concern included do # don't use

    default devise email validation def email_required?; false; end def email_changed?; false; end def will_save_change_to_email?; false; end # ... MZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUIc(JU)VC
 IUUQTHJUIVCDPNMZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUICMPC BGDCBEFCEBFFFBQQNPEFMTEFWJTF@UPLFO@BVUIDPODFSOTVTFSSC
  6. module Devise::Models::Validatable def self.included(base) base.extend ClassMethods assert_validations_api!(base) base.class_eval do validates_presence_of

    :email, if: :email_required? if Devise.activerecord51? validates_uniqueness_of :email, allow_blank: true, case_sensitive: true, if: :will_save_change_to_email? validates_format_of :email, with: email_regexp, allow_blank: true, if: :will_save_change_to_email? else # ... end # ... end end ͜ͷvalidationΛskip͍ͨ͠
  7. module Devise::Models::Confirmable extend ActiveSupport::Concern if Devise.activerecord51? def postpone_email_change? postpone =

    self.class.reconfirmable && will_save_change_to_email? && !@bypass_confirmation_postpone && self.email.present? && (!@skip_reconfirmation_in_callback || !self.email_in_database.nil?) @bypass_confirmation_postpone = false postpone end else # ... ͜ͷvalidation͸skipͨ͘͠ͳ͍
  8. will_save_to_change_email? module ActiveRecord::AttributeMethods::Dirty extend ActiveSupport::Concern include ActiveModel::Dirty included do #

    ... # Attribute methods for "will change if I call save?" attribute_method_affix(prefix: "will_save_change_to_", suffix: "?") attribute_method_suffix("_change_to_be_saved", "_in_database") end SBJMTSBJMTc(JU)VC
 IUUQTHJUIVCDPNSBJMTSBJMTCMPCFEBDCGDECFDD⒎BDUJWFSFDPSEMJC BDUJWF@SFDPSEBUUSJCVUF@NFUIPETEJSUZSC
  9. module DeviseTokenAuth::Concerns::ConfirmableSupport extend ActiveSupport::Concern included do def postpone_email_change? postpone =

    self.class.reconfirmable && email_value_in_database != email && !@bypass_confirmation_postpone && self.email.present? && (!@skip_reconfirmation_in_callback || !email_value_in_database.nil?) @bypass_confirmation_postpone = false postpone end end will_save_to_change_email?Λ email_in_database != emailͰ࠶࣮૷ ˞ɹFNBJM@WBMVF@JO@EBUBCBTF͸3BJMTͷόʔδϣϯʹԠͨ͡FNBJM@JO@EBUBCBTFΛฦ͢ϝιουΛఆٛͨ͠΋ͷͰ͢ will_save_to_change_email?
  10. module DeviseTokenAuth::Concerns::User extend ActiveSupport::Concern included do def email_required?; false; end

    def email_changed?; false; end def will_save_change_to_email?; false; end # ... MZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUIc(JU)VC
 IUUQTHJUIVCDPNMZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUICMPC BGDCBEFCEBFFFBQQNPEFMTEFWJTF@UPLFO@BVUIDPODFSOTVTFSSC Ͱ͖ͨ ValidatableϞδϡʔϧͷڍಈΛมߋ͠ͳ͍
  11. ޙํޓ׵ੑ module DeviseTokenAuth::Concerns::User extend ActiveSupport::Concern included do def email_required?; false;

    end def email_changed?; false; end def will_save_change_to_email?; false; end if DeviseTokenAuth.send_confirmation_email && devise_modules.include?(:confirmable) include DeviseTokenAuth::Concerns::ConfirmableSupport end ϝʔϧૹ৴ϑϥά
  12. ޙํޓ׵ੑ # By default DeviseTokenAuth will not send confirmation email,

    # even when including devise confirmable module. # If you want to use devise confirmable module and # send email, set it to true. # (This is a setting for compatibility) # config.send_confirmation_email = true •υΩϡϝϯτʹઆ໌Λ௥Ճ •configͷςϯϓϨʔτʹઃఆ஋Λ௥Ճ ͜ͷઃఆ஋͕͋Δཧ༝΋ Ұݴఴ͑ͨ
  13. ςετͷ௥Ճ class ConfirmableUser < ActiveRecord::Base # Include default devise modules.

    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :confirmable DeviseTokenAuth.send_confirmation_email = true include DeviseTokenAuth::Concerns::User DeviseTokenAuth.send_confirmation_email = false end •༨ஊͰ͕͢ઃఆ஋ͷςετͷ΍Γํ͕Θ͔Βͳ͔ͬͨͷͰ
 ࠙਌ձͰΞυόΠε͍͚ͨͩΔͱخ͍͠Ͱ͢ʂ MZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUIc(JU)VC
 IUUQTHJUIVCDPNMZOOEZMBOIVSMFZEFWJTF@UPLFO@BVUICMPC BGDCBEFCEBFFFUFTUEVNNZBQQBDUJWF@SFDPSEDPOpSNBCMF@VTFSSC
  14. ૬ஊ if Devise.rails51? && self.respond_to?(:email_in_database) def postpone_email_change? postpone = self.class.reconfirmable

    && will_change_email? && !@bypass_confirmation_postpone && self.email.present? && (!@skip_reconfirmation_in_callback || !self.email_in_database.nil?) @bypass_confirmation_postpone = false postpone end else def postpone_email_change? postpone = self.class.reconfirmable && will_change_email? && !@bypass_confirmation_postpone && self.email.present? && (!@skip_reconfirmation_in_callback || !self.email_was.nil?) @bypass_confirmation_postpone = false postpone end end ɹࣅͨॲཧ͕͋Δͱ͍͏ࢦఠ ɹॲཧ͕ࣅͨίʔυϒϩοΫ
  15. ૬ஊ def postpone_email_change? postpone = self.class.reconfirmable && email_value_in_database != email

    && !@bypass_confirmation_postpone && self.email.present? && (!@skip_reconfirmation_in_callback || !email_value_in_database.nil?) @bypass_confirmation_postpone = false postpone end module੾Γग़͠+ DRYʹ͖ͯͬ͢͠Γ
  16. •ௐࠪɾमਖ਼ •ޙํޓ׵ੑͷҡ࣋ •ςετͷ௥Ճ •Ϛʔδ͞ΕΔ౒ྗ ͜ͷPRͰ΍ͬͨ͜ͱ ઃܭͷཧղ Өڹൣғͷ֬ೝ ྺ࢙తܦҢͷ೺Ѳ طଘ&৽نϢʔβ΁ͷ഑ྀ ૬ஊ

    ૬खͷෛ୲ΛݮΒ͢ ʮ͜ͷίʔυͳΒೖΕͯ΋େৎ෉ʯ σάϨΛى͜͞ͳ͍ কདྷͷσάϨΛੜ·ͳ͍ νʔϜن໿Λ஌Δ Ϧϯτʹै͏ ؔ࿈Gemͷ֬ೝ υΩϡϝϯτ ςϯϓϨʔτ
  17. •RailsίϯτϦϏϡʔγϣϯ͔ΒֶΜͩGit/GitHubज़ - @koic
 https://speakerdeck.com/koic/commit-message-will-never-die •OSSͰ݁ՌΛग़͢ํ๏ - @knu
 https://speakerdeck.com/knu/ossdejie-guo-wochu-sufang-fa •RailsͷissueΛղܾ͢Δ·ͰͷखॱͱOSSॳ৺ऀͰ΋Ͱ͖Δ͜ͱ -

    @sinsoku
 https://sinsoku.hatenablog.com/entry/2019/10/17/013415 •RubyྗΛ্͛ΔͨΊͷίʔυϦʔσΟϯά - @kinoppyd
 https://docs.google.com/presentation/d/1de64myiozcpiS18fvrmmlYLhXdl0y_qlUc-2TGZkNhY/ edit#slide=id.g74005e1fbe_2_29 •OSSߩݙ௒ೖ໳ - @shigemk2
 https://www.slideshare.net/shigemk2/oss-78585757 ࢀߟ

More Decks by makicamel

Other Decks in Programming