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
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
make your own gem
Step by step process for building your own gem including two examples
mmr
December 19, 2013
More Decks by mmr
See All by mmr
rails decorators
mribica
0
83
emberjs
mribica
1
230
Other Decks in Programming
See All in Programming
Composerを使ったサプライチェーン攻撃の様子を眺めてみる #phpstudy
o0h
PRO
2
240
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
190
ふつうのFeature Flag実践入門
irof
7
3.7k
Claspは野良GASの夢をみるか
takter00
0
180
New "Type" system on PicoRuby
pocke
1
830
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
190
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4k
Contextとはなにか
chiroruxx
1
290
Agentic UI
manfredsteyer
PRO
0
140
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
570
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
250
Building Applications with DynamoDB
mza
96
7.1k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.5k
Exploring anti-patterns in Rails
aemeredith
3
400
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.5k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
First, design no harm
axbom
PRO
2
1.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
140
Balancing Empowerment & Direction
lara
6
1.2k
Test your architecture with Archunit
thirion
1
2.3k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
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