Gemnasium の Rubygems Monthly

GemnasiumRubygems Monthly というレポートを毎月出してくれるようになりました。

Gemnasium 自体はとても便利で、利用している Rubygems の更新を通知してくれるやつです。このMontylyは自分が使っていない主要なGemについても教えてくれるので、これはなかなか良さそうです。

ざっと

見て見ました。詳細リンクなどがあるので、できれば原文を見てください。

Sinatra2

Sinatra2 が出たんですね。
sinatra/mustermann: your personal string matching expert
というrouterを使っているようです。

Bundler 1.15.x

色々機能追加されているようでしたので、合わせて以下のchangelogも見て見ました。
bundler 1.15.0.pre.1 - Gemnasium

Features:

  • print a notification when a newer version of bundler is available (#4683, @segiddins)
  • add man pages for all bundler commands (#4988, @feministy)
  • add the bundle info command (@fredrb, @colby-swandale)
    そんなに有難い情報ではないですが、以下のようなものが見れます。
$ bundle info rails
  * rails (5.1.1)
    Summary: Full-stack web application framework.
    Homepage: http://rubyonrails.org
    Path: /Users/rochefort/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rails-5.1.1
  • all files created with bundle gem comply with the bundler style guide (@zachahn)
    bundler style guide って何か公開されているものがあるのかと思ったら、
    Lint newgem templates by zachahn · Pull Request #5499 · bundler/bundler
    rubocop.yml に準拠してファイル生成しますってことみたい。
  • if installing a gem fails, print out the reason the gem needed to be installed (#5078, @segiddins)
  • allow setting gem.push_key to set the key used when running rake release (@DTrierweiler)
  • print gem versions that are regressing during bundle update in yellow (#5506, @brchristian)
  • avoid printing extraneous dependencies when the resolver encounters a conflict (@segiddins)
  • add the bundle issue command that prints instructions for reporting issues (#4871, @jonathanpike)
    InstuctionとともにEnvironment や 設定情報を出力。
  • add –source and –group options to the bundle inject command (#5452, @Shekharrajak)
  • add the bundle add command to add a gem to the gemfile (@denniss)
    これは結構使えそう。コメントはなくてもいい気がしますが。
$ bundle init
$ bundle add rails
$ cat Gemfile
# frozen_string_literal: true
source "https://rubygems.org"

# gem "rails"

# Added at 2017-06-10 13:37:06 +0900 by rochefort:
gem "rails", "~> 5.1"
  • add the bundle pristine command to re-install gems from cached .gem files (#4509, @denniss)
    cacheから再インストール。
  • add a –parseable option for bundle config (@JuanitoFatas, @colby-swandale)
$ bundle config --parseable
jobs=4
gem.coc=false
gem.mit=false
gem.test=false
build.nokogiri=--with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
build.mysql2=--with-opt-lib=/usr/local/opt/openssl/lib --with-opt-include=-I/usr/local/opt/openssl/include

RuboCop 0.49.x

–parallel オプションが追加になったのとsecurity対策がされたようです。
rubocop に security なんてあんのかと思ったら、/tmp/$uid/ 以下にキャッシュファイルを保存しているようで
悪意のあるユーザにこれが改ざんされる可能性があるとのこと。

CanCanCan 2

古いバージョンのRailsRubyをサポート対象外。Sequel と Mongoidも対象外。
(使って見たいけど)使っていないので、軽く眺めて終わり。

Devise 4.3.0

Support for Rails 5.1

Puma 3.9.0

USR1/USR2 シグナルでrestartができるようになった。
最大スレッド数より多くのクライアントを受け入れなくなった。

ActsAsTaggableOn 5

Ruby 2.2.7 以上をサポート、ActiveRecord 4.2未満をサポート対象外。

administrate のラベルを日本語化する

今日もthoughtbot/administrate tipsです。
 
default_locale を ja に変更すると、一部日本語化されますが、各columnのラベルはそのままです。
ちなみに、default の locales は以下。
administrate/config/locales at master · thoughtbot/administrate

ソース

githubを見てもよくわからなかったのでソースをのぞいてみると、

# administrate-ceae08ca855b/app/views/administrate/application/_collection.html.erb

        <%= t(
          "helpers.label.#{resource_name}.#{attr_name}",
          default: attr_name.to_s,
        ).titleize %>

となっていたので、 hepers.label 以下に定義してやればok。

対応

# config/locales/ja.yml
ja:
  helpers:
    label:
      player:
        main_image_url: 画像
        name: 名前
        catchphrase: キャッチフレーズ
        age: 年齢
        Tall: 身長
        created_at: 更新日
        updated_at: 更新日

Active Record の attributes と同一の場合は、マージ <<: *attributes を使って一元管理するのが良いでしょう。

See Also

Rails管理画面生成gem administrate を使ってみる - rochefort’s blog

Rails管理画面生成gem administrate でソート順を指定する

Dashboardのソート順を変更したいと思ったのですが、どうやらそれを設定するための機能は用意されていないようでした。
少し調べてみると、以下のissueで議論されていました。
Default order/sort of lists · Issue #442 · thoughtbot/administrate

対応方法

get parameter で制御すれば良いだけですので、更新日付の昇順で表示したい場合、以下のようになります。

module Admin
  class ArticlesController < Admin::ApplicationController
    before_action :default_params

    # def index
    #   super
    #   @resources = Article.
    #     page(params[:page]).
    #     per(10)
    # end

    def default_params
      params[:order] ||= "updated_at"
      params[:direction] ||= "desc"
    end
  end
end

See Also

Rails管理画面生成gem administrate を使ってみる - rochefort’s blog