GitHub Pages ã使ãå§ãããã¨
ããã°ãå¢ãï¼ã¦ï¼ã¾ããã
çç±ï¼ãã¤ã使ã£ã¦ããã¨ãã£ã¿ï¼èªåã®å ´åã¯Vimï¼ã§æ¥è¨ãæ¸ãããã£ãã
ãã¾ãã«ãããã¹ãã¨ãªã¢ã§ã®æç« ç·¨éï¼ã¨ã¯ã¦ãªè¨æ³ï¼ã身ã«ã¤ããªãã®ã§ãããã«æ¥è¨ã楽ã«æ¸ããã追æ±ããäºå®ãã¾ãã¯ãã¿ã¼ããã«ããç°¡åã«è¨äºãæ¸ãããã®ãã¼ã«ãã¤ãã£ãã$EDITORã使ã£ã¦ã¿ã¼ããã«ä¸ã§è¨äºãç·¨éã»ãã¬ãã¥ã¼ã»å ¬éã¾ã§ã§ããCUIåããã¼ã«ã
GitHub - hibariya/retter: A diary workflow for shell users
ãã¦ããåç¥ã®æ¹ãå¤ãã¨æãã¾ãããä¸ã®ä¸ã«ã¯ Octopress ã¨ããç´ æ´ããããã¼ã«ãããã¾ããåã¯Retterã®éçºéä¸ã§Octopressã®åå¨ã«æ°ã¥ãã¦ãã¾ã£ãã*1
ä½ã£ã¦ãã¾ã£ããã®ã¯ä»æ¹ããªãããã©ãã¾ã§ã®ãã®ãä½ããã¨ãã§ãããã試ãããã®ã§ããã°ããã¯é»ã ã¨éçºãç¶ãããã¨æãã¾ããããããªã©ã¯å°ããªãã®ãã大ããªãã®ã¾ã§åãä»ãã¦ããã¾ãã
*1:ãã¡ããRetterã«ãåªãã¦ããç¹ãããã¾ãããã®ãã¼ã«ã¯retterã¨ããã³ãã³ãã§æä½ããã®ã§ãããã³ãã³ãèªä½ã¯çæã ãã§æã¦ã¦ãã¾ããããã¨ã¦ãæã«ããããã§ãã
Railsåå¼·ä¼@æ±äº¬ç¬¬63åã§ã»ãã·ã§ã³ãªã¼ãã¼ã¨ããã®ããã£ããã¨
ããæ°ã¶æéãè¡ããè¡ããã¨æãã¤ã¤ä¸ã ãããªãã£ã Rails' Wiki - Rails勉強会@東京第63回 ã«è¡ã£ã¦ãããä»å㯠RubyKaigi Advent Calendar 2011 | 日本Ruby会議2011(7月16日〜18日) ã®ã¤ãã³ãã®ã²ã¨ã¤ã§ãããã®ã§ããã
ä¹
ã
ã®åå ã§é
å»ãããã§ãããçãã¦æ©ã
ã« [twitter:@takkanm] ããã«ãRails3.1ã®ã»ãã·ã§ã³ãã£ã¦ãã¨æåããããããããã¤ãã³ãã§é·æé話ããçµé¨ã¯ç¡ãããä½ãããã¹ããªã®ãã¼ãããã¨ããåãã£ã¦ããªãã£ãã®ã§ãçµæ§å°æããããã®æç¹ã§ææ°ã®Railsãããã·ã³ã«å
¥ãã¦ç¡ãã£ããã話ãããã¨ã¯å
¨ããªãæ°ããã¦ããã®ã§ããã
ã ãã©å¿é
ã¯ãããªãã£ã! ä»åã¯ç¶æ³ãããã£ã(ã¿ããªå²ã¨è©³ããã£ããä»)ã®ãããã¨æããã©ãäºåã«å
¥å¿µãªæºåãå¿
è¦ãªããã§ã¯ãªãã(ããã«è¶ãããã¨ã¯ãªããã©)ãç¥ããªããã¨ãããã¨ãããããããããã¯ã«ã§ããããã¦ãã»ãã·ã§ã³ãªã¼ãã¼ã¨ããã®ã¯ã¨ã¦ã好é½åãªç«ã¡ä½ç½®ãªã®ã§ãããå¨ãã®äººã¨ã ãããåããããªç«ã¡ä½ç½®ã®ã¾ã¾ã§ããããããã¨ããããããã話ã«å
¥ããããããããã£ã¦å¨ãã®äººã«èº«ãä»»ãã¦ãåãããã®ã¯å²ã¨æ¥½ããã
ã»ãã·ã§ã³ãªã¼ãã¼ã¨ããåç®ãããã¨ãåãããã®ãå½ç¶ã«ãªã£ã¦ãã¤ãã³ãã«åå ãã¦ããæãã¨ã¦ãåºã¦ãããããªã®ã§ãå¯ãããå±ã§ã·ã£ã¤ã§ãã®ãããªäººã«ã¯ã¨ã¦ãåã£ã¦ããã®ã§ã¯ãªããã¨æãã¾ããã
決ãã¦ãã¾ãããã訳ã§ã¯ãªããã©å¥½ãçµé¨ã«ãªã£ãã
ãã¨ããã®ã¨ãæãã¦ããã£ã RailsCasts on Apple Podcasts ã¯ã¨ã¦ã便å©ããã ã¨æãã¾ããã
Mongoid::Paranoiaã§è«çåé¤ããããã¥ã¡ã³ããä¸ç·ããã«åãåããã
hatena.vimã®åä½ç¢ºèªãå ¼ãã¦ã
unscoped ã§è«çåé¤ããããã®ãå¼ã£å¼µã£ã¦ããããã¨æã£ããéã£ãã
# mongoid-2.0.2/lib/mongoid/paranoia.rb <ä¸ç¥...> module ClassMethods #:nodoc: # Override the default +Criteria+ accessor to only get existing # documents. Passes all arguments up to +NamedScope.criteria+ # # Returns: # # A +Criteria+ for deleted_at not existing. def criteria(*args) super.where(:deleted_at.exists => false) end # Find deleted documents # # Examples: # # <tt>Person.deleted</tt> # all deleted employees # <tt>Company.first.employees.deleted</tt> # works with a join # <tt>Person.deleted.find("4c188dea7b17235a2a000001").first</tt> def deleted where(:deleted_at.exists => true) end end <ä¸ç¥...>
Mongoid::Paranoiaã使ãã¨criteriaãä¸æ¸ãããããã§ãããã ãã unscoped ã¨ããã¦ãã ãã ã£ãã®ãã
åé¤ããããã®ã¯ deleted ã§åãããã©ãè«çåé¤é¢ä¿ãªãåãåãããã¨ãã¯ã©ããããã ããã
module Mongoid::Paranoia::ClassMethods def with_deleted c = criteria c.selector.clear c end end
足ãã¦ãã®å ´ããã®ãã ã
ã¯ã£ã¨ãããã¨
ruby-1.9.2-p0 > 10.times.map{ 'foo' }.map{|v| puts v.object_id } 2152510320 2152510280 2152510200 2152510160 2152510120 2152510060 2152510020 2152509980 2152509920 2152509780 => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] ruby-1.9.2-p0 > (['foo']*10).map{|v| puts v.object_id } 2151828140 2151828140 2151828140 2151828140 2151828140 2151828140 2151828140 2151828140 2151828140 2151828140 => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
ãã¾ãæèãã¦ãªãã£ãã
http://doc.ruby-lang.org/ja/1.9.2/class/Array.html
æ°å¤ã¨ãSymbolã¯ã©ã¡ããåãã§object_idã¯å¤ãããªããå°ãåã«RHGãããã£ã¨ã ãèªãã ã®ã§ããã¯æ³åã§ããã
ruby-1.9.2-p0 > 10.times.map{ :urryyyy }.map{|v| puts v.object_id } 498728 498728 498728 498728 498728 498728 498728 498728 498728 498728 => [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
äºæ³ãããã£ã¦ããã£ãã
Fabricationã使ã£ã¦ã¿ã
â»2011/11/08 ã³ã¡ã³ãæ¬ã§ææãé ããç®æãå çä¿®æ£ãã¾ãããã¾ããå²ã¨å¤ãè¨äºã§ãã®ã§ææ°ã®æ å ±ã¯ Fabrication ãåç §ãããã¨ãã奨ããã¾ãã
ãããä½ã£ã¦ãã¨ããmachinistã¨machinist_mongoã使ã£ã¦ãããã§ããã試ãã«åã ããæ°ã«ãªã£ã¦ããFabricationã§æ¸ãæãã¦ã¿ã¾ãããREADMEæ¸ãã¦ãããã¨ãããã¤ãå®éã«ãã£ã¦ã¿ãã®ã§ã¡ã¢ãã¦ããã¾ããå²ã¨ä½¿ããããã£ãã§ãã
ä½ã«ä½¿ããã®
ä¸è¨ããµãã¼ããã¦ãããã§ãã®ã§ãMongoid使ãã¾ãããã£ãï¼
- Plain old Ruby objects
- ActiveRecord objects
- Mongoid Documents
使ã£ããã®
- Fabricationâ¦æ¬æ¥ã®ã¡ã¤ã³
- Fakerâ¦åãã¼ã¿ãã©ãã©ãä½ã£ã¦ããããã¤
QuickStart & 使ãæ¹
Gemfile
Rails/Mongoid/RSpec/Fabricationã§âã®ãããªçµã¿åããã§ä½¿ã£ã¦ã¾ãã
group :development, :test do gem 'rspec-rails', '>= 2.0.0.beta.22' gem 'mongoid-rspec' gem 'faker' gem 'fabrication' # <= ãã gem 'wirble' gem 'spork' end
è¨è¿°ããå ´æ
spec/fabricators.rbã«æ¸ãããspec/fabricators/*.rbã«è¤æ°ãã¡ã¤ã«ã«ãã¦æ¸ãã¦ãããã¿ããã§ããããã«ç½®ãã¦ããã°ãå¿ è¦ã«ãªã£ããåæã«å¼ã°ãã¾ããæåããèªåã§èªã¿è¾¼ãã§ããããã¨ãã¯spec/spec_helper.rbãªã©ã«æ¸ãã¾ãã
Fabricatorãæ¸ãã¦ä½¿ã£ã¦ã¿ã
spec/fabricators.rbãªã©ã«fabricatorãæ¸ãã¦ããã¾ããblueprintã¿ãããªæãã§ã
# Userã¢ãã«ã¯ãããªæãã ã¨ãã¾ã class User include Mongoid::Document field :screen_name, :type=>String field :description, :type=>String field :site, :type=>String field :gender, :type=>String end # Userã¢ãã«ã®fabricatorãä½ãã¾ã Fabricator(:user) do screen_name { Faker::Internet.user_name } description { Faker::Lorem.paragraph[0..190] } site { ['http://', Faker::Internet.domain_name].join } gender { ['male', 'female'].sort_by{ rand }.first } end
ä½ã£ãFabricatorãspecã®ä¸ã§å¥½ããªã¨ãã«å¼ã³åºãã¾ããfactorygirlãmachinistã¨åãããã«ã3éãã®å¼ã³åºãæ¹ãããã¾ãã
# ã¤ã³ã¹ã¿ã³ã¹ãä¿åãã¦è¿ã Fabricate(:user) # => #<User _id: 4cb18e0c011c0e5a2c000001, screen_name: "aidan", description: "Vel iste illo beatae maxime earum accusantium. Facilis doloremque nemo dolores perspiciatis. Eum et nisi sunt qui soluta facilis consequatur quasi. Qui sunt omnis beatae sit. Quisquam earum d", site: "http://wintheiserwunsch.com", gender: "female"> # ã¤ã³ã¹ã¿ã³ã¹ãä¿åããã«è¿ã Fabricate.build(:user) # => #<User _id: 4cb18e32011c0e5a2c000002, screen_name: "darlene", description: "Exercitationem voluptatem voluptatibus officia saepe labore earum. Voluptas ut ipsam soluta. Libero possimus eius illo soluta quo blanditiis quod. Similique ea qui reprehenderit nihil ut cons", site: "http://schiller.uk", gender: "female"> # å±æ§ã ããçæãã¦Hashã§è¿ã Fabricate.attributes_for(:user) # => {"screen_name"=>"jaylon", "description"=>"Et vitae nobis enim non. Quia sunt ipsum laboriosam. Maxime ut neque voluptatum velit est aliquam sequi qui. Eius dolorem id ut assumenda.", "site"=>"http://wuckert.uk", "gender"=>"male"}
Fabricatorã®ç¶æ¿ã¨ã
ãã§ã«ä½ã£ãã®ã¨ã¯ã¡ãã£ã¨éãã®ãã»ããã¨ãã¯ããã§ã«ããfabricatorãç¶æ¿ãããã¨ãã§ãã¾ãã:fromãã©ã¡ã¼ã¿ã«ç¶æ¿å ã®ååãå ¥ãã¦ãå¤æ´ããããã£ã¼ã«ãã®å®ç¾©ãè¨è¿°ãã¾ãã
# å¿ ãfemaleãªã²ã¨ãã»ãã Fabricator(:female, :from=>:user) do gender 'female' end
ãã¡ãããç¶æ¿ã¯ä½¿ããå¼ã³åºãã¨ãã«ç´æ¥æå®ãããã¨ãã§ãã¾ãã
# ãã¾ã ãfemaleãªã²ã¨ãã»ãã Fabricate(:user, :gender=>'female') # => {"screen_name"=>"daron", "description"=>"Aut dolor reprehenderit consequuntur nihil magni odit eveniet. A est magni nam vero praesentium. Praesentium quae perferendis mollitia. Voluptatem harum ex aperiam tempora ab nihil voluptas. ", "site"=>"http://huel.com", "gender"=>"female"}
ã¯ã©ã¹ã®æ示çãªæå®
:class_nameãã©ã¡ã¼ã¿ã§æ示çã«ã¯ã©ã¹åãæå®ãããã¨ãã§ãã¾ããè²ã ãªãã¿ã¼ã³ã§Fabricatorãã¤ããããã¨ããªã©ã¯ããã§ãã¯ã©ã¹åã¯ã·ã³ãã«ãklassãæååã§æå®ã§ãã¾ãã
# :class_name 㯠:user, User, 'User' ãªã©ã§æå®å¯ Fabricator(:invalid_user, :class_name=>:user) do screen_name 'hibariya' description 'i have no gender' end
Sequenceã§ä¸æã«ãã
Machinistã®Shamã®ãããªãã®ãç¨æããã¦ãã¾ãã*1Fabricate.sequenceã使ãã¨ãå¼ã³åºããã³ã«ã¤ã³ã¯ãªã¡ã³ãããæ°å¤ãå¾ããã¾ãããããã¯ã渡ããã®ã§æ°å¤ä»¥å¤ã®ä¸æãªä½ããã¤ãããã¨ãã§ãã¾ããFakerã«ã¯å¤§éã®åèªã¨ããã³ã¼ãä¸ã«ãã«ã£ã¨å
¥ã£ã¦ããã§ãããæ®éã«éè¤ãã¾ãã®ã§ããã¼ã¿ãä¸æã§ãªãã¨ãããªãã¨ããªã©ã¯ããã使ãã¾ãã
大ããåããã¨3ã¤ã®æ¸ãæ¹ã«ãªãããã§ãã
Fabricate.sequence(:foo_id) # å¼ã³åºããã³ã«0ããå§ã¾ãé£çªãè¿ã Fabricate.sequence(:bar_id, 1000) # å¼ã³åºããã³ã«1000ããå§ã¾ãé£çªãè¿ã Fabricate.sequence(:future){|n| n.days.since } # å¼ã³åºããã³ã«1æ¥ãã¤æªæ¥ã®æ¥ä»ãè¿ã
ãã£ãã®Userã¢ãã«ã®ä¾ã ã¨ãããªæãã«ãªãã¾ãã
# uriãscreen_nameãéè¤ãããããªã! Fabricator(:user) do screen_name { Fabricate.sequence(:screen_name){|i| [Faker::Internet.user_name, i.to_s].join } } # <= ãã description { Faker::Lorem.paragraph[0..190] } site { Fabricate.sequence(:uri){|i| ['http://', i.to_s, Faker::Internet.domain_name].join } } # <= ãã gender { %w(male female).sort_by{ rand }.first } end
on_init, init_with ã§newã«å¼æ°ã渡ã
newããã®ã«å¼æ°ãå¿ è¦ãªã¯ã©ã¹ã®fabricatorãä½ãã¨ããªã©ã«ä½¿ãã¾ã
class Site def initialize(uri) @uri = uri end end # on_initã¨init_withã§ãinitializeã«æ¸¡ãå¼æ°ãæå®ã§ãã Fabricator(:site) do on_init{ init_with(['http://', Faker::Internet.domain_name].join) } end
after_build, after_create ã³ã¼ã«ããã¯
ä¿åããåãä¿åãããã¨ã®ã³ã¼ã«ããã¯ããã£ãã¾ã§åéããã¦ãããã§ãããFabricate.buildã§ãafter_createã¯å¼ã°ããããã§ã(ã§ãsaveã¯ãããªã)ããã¯ãã°ã ã£ãããã§ãï¼https://github.com/paulelliott/fabrication/pull/36
ï¼ã
# User#fetch_recent_entries!ãsaveåã®ã¹ãããã§å¼ã³åºããã Fabricator(:foo_user, :from=>:user) do after_build {|user| user.fetch_recent_entries! } end # User#fetch_recent_entries!ãsaveå¾ã®ã¹ãããã§å¼ã³åºããã Fabricator(:bar_user, :from=>:user) do after_create {|user| user.fetch_recent_entries! } end
belongs_to, references_oneãªé¢é£ã!ã§è¡¨ç¾
belongs_to, references_oneãªé¢ä¿ã«ãããã®ã¯!ãä»ããã¨èªåçã«ä½ã£ã¦ãããããããã¹ããï¼ã¨ããã®ã¯ééãã§ã!ãä»ãããå¦ãã§é¢é£ãä½ãããã¿ã¤ãã³ã°ãå¤ããããããã§ãï¼!ãä»ããªããã°åç
§ãããã¾ã§ä½ãããªãï¼ã
Fabricator(:umbrella) do color { %w(red green blue pink violet purple).sort_by{ rand }.last } end Fabricator(:girl) do name 'unknown' umbrella! # !ãä»ããã¨å³åº§ã«é¢é£ãçæããã end
Machinist <=> Fabrication æ¯è¼è¡¨
Machinistã¨ã®éããããã使ãé ç®ã ã表ã«ãã¦ã¿ãã¨ãããªæãã§ããããã*2
Machinist | Fabrication |
---|---|
Model.blueprint do ~ end | Fabricator(:model) do ~ end |
Model.blueprint(:named_blueprint) do ~ end | Fabricator(:named_fabricator, :from=>:model) do ~ end |
Model.make | Fabricate(:model) |
Model.make_unsaved | Fabricate.build(:model) |
Model.plan | Fabricate.attribues_for(:model) |
ããæ´æ°ãã¦ãããã°ãä¸ã®æ¹ã«è¡¨ç¤ºãããRSSSããä½ã£ããã¨
詳ããã¯: http://rsss.beã使ãã¨âã®ãããªæãã«ãªãã¾ãã
http://rsss.be/hibariya
ããã¯ãªã«
- 使ã£ã¦ããããã°ãã¾ã¨ãã¦ç»é²ã§ãããããã£ã¼ã«ã®ãããªãã®
- æè¿ããæ´æ°ãã¦ããããã°ã大ããä¸ã®æ¹ã«è¡¨ç¤ºãã
- æè¿ã©ã®ããã°ãããæ´æ°ãã¦ãããã®æ¨ç§»ã表示ãã
- 使ã£ã¦ããããã°ã®ãã£ã¼ããã¾ã¨ãã¦åã
- ãã£ã¼ããåããµã¼ãã¹ãªãããã°ã§ãªãã¦ãå¯
- Twitter OAuth(Read権é)ã§ãã°ã¤ã³ããå¿ è¦ãã
èªåã«é¢é£ãã¦ãURLããã¼ã£ã¨ä¸¦ã¹ãã¿ã¤ãã®ãããã£ã¼ã«ã¨ãã§ããã¾ã使ããªããªã£ããµã¤ããä¸è¦§ããæ¶ããããã¦ç®¡çããã®ãé¢åã ãªã¼ã¨æã£ã¦ãã®ãä½ããã£ããã§ããæè¿ãã®ããããã°ä½¿ã£ã¦ãªããªã¨ããæè¿ãªããã°ãããã¦ãªããªã¼ã¨ãããããã®ãã±ã£ã¨è¦ã§åãããããªãã¼ã¸ã欲ããã£ãã®ã§ãHerokuã¨Rails3ã¨MongoDBã®åå¼·ãå ¼ãã¦ä½ã£ã¦ã¿ã*1ãæè¿Herokuãã©ãã®ããã®ã¨ããã¨ã³ããªãå¤ãã£ãåå ã¯ããã§ããã
ãã°ããããã§éçºä¸ GitHub - hibariya/rsss: 最近使っているサービスを可視化
Herokuã§Ruby1.9.2ã使ããããã«ãªã£ã¦ã
ä»æ´ã§ããã使ããããã«ãªã£ã¦ã¾ããã®è¨é²ã
% heroku stack aspen-mri-1.8.6 * bamboo-ree-1.8.7 bamboo-mri-1.9.1 (beta) bamboo-mri-1.9.2 (beta) % heroku stack:migrate bamboo-mri-1.9.2
試ãã«ä½¿ã£ã¦ã¿ãã¨ãããHerokuで使うRubyを1.9.1から1.8.7に戻した - のどをRubyでいっぱいにしてã§æ©ãã§ããããã¤ãã®æ©ã¾ããäºè±¡ãèµ·ããããæ®éã«ä½¿ãã¦ãã¾ããã¨ããã§(beta)ãªã®ã¯ãã¤ã¾ã§ãªãã§ããããã