Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
後方互換の保ち方 / How to Maintain Compatibility
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Katsuya Hidaka
June 30, 2018
Programming
1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
後方互換の保ち方 / How to Maintain Compatibility
松江Ruby会議09 セッション#4
Katsuya Hidaka
June 30, 2018
More Decks by Katsuya Hidaka
See All by Katsuya Hidaka
HTML帳票 / Frontend Study Group in Sannin 3rd
hidakatsuya
0
3.3k
2006-2016 Ruby, OSS, Thinreports/matsue-rubykaigi08-LT
hidakatsuya
0
540
prpr でプルリクエスト運用を自動化する /Introduction-of-prpr
hidakatsuya
0
3.8k
AgileJapan2016 Shimane Session2-2
hidakatsuya
0
2.3k
Introduction of Thinreports for PHP
hidakatsuya
0
6.6k
Other Decks in Programming
See All in Programming
Lessons from Spec-Driven Development
simas
PRO
0
240
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.7k
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
620
Vite+ Unified Toolchain for the Web
naokihaba
0
410
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.7k
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
220
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
420
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.6k
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
120
どこまでゆるくて許されるのか
tk3fftk
0
290
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
250
1B+ /day規模のログを管理する技術
broadleaf
0
120
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
320
Embracing the Ebb and Flow
colly
88
5.1k
From π to Pie charts
rasagy
0
220
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.2k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Test your architecture with Archunit
thirion
1
2.3k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
Transcript
後⽅互換の保ち⽅ 松江Ruby会議09
⽇⾼ 克也 @hidakatsuya Misoca松江オフィス勤務 サーバサイド⽅⾯(主にRuby) Thinreports 開発者
Thinreports • Ruby向けのPDF⽣成ツール • OSS • Thinreports Editor - レイアウトを作成するデスクトップアプリ
• Thinreports Generator for Ruby - レイアウトからPDFを作る gem
hello_world.tlf require 'thinreports' report = Thinreports::Report.new layout: ‘hello_world.tlf' report.start_new_page do
|page| page.item(:world).value = 'World' end report.generate filename: ‘hello_world.pdf’ PDF
History • 2010年 0.6.0 プレビュー版リリース • 2011年 0.7.0 最初の安定版 •
2012年 Fukuoka Ruby Award 2012 で⼤賞受賞 • 2015年 0.8.0 リリース • 2015年 Thinreports for PHP がリリース • 2016年 0.9.0 リリース - レイアウトファイル (*.tlf) の仕様を⼤幅に変更 • 2017年 0.10.0 リリース
For PHP, Java, Go • https://github.com/thinreports-php/thinreports-php • https://bitbucket.org/symfo/thinreports-java • https://github.com/naofum/thinreports-java
• https://github.com/renatosuero/thinreports-go
0.8 to 0.9 • レイアウトファイル (*.tlf) の内部構造を⼤幅に変更 • 互換性を壊す変更 •
このときにどう対応したか • 以降、古い仕様を 0.8 ver、新しい仕様を 0.9 ver と呼称
0.8 ver tlf 1: { 2: "version": "0.8.2", 3: "config":
{ 4: "title": "Report Title", 5: "page": { 6: "paper-type": "A4", 7: "orientation": "landscape", 8: "margin-top": 0.0, 9: "margin-bottom": 0.0, 10: "margin-left": 0.0, 11: "margin-right": 0.0, 12: } 13: }, 14: "svg": "<svg><g class=\"canvas\"><rect x- id=\"rect_id\" x=\"100.0\" y=\"100.0\" width=\"200\" height=\"200\"/>...</ g></svg>" 15: }
Ploblems for 0.8 ver • 変更箇所の Diff が全くわからない • Editor
の実装に強く依存していて、仕様変更が困難 • 構造や属性の仕様がわかり⾟いし、扱いにくい - サードパーティにも広がらない
0.9 version • すべてをJSONで表現 • Editor の依存を排除 • Diff も⼀⽬瞭然
• ⼈間が読める • その後の開発が断然や りやすくなった { "version": "0.10.0", "items": [ { "type": "text", "display": true, "x": 210.6, "y": 55, "width": 174, "height": 48, "style": { "font-family": ["IPAGothic"], "font-size": 24, "color": "#000000", "text-align": "center", "vertical-align": "middle", "font-style": [] }, "texts": ["ݟੵॻ"] }, { "id": "recipient_name", "type": "text-block", "display": true, :
⽅針: 後⽅互換を保つ • 0.8 ver の tlf は Generator v0.9
でもそのまま利⽤できる • 0.8 ver の tlf は Editor v0.9 でも編集でき保存できる - 保存すると 0.9 ver の tlf になる
Generator v0.9 • 0.9 ver の tlf で PDF ⽣成できるように書き換える
• tlf が 0.8 ver の場合は 0.9 ver に変換してから扱う - 0.8 ver to 0.9 ver にコンバートするクラスを追加
Thinreports::Layout:: LegacySchema 1: def initialize(legacy_schema) 2: @legacy_schema = legacy_schema 3:
: 4: end 5: 6: def upgrade 7: config = legacy_schema['config'] 8: page_config = config[‘page'] 9: 10: { 11: 'version' => legacy_schema['version'], 12: 'title' => legacy_schema['config']['title'], 13: 'report' => { 14: 'paper-type' => page_config['paper-type'], 15: 'width' => page_config['width'].to_f, 16: 'height' => page_config['height'].to_f, 17: : 18: }, 19: 'items' => item_schemas 20: } 21: end 22: 23: private 24: :
Thinreports::Layout::Format 1: def self.build(filename) 2: schema = JSON.parse(read_file(filename)) 3: version
= Layout::Version.new(schema['version']) 4: 5: unless version.compatible? 6: raise Errors::IncompatibleLayoutFormat.new( 7: filename, schema['version'], 8: Layout::Version.compatible_rules.join(' and ') 9: ) 10: end 11: 12: if version.legacy? 13: warn ‘[DEPRECATION] ...’ 14: schema = Layout::LegacySchema.new(schema).upgrade 15: end 16: 17: new schema #=> Thinreports::Layout::Format 18: end
Design • 0.8 ver に関する知識と責務を集約 • 0.8 ver の tlf
に関するコードを排除 - 条件分岐は最⼩限にしたい • 考えることを増やさない - 以降の実装がやりやすい • テスト書きやすい
thinreports-cli gem • Editor 0.9 で⼀個ずつ開いて保存して変換→⾟いとの声 • 0.8 ver の
tlf を 0.9 ver に変換できるコマンドを作った $ thinreports upgrade /path/to/0.8.tlf /path/to/0.9.tlf
Reuse 1: module Thinreports 2: module Cli 3: module Commands
4: class Upgrade 5: def initialize(source_path, destination_path) 6: @source_path = Pathname.new(source_path) 7: @destination_path = Pathname.new(destination_path) 8: end 9: 10: def call 11: source_schema = load_source_schema 12: destination_path.write(upgrade_schema(source_schema), encoding: 'UTF-8') 13: end 14: 15: private 16: 17: attr_reader :source_path, :destination_path 18: 19: def upgrade_schema(source_schema) 20: upgraded_schema = Thinreports::Layout::LegacySchema.new(source_schema).upgrade 21: JSON.pretty_generate(upgraded_schema) 22: end 23: :
Future of Thinreports • Custom Font (WIP) - 任意のフォントが使えるようになる -
だいたいできてる - https://github.com/thinreports/thinreports/issues/5 • Section Report (WIP) - 新しいレポート形式 - より柔軟に動的なレイアウトが作れるようになる - https://github.com/thinreports/thinreports/issues/7
end