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

RailsとPhoenixのパッケージ比較&Elixirのマクロについて少々

 RailsとPhoenixのパッケージ比較&Elixirのマクロについて少々

RailsとPhoenixのパッケージ比較&Elixirのマクロについて少々

Kenta Katsumata

March 21, 2016
Tweet

More Decks by Kenta Katsumata

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ໊લɿউຢ݈ଠ • ࢓ࣄɿϑϦʔϥϯεͷࡶ৯ܥΤϯδχΞ • ݱࡏɿ(ג)ΞΧπΩ͞ΜͰ৽نࣄۀνʔϜͷΤϯδχΞ • झຯɿےτϨɾύʔςΟɾΫϥϒ׆ಈɾετϦʔτμϯεɾϥάϏʔ؍ ઓɾbokete(੕11000֫ಘܦݧ͋Γ)

    • ΩϟϦΞ·ͱΊ COBOL/Delphi/VC++/Perl/JavaScript/C#/VB.NET/Ruby/Java/PHP/ActionScript/lua/Python/Objective-C/Elixir Windows-SDK/MFC/STL/.NET Framework/Struts/CakePHP/Symfony/CodeIgniter/Zend Framwork/Ethna/Rails/Django/Phoenix SQL Server/Oracle/MySQL/Potgresql AWS(VPC/EC2/RDS/S3/CloudFront/Route53/IAM/SES/CLI) IIS/ActiveX(COM)/DirectShow/ActiveDirectory/Sharepoint/Biztalk/Exchange BIND/LDAP/DHCP/Sendmail/Postfix/apache/nginx/unicorn/Tomcat/Jenkins/Wercker/Chef/Capistrano/Gulp Xen/KVM/VMWare/Vagrant/Docker/LVS/memcached/Tokyo Tyrant/Kyoto Tycoon/Redis/MongoDB/Q4M/RabbitMQ Zabbix/nagios/Cacti/Munin/NewRelic/ElasticSearch/Mecab/Fluentd (αʔόʔαΠυ։ൃɾΠϯϑϥߏங؅ཧɾෛՙରࡦɾιʔγϟϧήʔϜ։ൃɾWindowsΞϓϦ։ൃɾiOS/AndroidΞϓϦ։ൃͳͲ৭ʑͱ)
  2. ύοέʔδൺֱද ༻్ 3BJMT 1IPFOJY ධՁ ϚΠάϨʔγϣϯ SJEHFQPMF FDUP@NJHSBUF  ೝূ

    EFWJTF VFCFSBVUI ˚ ೝՄ DBODBODBO HVBSEJBO ˓ ιʔγϟϧϩάΠϯ PNOJBVUI VFCFSBVUI@ ˓ ؅ཧը໘ BDUJWFBENJO FY@BENJO ˚ 3&45"1* HSBQF NBSV ˓ ը૾Ξοϓϩʔυ DBSSJFSXBWF BSD ˚ "84࿈ܞ BXTTELSBJMT BXTFMJYJSFY@BXT FSMDMPVE ˓ ଟݴޠରԠ JO HFUUFYU ˓ .PEFMͷ ଟࠃޠରԠ HMPCBMJ[F   ઃఆ஋؅ཧ SBJMT@DPOpH  ˚
  3. ϚΠάϨʔγϣϯ (ecto_migrate) ▪Good • ridgepoleͱಉ༷ʹɺࣗಈతʹCREATEจ΍ALTERจΛੜ੒ͯ͘͠Ε·͢ɻ ▪Bad • ϑΟʔϧυͷܕΛมߋ͠ͳ͍ͱɺϑΟʔϧυͷαΠζมߋ౳͕ߦ͑ͳ͍ɻ • ઐ༻ͷςʔϒϧΛ3ͭ͘Β͍উखʹੜ੒ͯ͠͠·͏ɻ

    • Ecto2.0΁ͷΞοϓάϨʔυʹ௥ਵ͢Δؾ഑͕ͳ͍Ͱ͢ɻ(Issueཱ͕ͬͯͳ͍ˍͦΕ༻ͷϒϥϯν΋ ͳ͍) ▪·ͱΊ • ݱ࣌఺Ͱ͸ɺPhoenixͷ௨ৗͷϚΠάϨʔγϣϯػೳΛ࢖༻͓͍ͯͨ͠ํ͕ྑ͍ͱࢥΘΕ·͢ɻ • ridgepoleͷElixir൛͕ཉ͍͠Ͱ͢ɾɾɾɻ
  4. ೝূ (ueberauth/ueberauth_identity) ▪Good • ͱΓ͋͑ͣPhoenixʹ͓͍ͯ͸ελϯμʔυͳೝূύοέʔδͳͷͰ҆৺ײ͸͋Γ·͢ɻ ▪Bad • deviseͱൺֱ͢Δͱ͔ͳΓػೳෆ଍ɻ(֬ೝϝʔϧͷૹ৴ػೳ΍ύεϫʔυ࠶ઃఆػೳ౳͕ͳ͍) • ೝূޙͷϢʔβʔ৘ใΛηογϣϯʹอ࣋ͨ͠Γ͢ΔίʔυΛࣗ෼Ͱॻ͘ඞཁ͕͋Δɻ

    • (ඞવతʹ)ϔϧύʔؔ਺౳΋ࣗ෼Ͱ࡞੒͢Δඞཁ͕͋Δɻ(current_userͱ͔user_signed_in?ͱ ͔) ▪·ͱΊ • ػೳෆ଍Ͱ͸͋Γ·͕͢ɺޙड़͢ΔueberauthͷιʔγϟϧϩάΠϯܥύοέʔδͱͷབྷΈ΋͋ ΔͷͰɺͱΓ͋͑ͣ͜ΕҰ୒͔ͳͱ͍͏ҹ৅Ͱ͢ɻ
  5. ೝՄ (guardian) ▪Good • ueberauthͱͷ࿈ܞ͸ී௨ʹՄೳͩͱࢥΘΕ·͢ɻ(ϑϩʔ͕ҟͳΔͷͰ౰વͱ͍͑͹౰વͰ͕͢) • Phoenixͷίϯτϩʔϥʔʹ૊ΈࠐΜͰ࢖͏ͷ͕લఏ(ΞΫγϣϯʹҾ਺͕2ͭ௥Ճ͞ΕΔ)ͳΑ͏Ͱ͕͢ɺޙड़͢ Δmaru(REST API༻ύοέʔδ)ͱͷ࿈ܞ΋ՄೳͩͱࢥΘΕ·͢ɻ •

    guardiandbͱ࿈ܞ͢Ε͹ɺαʔόʔଆͷૢ࡞ͰಛఆͷϢʔβʔΛڧ੍ϩάΞ΢τ͢Δ͜ͱ͸ՄೳͳΑ͏Ͱ͢ɻ ▪Bad • υΩϡϝϯτ͕෼͔Γʹ͍͘Ͱ͢ɻʮphoenix_guardianʯͱ͍͏αϯϓϧ͕͋ΔͷͰͦͪΒΛࢀߟʹ͢Δͱྑ͍ ͔ͱɻ(https://github.com/hassox/phoenix_guardian) • cancancanΈ͍ͨͳߏจͰݖݶ൑ఆΛߦ͍͍ͨ৔߹͸ɺϥοϓ͢ΔϞδϡʔϧ΍ϔϧύʔΛผʹ࡞Δඞཁ͕͋Γ ͦ͏Ͱ͢ɻ ▪·ͱΊ • ͱΓ͋͑ͣػೳͱͯ͠͸े෼଍Γ͍ͯΔ͔ͳͱ͍͏ҹ৅Ͱ͢ɻ
  6. REST API (maru) ▪Good • grapeͱಉ༷ͳDSLΛ࢖ͬͯAPI͕ఆٛग़དྷ·͢ɻ ▪Bad • (maru͕ѱ͍Θ͚Ͱ͸ͳ͍Ͱ͕͢)jbuilderతͳύοέʔδ͕ͳ͍ͷͰςϯϓϨʔτ Ͱ͸ͳ͘ϚοϓͰjsonΛఆٛ͢Δඞཁ͕͋Γ·͢ɻ

    ▪·ͱΊ • jsonੜ੒෦෼ʹؔͯ͠͸ͱΓ͋͑ͣϚοϓͰରԠ͓͍ͯͯ͠ɺ༨༟͕͋Ε͹ಠࣗʹ ύοέʔδ࡞ͬͯDSLͰjson෦෼Λఆٛग़དྷΔΑ͏ͨ͠ํ͕ྑͦ͞͏ͳҹ৅Ͱ͢ɻ
  7. ؅ཧը໘ (ex_admin) ▪Good • ActiveAdminͱ΄΅ಉ༷ͳUIˍػೳ͕؆୯ʹ࣮ݱग़དྷ·͢ɻ • ueberauthͱͷ࿈ܞ΋ՄೳͰ͢ɻ(ϩάΠϯ/ϩάΞ΢τ/ϩάΠϯϢʔβʔ໊ͷදࣔ౳) • (ueberauthͱ࿈ܞ͢ΔػೳΛ࡞੒ͨ͠ࡍͷهࣄ ->

    http://qiita.com/poly_soft/items/7da87d56ebdbb8755a3c) ▪Bad • (ex_admin͕ѱ͍Θ͚Ͱ͸ͳ͍Ͱ͕͢)Ϟσϧͱؔ࿈ͨ͠ը૾ͷΞοϓϩʔυ͕UPDATEॲཧͷ৔߹ʹ͔͠ߦ͑ͳ͍ͱ͍͏੍ݶ͕ ͋Γ·͢ɻ(ޙड़͢Δarc_ectoͷ੍ݶ) • guardianͱͷ࿈ܞ͸ͪΐͬͱऑͦ͏ͳײ͡Ͱ͢ɻ(before_filterػೳΛ࢖͑͹ɺΞΫγϣϯ୯ҐͰݖݶΛ൑ఆ͢Δఔ౓ͷ͜ͱ͸Մ ೳͬΆ͍Ͱ͕͢) • ෆ۩߹ଟΊͰ͢ɻ͋Μ·Γςετ͞Εͯͳ͍ײ͡ɻࢲ΋2ͭ΄ͲϓϧϦΫΛૹ৴ͯ͠Ϛʔδ͞Ε·͕ͨ͠ɺ࡞ऀͷํ͕ଟ๩ͳΑ͏ ͳͷͰࠓޙ΋ϝϯςφϯε͞Ε͍ͯ͘ͷ͔ͪΐͬͱո͍͔͠ͳͱ…ɻ ▪·ͱΊ • ը૾ϑΝΠϧͷΞοϓϩʔυػೳ΍ɺݫີͳೝՄܥͷػೳ͕ඞཁͳ͍ͷͰ͋Ε͹े෼ศརʹ࢖༻ग़དྷΔͱࢥ͍·͕͢ɺͦ͏͍ͬ ͨػೳ͕ඞਢͳͷͰ͋Ε͹ex_admin͸࢖༻͠ͳ͍ํ͕ྑ͍ͱࢥΘΕ·͢ɻ
  8. ը૾Ξοϓϩʔυ (arc/arc_ecto) ▪Good • ϩʔΧϧ/S3΁ͷϑΝΠϧΞοϓϩʔυɺը૾ͷϦαΠζ΍ϑΥʔϚοτม׵౳͸໰୊ͳ࣮͘ߦग़དྷ·͢ɻ ▪Bad • Ectoͱͷ࿈ܞ͸arc_ectoΛ࢖༻͢Δ͜ͱͰՄೳʹͳΓ·͕͢ɺ(Ecto.TypeϏϔΠϏΞͷ࢓༷తʹ)INSERTॲཧ࣌ͷϞ σϧͱͷؔ࿈෇͚͕ߦ͑·ͤΜɻ •

    arc_ectoͷEcto2.0΁ͷରԠ͸૬౰஗͘ͳΓͦ͏Ͱ͢ɻ(Issueཱ͕ͬͯͳ͍ˍͦΕ༻ͷϒϥϯν΋ͳ͍) • arc_ectoΛ࢖༻͠ͳ͍৔߹͸ɺΞοϓϩʔυॲཧΛݺͼग़͢ίʔυΛίϯτϩʔϥ΍αʔϏε૚ʹ͍͍ͪͪॻ͘ඞ ཁ͕͋Γ·͢ɻ(͕͜͜໘౗) • CarrierwaveͷΑ͏ʹɺϒϥ΢βΩϟογϡରࡦͱͯ͠ϑΝΠϧ໊Λߋ৽࣌ʹຖճมߋ͢Δͷ͕গʑ೉͍͠ͷͰɺ Ωϟογϡରࡦͱͯ͠͸ΫΤϦจࣈྻΛ࢖Θ͟ΔΛಘͳ͍ɻ(CloudFront͸ҰԠରԠͯ͘͠Ε͍ͯΔ) ▪·ͱΊ • arc_ecto͸࢖༻ͤͣɺarc͚ͩΛ࢖༻͢ΔΑ͏ʹͨ͠ํ͕ແ೉ͩͱࢥΘΕ·͢ɻ
  9. AWS࿈ܞ (ex_aws/aws-elixir/erlcloud) ▪Good • ͱΓ্͋͑ͣهͷ͍ͣΕ͔ͷύοέʔδΛ࢖༻͢Ε͹ɺAWSͷେମͷαʔϏεͱ͸࿈ܞग़དྷΔΑ͏Ͱ ͢ɻ ▪Bad • ex_aws͸ݱ࣌఺ͰDynamo/Kinesis/Lambda/SQS/S3ʹ͔͠ରԠ͍ͯ͠·ͤΜɻ •

    aws-elixir͸ɺͳ͔ͥEC2/S3ʹରԠ͍ͯ͠·ͤΜɻ • erlcloud͸େମͷαʔϏε΍APIʹରԠ͍ͯ͠ΔΑ͏Ͱ͕͢ɺҾ਺ΛจࣈྻͰ͸ͳ͘char listͰ౉͢ඞཁ ͕͋Γɺ͞Βʹ໭Γ஋͕ϚοϓͰ͸ͳ͘listͰฦͬͯ͘ΔͷͰѻ͍͕গʑ໘౗ͬΆ͍Ͱ͢ɻ ▪·ͱΊ • ύοέʔδ͕ґଘ͍ͯ͠Δ৔߹(arc -> ex_aws౳)Λআ͍ͯ͸ɺجຊతʹ͸erlcloudΛϥοϓͯ͠࢖͏ͷ ͕ྑ͍ͷͰ͸ͳ͍͔ͱࢥΘΕ·͢ɻ
  10. defmodule Mod1 do defmacro macro1(name) do IO.puts "macro1 called." #

    ϚΫϩల։࣌ʹ࣮ߦ͞ΕΔ quote do Mod1.func1 # ίϯύΠϧ࣌ʹ࣮ߦ͞ΕΔ(defmodule಺Ͱల։͞ΕΔͨΊ) def unquote(name)() do # unquote(name)͸ϚΫϩల։࣌ʹ࣮ߦ͞ΕΔ IO.puts "#{unquote(name)} called." # IO.puts͸ϥϯλΠϜɻunquote(name)͸ϚΫϩల։࣌ Mod1.macro2 # ίϯύΠϧ࣌ʹల։͞ΕΔ end end end defmacro macro2 do quote do IO.puts "macro2 called." # ϥϯλΠϜ(defͷதʹల։͞ΕΔͨΊ) end end def func1 do IO.puts "func1 called." end end defmodule Mod2 do import Mod1 macro1 :hello end # => macro1 called. # => func1 called. Mod2.hello # => hello called. # => macro2 called.