scalar型を新しく定義するためにはscalarキーワードを使います。例えば、Date型を新しく定義するには次のようにします。 scalar Date スキーマではこれだけですが、実際に使う際はGraphQL処理系に対してさらにシリアライズとデシリアライズを定義することになります。 GraphQL組み込みのscalar型は先にあげたものだけなので、例えばバイナリ、日付と時刻、HTML/XML、BigIntなどを必要に応じて追加することになるでしょう。ただしその場合、サーバーサイドとクライアントサイドでシリアライズ・デシリアライズの実装を一致させる必要があります。 Enum enum(イナム)はscalar型の一種で、特定の値のみを持つ型です。例えば、組み込みscalar型であるBooleanをenumで宣言すると次のようになるでしょう。 enum Boolean { true false
This page shows you how to do the following: Create a Hello World app. Package the app into a container image using Cloud Build. Create a cluster in Google Kubernetes Engine (GKE). Deploy the container image to your cluster. The sample is shown in several languages, but you can use other languages in addition to the ones shown. To follow step-by-step guidance for this task directly in the Cloud Sh
こんにちは。メドピアのRuby(Rails)化をお手伝いしている@willnetです。最近はよくリファクタリングをしています。 今回は、最近僕がリファクタリングしている内容についてまとめようと思います。 メドピアではFat Model/Controllerを避けるために、rubocopの設定を利用しクラスの行数が300行以下になるよう制限しています*1。最近300行を超えるモデルが出てきたので、一部の処理を別のクラスに切り出し始めました。 このとき、Railsが提供している機能であるconcernsを利用すると楽に行数を減らすことができますが、それだとrubocopの指摘を回避できるという意味しかないので、なるべく委譲(composition)を利用して処理を別クラスに移していっています*2。 複数モデルにまたがる処理を切り出す Railsアプリケーションを書いていると、複数のモデルを一度
if your application uses root as your database username; you’re doing it wrong. a good practice is you should have two users for your application. let say i have a database called blog_production, i will have two users in my database: blog and blog_admin. the former will be use for regular stuff, and the latter for database administration. each db user have diffrent set of privileges. blog user pr
Optimizing Rails for Memory Usage Part 3: Pluck and Database Laziness This is part three in a four-part series on optimizing a potentially memory-heavy Rails action without resorting to pagination. The posts in the series are: Part 1: Before You Optimize Part 2: Tuning the GC Part 3: Pluck and Database Laziness Part 4: Lazy JSON Generation and Final Thoughts Pluck the Chicken If changing Ruby’s GC
In programming language terms, “laziness” refers to code whose evaluation is delayed until the last possible moment. This strategy can have several benefits. For example: nums = (1..1_000_000).lazy squares = nums.map { |x| x * x } squares.take_while { |x| x < 100 }.to_a #=> [1, 4, 9, 16, 25, 36, 49, 64, 81]In this (contrived) example, since we're using a lazy enumerator, we never actually calculat
Come with me on a journey through the internals of Rails, as we trace a request from the web server to the controller action method, and follow the response back again. This will give you a glimpse of how Rails works under the hood, hopefully exposing some of the “magic” of the framework. We will also get to see some of the design/architectural decisions at the core of Rails. This analysis was con
Rails 5 has added some nice enhancements to Active Support. This blog will go over some of those changes. Improvements in Date, Time and Datetime prev_day and next_day As the name of the methods suggests, next_day returns next calendar date. Similarly, prev_day returns previous calendar date. 1 2Time.current 3=> Fri, 12 Feb 2016 08:53:31 UTC +00:00 4 5Time.current.next_day 6=> Sat, 13 Feb 2016 08:
Myron Marston » New in RSpec 3: Composable Matchersの訳です。 あかんところあったらTwitterで@nilp_までお願いします RSpec 3の、最も大きな新機能が3.0.0.beta2で公開されました: コンポーザブルマッチャ(組み合わせ可能なマッチャー)です。 これにより強力で壊れづらい検証を書けるようになり、新たな可能性が開けました。 例 RSpec 2.xでは、私はこのようなコードを度々書いてきました。 class BackgroundWorker attr_reader :queue def initialize @queue = [] end def enqueue(job_data) queue << job_data.merge(:enqueued_at => Time.now) end end describe Back
前回からの続き。 ところで、最近のRubyは{abc:123}({:abc => 123}と同等)のようなハッシュ定義も可能になり、間違いなくシンボルキーが多用される時代なのに... with_indifferent_accessは、なぜ文字列キーを使うのか? シンボルは無駄にオブジェクトを生成しない。 コード中に:fooがいくつあっても、たった一つの:fooオブジェクトを参照するだけ。 irb(main):001:0> :foo.object_id => 538568 irb(main):002:0> :foo.object_id => 538568 irb(main):003:0> :foo.object_id => 538568 オブジェクトIDがすべて538568。同じである。 一方、文字列は何度も異なるオブジェクトを生成する。 コード中に"foo"が出現する度に、異なる"foo"
ひとでさんのこの前のYAPCでの発表(ベストスピーカーおめでとうございます)の はてなブログではドメイン駆動など使ってイケてるサービスを作り続けているぜっていう話、 オブジェクト指向やらドメイン駆動の話とかいろいろあったけれども、 結局のところイケてるサービスを作り続けるためには継続的にコードベースも良くしていかなければいけない っていうメッセージがあったのだったのだと勝手に解釈していてすごい共感している。 エリック・エヴァンスの本自体買って中途半端に読んで読みっぱなしなので、 ドメイン駆動設計については何も意見できるところはまだない。 でも最近思うのが、複雑な仕様を手続き的に実装すると確実に複雑なままになってしまうので、 やっぱりビジネス上に現れるルールは単語で表現してコードに起こすという作業をしないと ダメだと思って、ここ数日過去に作ったコードに手を加えるついでに大幅に書き直している。
← back to all talks and articles FactoryGirl Tips and Tricks FactoryGirl is an awesome fixture replacement library that gives you a lot of power and flexibility, at the cost of more code to maintain and increased mental overhead. It pays get to know it, so you can wield its flexibility to improve your tests and your productivity. Get the most out of FactoryGirl 1. Use traits for modular factories
みなさん、こんにちは。 ウェブ・サーバーサイドを担当しています、Railsエンジニアの黒田です。 マネーフォワードも早いもので、サービスインしてから2年以上が経過しました。 サービスをご愛顧してくださっている皆様には、心から感謝しております。 さて、今回のエンジニアブログは「リファクタリング」についてです。 マネーフォワードのように、ユーザーファースト&デリバリー優先で爆速開発を進めていると、サービスとしてはイケてても、コード的にイケてるとは言い難い部分が発生してしまいがちです。 「思いやりのないコード」「可読性が悪いコード」「必要以上に複雑なコード」は、バグ発生率を高め、開発スピードを低下させ、何よりエンジニアの気分を憂鬱にさせてしまいます。。。 マネーフォワードでは継続的かつ積極的にリファクタリングの時間を創る取組みをしていますが、そのなかで今回はRailsのリファクタリングでとても便
Programmers make mistakes. Some of them are just annoying (for others to read) and some are really dangerous. Here is my selection of 10 mistakes done by Ruby / Ruby on Rails developers. These tips are easy to follow and can save you much time of later debugging. 1. Double negative and complex conditionals if !user.nil? # ... end unless user.blank? # ... end unless user.active? || address.confirme
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く