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

UpdateAdhoqToSupportRails5

takkanm
August 29, 2016

 UpdateAdhoqToSupportRails5

SpeeeCoffeeMeetup#01 で LT した話

takkanm

August 29, 2016
Tweet

More Decks by takkanm

Other Decks in Technology

Transcript

  1. 3BJMT&OHJOFΛ
    3BJMTʹରԠͤͨ͞࿩
    ࡾଜӹོ
    !UBLLBON

    View Slide

  2. BCPVU.F
    w &JXB4ZTUFN.BOBHFNFOU
    w "TBLVTBSC
    w ύʔϑΣΫτ3VCZࣥචϝϯόʔͷҰਓ

    View Slide

  3. $PGGFF؀ڥ
    w ϛϧ͸ΧϦλͷύʔϑΣΫτλον
    w ՈͷυϦούʔ͸ϋϦΦ7
    w ձࣾͰ͸ΤΞϩϓϨοι
    w ౾͸ΦϒεΩϡϥ͞Μͷίʔώʔఆظศ

    View Slide

  4. ຊ୊

    View Slide

  5. "EIPR
    w IUUQTHJUIVCDPNFTNJODBEIPR
    w 3BJMTΞϓϦέʔγϣϯʹ೚ҙͷΫΤϦΛ౤͛Ε
    ΔΑ͏ʹ͢ΔͨΊͷFOHJOF
    w ΫΤϦΛอଘͨ͠Γɺ݁ՌΛ೚ҙͷϑΥʔϚο
    τʹͯ͠ग़ྗ͢Δ͜ͱ͕Ͱ͖Δ

    View Slide

  6. "EIPR

    View Slide

  7. "EIPRϢʔεέʔε
    w ूܭΫΤϦͷಈ࡞֬ೝ
    w ఆظతʹಛఆͷूܭΛཔ·Εͨ࣌ʹΫΤϦΛอ
    ଘͯ͠࢖ͬͯ΋Β͏
    w ো֐ରԠ౳Ͱσʔλͷ֬ೝΛߦ͏ࡍʹ

    View Slide

  8. IUUQTHJUIVCDPN
    FTNJODBEIPRQVMM
    w 3BJMT͕ϦϦʔε͞ΕͨޙʹૹΒΕ͖ͯͨରԠ
    QVMMSFRVFTU
    w ͦͷ··Ͱ͸Ϛʔδͮ͠Β͔ͬͨͨΊɺ࡞ऀʹ
    मਖ਼Λґཔ͕ͨ͠ରԠ͞Εͣ

    View Slide

  9. ࠓ೔ͷςʔϚ
    3BJMTͰಈ࡞͠ͳ͍3BJMTFOHJOFΛ
    աڈͷόʔδϣϯͰͷಈ࡞Λอͪͭͭ
    Ξοϓσʔτ͓ͤͨ͞࿩
    IUUQTHJUIVCDPNFTNJODBEIPRQVMM

    View Slide

  10. 3BJMTͰಈ࡞[ͤ͞ΔͨΊʹ
    ରԠͨ͜͠ͱ
    w [email protected]
    w "DUJPO$POUSPMMFS1BSBNFUFSTͷมߋ௥

    w 3BJMTɹʹ޲͚ͯͷXBSOJOH࡟আ

    View Slide

  11. [email protected]
    w 3BJMT͔Β͸[email protected]ͱ͍͏ϝιου
    ͕࡟আ͞ΕͨJOOPDFODF
    w [email protected]͸ίϯτϩʔϥʔͷϝιου
    ΛΞΫγϣϯͱͯ͠ݟͤͳ͘͢ΔͨΊͷϝιο
    υ

    View Slide

  12. มߋલ
    # app/controllers/adhoq/authorization_methods.rb
    module Adhoq
    module AuthorizationMethods
    extend ActiveSupport::Concern
    included do |controller|
    controller.before_filter Authorizer.new
    helper_method :adhoq_current_user
    hide_action :adhoq_current_user
    end
    def adhoq_current_user
    end
    end
    end

    View Slide

  13. มߋޙ
    # app/controllers/adhoq/authorization_methods.rb
    module Adhoq
    module AuthorizationMethods
    extend ActiveSupport::Concern
    included do |controller|
    controller.before_filter Authorizer.new
    helper_method :adhoq_current_user
    end
    private
    def adhoq_current_user
    end
    end
    end

    View Slide

  14. "DUJPO$POUSPMMFS1BSB
    NFUFSTͷมߋ௥ै
    w 3BJMTͰ"DUJPO$POUSPMMFS1BSBNFUFST
    ͕)BTIΛܧঝ͠ͳ͘ͳͬͨ
    w "DUJPO$POUSPMMFS1BSBNFUFSTͷΦϒδ
    ΣΫτΛͦͷ··"DUJWF+PCͷύϥϝʔλʔʹ
    ೖΕ͍ͯΔՕॴ͕͋ͬͨ

    View Slide

  15. มߋલ
    w
    module Adhoq
    class ExecutionsController < Adhoq::ApplicationController
    def asynced_create
    Adhoq::ExecuteJob.perform_later(current_query,
    params[:execution][:report_format], query_parameters)
    redirect_to current_query
    end
    def query_parameters
    params[:parameters] || HashWithIndifferentAccess.new
    end
    end
    end

    View Slide

  16. มߋޙ
    def query_parameters
    if params[:parameters]
    if params[:parameters].kind_of?(Hash)
    params[:parameters]
    else
    # for after Rails5
    params[:parameters].to_unsafe_hash
    end
    else
    HashWithIndifferentAccess.new
    end
    end

    View Slide

  17. 3BJMT΁޲͚ͯͷ
    XBSOJOH࡟আ
    w [email protected]Λ[email protected]
    w DPOpHͷॻ͖ํมߋ UFTU

    w UJNFܕΧϥϜͷڍಈΛܾఆ UFTU

    View Slide

  18. دΓಓɿ[email protected]ʹߦ
    ͬͨ3BJMTରԠ
    w [email protected]@DIBJOΛQSFQFOEFEΛ
    ࢖͏Α͏ʹ
    w IUUQTHJUIVCDPNNJMFT[T
    [email protected]

    View Slide

  19. มߋલ
    w
    module PdfHelper
    def self.included(base)
    # Protect from trying to augment modules that appear
    # as the result of adding other gems.
    return if base != ActionController::Base
    base.class_eval do
    alias_method_chain :render, :wicked_pdf
    alias_method_chain :render_to_string, :wicked_pdf
    after_filter :clean_temp_files
    end
    end
    end

    View Slide

  20. มߋલ
    w
    module PdfHelper
    def self.prepended(base)
    # Protect from trying to augment modules that appear
    # as the result of adding other gems.
    return if base != ActionController::Base
    base.class_eval do
    after_action :clean_temp_files
    alias_method :render_without_wicked_pdf, :render
    alias_method :render_to_string_without_wicked_pdf, :render_to_string
    def render(options = nil, *args, &block)
    render_with_wicked_pdf(options, *args, &block)
    end
    def render_to_string(options = nil, *args, &block)
    render_to_string_with_wicked_pdf(options, *args, &block)
    end
    end
    end
    end

    View Slide

  21. ࠓޙͷͨΊʹ
    w ςετϚτϦοΫεͷ௥Ճ
    w FEHF3BJMTͱ࠷৽ͷ3VCZͷόʔδϣϯ
    ௥Ճ
    w αϙʔτόʔδϣϯͷมߋ
    w 3BJMTެࣜͱαϙʔτόʔδϣϯ͋Θͤͨ

    View Slide

  22. ·ͱΊ
    w ޙํޓ׵ੜΛอͪͳ͕Β௥ਵ͢Δͷେม
    w ಈ͍ͯͳͯ͘΋͍͍͔Β֬ೝͰ͖Δ؀ڥ͸༻
    ҙ͓ͯ͜͠͏
    w ͪΌΜͱಈ͘Α͏ʹͳͬͨͷͰؾʹͳͬͨํ
    ͸BEIPR࢖ͬͯΈ͍ͯͩ͘͞

    View Slide