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
make your own gem
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
mmr
December 19, 2013
Programming
0
110
make your own gem
Step by step process for building your own gem including two examples
mmr
December 19, 2013
Tweet
Share
More Decks by mmr
See All by mmr
rails decorators
mribica
0
80
emberjs
mribica
1
220
Other Decks in Programming
See All in Programming
Ruby and LLM Ecosystem 2nd
koic
1
500
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
530
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
240
猫の手も借りたい!ので AIエージェント猫を作って社内に放した話 Claude Code × Container Lambda の Slack Bot "DevNeko"
naramomi7
0
260
Ruby x Terminal
a_matsuda
7
590
LangChain4jとは一味違うLangChain4j-CDI
kazumura
1
170
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.3k
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
220
エージェント開発初心者の僕がエージェントを作った話と今後やりたいこと
thasu0123
0
240
ロボットのための工場に灯りは要らない
watany
10
2.6k
go directiveを最新にしすぎないで欲しい話──あるいは、Go 1.26からgo mod initで作られるgo directiveの値が変わる話 / Go 1.26 リリースパーティ
arthur1
2
530
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
190
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
680
The Mindset for Success: Future Career Progression
greggifford
PRO
0
270
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
A Soul's Torment
seathinner
5
2.4k
Designing Powerful Visuals for Engaging Learning
tmiket
0
270
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
100
Darren the Foodie - Storyboard
khoart
PRO
3
2.8k
Google's AI Overviews - The New Search
badams
0
930
SEO for Brand Visibility & Recognition
aleyda
0
4.3k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
150
The untapped power of vector embeddings
frankvandijk
2
1.6k
Transcript
ruby gems proces pravljenja i korisni paterni
Sadrzaj • struktura i proces kreiranja gem-a • short-url •
gitshot • https://github.com/mribica
Struktura % short-url . |__short-url.gemspec |__lib/ |__short-url/ |__short-url.rb
gemspec • specifikacija gem-a • osnovne informacije (naziv, opis, autor)
• verzija • specifikacija datoteka koje ce biti ukljucene u gem • specifikacija izvrsnih skripti
% short-url.gemspec Gem::Specification.new do |s| s.name = 'short-url' s.version =
'0.0.1' s.date = '2012-11-22' s.summary = "short url generator" s.description = "short url generator using bit shuffle" s.authors = ["Muamer Ribica"] s.email = '
[email protected]
' s.files = ["lib/short_url.rb"] s.homepage = 'http://www.github.com/mribica/short-url' s.license = 'MIT' end
Buildanje i instalacija • $ gem build short-url.gemspec • $
gem install ./short-url-0.0.1.gem • $ gem push ./short-url-0.0.1.gem • ... login • gem install short-url (sa rubygems.org)
short-url gem • generisanje nepredvidivih, jedinstvenih kljuceva • class i
instance metode za generisanje kljuca • konfigurabilan modul (initializer)
# short_url.rb module ShortUrl ... end # test.rb class Test
include ShortUrl end Test.short_url(2) Test.new.short_url
class i instance metode
module ShortUrl def self.included(base) base.extend(ClassMethods) end def short_url # instance
metoda end module ClassMethods def short_url(id) # class metoda end end end
konfigurabilan modul
• konfiguracija modula (alfabet, duzinu kljuca) • gdje cuvati konfiguraciju
(izolovanje) • cattr_accessor (Rails kroz ActiveSupport) • class varijabla u modulu
Meta klasa
• u ruby-u je sve objekat • svaki objekat ima
klasu • svaki objekat ima i meta klasu • meta klasa moze imati metode, koje su dostupne samo toj instanci
module Test class << self # self je sada meta
klasa modula attr_accessor :configuration end def self.configure self.configuration |= Configuration.new yield(configuration) end end # bilo gdje u aplikaciji Test::configure {|config| config.attr = ‘foo’} Test::configuration # => configuration obj
• konfiguracija je sada izolovana samo na modul • modul
se moze konfigurisati iz initializera • klasa koja ukljuci modul dobija samo metode koje ce koristiti
gitshot gem • slika nakon svakog komita • jednostavna instalacija
i inicijalizacija skripte • % gem install gitshot • gitrepo% gitshot install
gemspec executable Gem::Specification.new do |s| ... s.default_executable = %q{gitshot} s.executables
= ["gitshot"] ... end
require 'fileutils' module Gitshot class Hook HOOK_PATH = '.git/hooks/post-commit' def
install tmpl = File.expand_path("hook-templ", _FILE_) FileUtils.cp(tmpl, HOOK_PATH) FileUtils.chmod(0755, HOOK_PATH) end end end
gitrepo% gitshot install Gitshot installed .git/hooks/post-commit gitrepo% git commit -am
“commit” [Cheese!] Capturing image from device "Built-in iSight" b2bc7.jpeg