Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
make your own gem
Search
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
84
emberjs
mribica
1
240
Other Decks in Programming
See All in Programming
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
160
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.2k
AHC070解法紹介
eijirou
0
130
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
270
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
800
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
330
The Rails Doctrine Decade
koic
2
370
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
120
速習iPhone Duo対応
yuukiw00w
2
730
App Intentsのビルドプロセスを支える技術
kntkymt
0
430
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
190
Featured
See All Featured
Designing for Timeless Needs
cassininazir
1
500
We Have a Design System, Now What?
morganepeng
55
8.3k
Embracing the Ebb and Flow
colly
88
5.2k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.3k
It's Worth the Effort
3n
188
29k
GitHub's CSS Performance
jonrohan
1033
470k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
How GitHub (no longer) Works
holman
316
150k
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