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

hanami Minsk

hanami Minsk

Anton Davydov

April 23, 2016
Tweet

More Decks by Anton Davydov

Other Decks in Programming

Transcript

  1. hanami (ᜰ憎) Hanami (ᜰ憎, lit. "flower viewing") is the Japanese

    traditional custom of enjoying the transient beauty of flowers, flowers ("hana") in this case almost always referring to those of the cherry ("sakura") or, less frequently, plum ("ume") trees.
  2. app/ ʮʒʒ application.rb ʮʒʒ assets ʔ ʦʒʒ ... ʮʒʒ config

    ʔ ʦʒʒ ... ʮʒʒ controllers ʔ ʦʒʒ ... ʮʒʒ templates ʔ ʦʒʒ ... ʦʒʒ views ʦʒʒ ...
  3. app/ ʮʒʒ application.rb ʮʒʒ assets ʔ ʦʒʒ ... ʮʒʒ config

    ʔ ʦʒʒ ... ʮʒʒ controllers ʔ ʦʒʒ ... ʮʒʒ templates ʔ ʦʒʒ ... ʦʒʒ views ʦʒʒ ...
  4. app/ ʮʒʒ application.rb ʮʒʒ assets ʔ ʦʒʒ ... ʮʒʒ config

    ʔ ʦʒʒ ... ʮʒʒ controllers ʔ ʦʒʒ ... ʮʒʒ templates ʔ ʦʒʒ ... ʦʒʒ views ʦʒʒ ...
  5. app/ ʮʒʒ application.rb ʮʒʒ assets ʔ ʦʒʒ ... ʮʒʒ config

    ʔ ʦʒʒ ... ʮʒʒ controllers ʔ ʦʒʒ ... ʮʒʒ templates ʔ ʦʒʒ ... ʦʒʒ views ʦʒʒ ...
  6. apps/ ʮʒʒ admin ʔ ʮʒʒ application.rb ʔ ʮʒʒ assets ʔ

    ʔ ʦʒʒ ... ʔ ʮʒʒ config ʔ ʔ ʦʒʒ ... ʔ ʮʒʒ controllers ʔ ʔ ʦʒʒ ... ʔ ʮʒʒ templates ʔ ʔ ʦʒʒ ... ʔ ʦʒʒ views ʔ ʦʒʒ ... ʦʒʒ web ʮʒʒ ...
  7. apps/ ʮʒʒ admin ʔ ʮʒʒ application.rb ʔ ʮʒʒ assets ʔ

    ʔ ʦʒʒ ... ʔ ʮʒʒ config ʔ ʔ ʦʒʒ ... ʔ ʮʒʒ controllers ʔ ʔ ʦʒʒ ... ʔ ʮʒʒ templates ʔ ʔ ʦʒʒ ... ʔ ʦʒʒ views ʔ ʦʒʒ ... ʦʒʒ web ʮʒʒ ...
  8. apps/ ʮʒʒ admin ʔ ʮʒʒ application.rb ʔ ʮʒʒ assets ʔ

    ʔ ʦʒʒ ... ʔ ʮʒʒ config ʔ ʔ ʦʒʒ ... ʔ ʮʒʒ controllers ʔ ʔ ʦʒʒ ... ʔ ʮʒʒ templates ʔ ʔ ʦʒʒ ... ʔ ʦʒʒ views ʔ ʦʒʒ ... ʦʒʒ web ʮʒʒ ...
  9. lib/ ʮʒʒ config ʔ ʦʒʒ mapping.rb ʮʒʒ project_name ʔ ʮʒʒ

    entities ʔ ʔ ʦʒʒ user.rb ʔ ʮʒʒ mailers ʔ ʔ ʦʒʒ templates ʔ ʦʒʒ repositories ʔ ʦʒʒ user_repository.rb ʦʒʒ project_name.rb
  10. lib/ ʮʒʒ config ʔ ʦʒʒ mapping.rb ʮʒʒ project_name ʔ ʮʒʒ

    entities ʔ ʔ ʦʒʒ user.rb ʔ ʮʒʒ mailers ʔ ʔ ʦʒʒ templates ʔ ʦʒʒ repositories ʔ ʦʒʒ user_repository.rb ʦʒʒ project_name.rb
  11. lib/ ʮʒʒ config ʔ ʦʒʒ mapping.rb ʮʒʒ project_name ʔ ʮʒʒ

    entities ʔ ʔ ʦʒʒ user.rb ʔ ʮʒʒ mailers ʔ ʔ ʦʒʒ templates ʔ ʦʒʒ repositories ʔ ʦʒʒ user_repository.rb ʦʒʒ project_name.rb
  12. lib/ ʮʒʒ config ʔ ʦʒʒ mapping.rb ʮʒʒ project_name ʔ ʮʒʒ

    entities ʔ ʔ ʦʒʒ user.rb ʔ ʮʒʒ mailers ʔ ʔ ʦʒʒ templates ʔ ʦʒʒ repositories ʔ ʦʒʒ user_repository.rb ʦʒʒ project_name.rb
  13. hanami - base repository, CLI router - Rack compatible HTTP

    router for Ruby controller - Full featured and fast actions for Rack utils - Ruby core extensions and class utilities model - Persistence with entities and repositories
  14. validations - Validations mixin for Ruby objects helpers - View

    helpers for Ruby applications view - Presentation with a separation between views and templates assets - Assets management for Ruby mailer - Mail for Ruby applications
  15. # hanami class HelloApp def call(env) [200, {}, ['Hello!']] end

    end router = Hanami::Router.new router.get '/', to: 'hello_app'
  16. class InstitutionsController < ApplicationController load_and_authorize_resource :only => [:destroy,:edit,:new,:create,:update] before_filter :authenticate_user!,

    :except => [:student_registration, :show, :validate_registration_pin, :result, :admission, :buy_registration_pin,:paygate_callback_fai lure, :paygate_cancel, :paygate_pending, :paygate_callback_success, :pin_transaction_info_print] before_filter :find_institution, :except => [:show,:index, :new, :create, :semesters_for_institute_type, :start_end_date_for_assessment_period, :courses_for_batch, :pa ygate_callback_failure, :paygate_cancel, :paygate_pending, :paygate_callback_success, :pin_transaction_info_print] before_filter :add_bread_crumb,:except => [:show] def paygate_callback_success @pay_gate_config = YAML::load(File.open("#{Rails.root}/config/pay_gate_config.yml"))[Rails.env] @payment = TransactionRecord.find_by_order_number(params[:OrderID]) uri = URI("https://fidelitypaygate.fidelitybankplc.com/cipg/MerchantServices/UpayTransactionStatus.ashx") parameters = {:MERCHANT_ID => "#{@pay_gate_config['merchant_id']}", :ORDER_ID => "#{@payment.order_number}"} uri.query = URI.encode_www_form(parameters) result =open(uri).read result_hash = Hash.from_xml(result) record_payment_details(result_hash) if result_hash["CIPG"]["StatusCode"] == PaymentRecord::PAYMENT_SUCCESS_CODE if @payment.transactionable_type.eql?("PaymentRecord") redirect_to institution_fees_path(@payment.transactionable_type.fee.institution), :notice => "Payment transaction has been #{result_hash['CIPG']['Status']}" elsif @payment.transactionable_type.eql?("PinBuyerInfo") unless @payment.transactionable.pin_id.present? @registration = @payment.transactionable.registration @valid_registration_pin_groups = @registration.valid_registration_pin_groups @online_valid_registration_pin_groups = @valid_registration_pin_groups.where(:pin_available_type => 'Online') @offline_valid_registration_pin_groups = @valid_registration_pin_groups.where(:pin_available_type => 'Offline') @available_pin = nil @online_valid_registration_pin_groups.each do |vpg| if vpg.available_pins.present? @available_pin = vpg.available_pins.first break else next end end if !@available_pin.present? @offline_valid_registration_pin_groups.each do |vpg| if vpg.available_pins.present? @available_pin = vpg.available_pins.first break else next
  17. class InstitutionsController < ApplicationController load_and_authorize_resource :only => [:destroy,:edit,:new,:create,:update] before_filter :authenticate_user!,

    :except => [:student_registration, :show, :validate_registration_pin, :result, :admission, :buy_registration_pin,:paygate_callback_fai lure, :paygate_cancel, :paygate_pending, :paygate_callback_success, :pin_transaction_info_print] before_filter :find_institution, :except => [:show,:index, :new, :create, :semesters_for_institute_type, :start_end_date_for_assessment_period, :courses_for_batch, :pa ygate_callback_failure, :paygate_cancel, :paygate_pending, :paygate_callback_success, :pin_transaction_info_print] before_filter :add_bread_crumb,:except => [:show] def paygate_callback_success @pay_gate_config = YAML::load(File.open("#{Rails.root}/config/pay_gate_config.yml"))[Rails.env] @payment = TransactionRecord.find_by_order_number(params[:OrderID]) uri = URI("https://fidelitypaygate.fidelitybankplc.com/cipg/MerchantServices/UpayTransactionStatus.ashx") parameters = {:MERCHANT_ID => "#{@pay_gate_config['merchant_id']}", :ORDER_ID => "#{@payment.order_number}"} uri.query = URI.encode_www_form(parameters) result =open(uri).read result_hash = Hash.from_xml(result) record_payment_details(result_hash) if result_hash["CIPG"]["StatusCode"] == PaymentRecord::PAYMENT_SUCCESS_CODE if @payment.transactionable_type.eql?("PaymentRecord") redirect_to institution_fees_path(@payment.transactionable_type.fee.institution), :notice => "Payment transaction has been #{result_hash['CIPG']['Status']}" elsif @payment.transactionable_type.eql?("PinBuyerInfo") unless @payment.transactionable.pin_id.present? @registration = @payment.transactionable.registration @valid_registration_pin_groups = @registration.valid_registration_pin_groups @online_valid_registration_pin_groups = @valid_registration_pin_groups.where(:pin_available_type => 'Online') @offline_valid_registration_pin_groups = @valid_registration_pin_groups.where(:pin_available_type => 'Offline') @available_pin = nil @online_valid_registration_pin_groups.each do |vpg| if vpg.available_pins.present? @available_pin = vpg.available_pins.first break else next end end if !@available_pin.present? @offline_valid_registration_pin_groups.each do |vpg| if vpg.available_pins.present? @available_pin = vpg.available_pins.first break else next
  18. # rails class String def pluralize # ... end end

    # hanami module Hanami module Utils class String def pluralize # ... end end end end Utils
  19. Controller test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

    } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end
  20. Controller test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

    } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end
  21. Controller test describe Web::Controllers::Board::Index do let(:action){ Board::Index.new } let(:params){ Hash[]

    } it 'is successful' do response = action.call(params) response[0].must_equal 200 end end
  22. TDD

  23. TDD

  24. sinatra vs grape vs hanami (JSON) 0 1250 2500 3750

    5000 req/s 4 127 1 703 2 739 sinatra grape hanami
  25. rails vs hanami 0 200 400 600 800 req/s 735

    384 653 54 rails(view) hanami(view) rails(json) hanami(json)