hdknr’s posterous

 
Filed under

ruby

 

Ruby Freaks Lounge:第11回 自由なWebフレームワーク,Ramaze|gihyo.jp … 技術評論社

シンプルなフレームワークといえば,第7回第9回で紹介したSinatraもそうでした。SinatraはDSLを駆使して独自の世界を作っていましたが,RamazeはRubyのやり方をできるだけ踏襲します。実際のアプリケーションの例を見てみましょう。

Filed under  //   Framework   ruby  

Comments [0]

Ramaze : index

Comments [0]

Ruby off Rails (japanese)

勉強になった。でもPythonでいいような気がして来た。

Filed under  //   Framework   orm   ruby  

Comments [0]

DataMapper - Why DataMapper?

Why DataMapper?

DataMapper differentiates itself from other Ruby Object/Relational Mappers in a number of ways:

Identity Map

One row in the database should equal one object reference. Pretty simple idea. Pretty profound impact. If you run the following code in ActiveRecord you’ll see all false results. Do the same in DataMapper and it’s true all the way down.

1 @parent = Tree.first(:conditions => { :name => 'bob' })
2 
3 @parent.children.each do |child|
4   puts @parent.object_id == child.parent.object_id
5 end

This makes DataMapper faster and allocate less resources to get things done.

Plays Well With Others

With DataMapper you define your mappings in your model. Your data-store can develop independently of your models using Migrations.

To support data-stores which you don’t have the ability to manage yourself, it’s simply a matter of telling DataMapper where to look.

1 class Fruit
2   include DataMapper::Resource
3 
4   storage_names[:default] = 'frt' # equivalent to set_table_name in AR
5 
6   property :id,   Serial
7   property :name, String, :field => 'col2'
8 end

DataMapper only issues updates or creates for the properties it knows about. So it plays well with others. You can use it in an Integration Database without worrying that your application will be a bad actor causing trouble for all of your other processes.

Laziness Can Be A Virtue

Columns of potentially infinite length, like Text columns, are expensive in data-stores. They’re generally stored in a different place from the rest of your data. So instead of a fast sequential read from your hard-drive, your data-store has to hop around all over the place to get what it needs.

With DataMapper, these fields are treated like in-row associations by default, meaning they are loaded if and only if you access them. If you want more control you can enable or disable this feature for any column (not just text-fields) by passing a lazy option to your column mapping with a value of true or false.

1 class Animal
2   include DataMapper::Resource
3 
4   property :id,    Serial
5   property :name,  String
6   property :notes, Text    # lazy-loads by default
7 end

Plus, lazy-loading of Text property happens automatically and intelligently when working with associations. The following only issues 2 queries to load up all of the notes fields on each animal:

1 animals = Animal.all
2 animals.each do |pet|
3   pet.notes
4 end

Strategic Eager Loading

DataMapper will only issue the very bare minimums of queries to your data-store that it needs to. For example, the following example will only issue 2 queries. Notice how we don’t supply any extra :include information.

 1 zoos = Zoo.all
 2 zoos.each do |zoo|
 3   # on first iteration, DM loads up all of the exhibits for all of the items in zoos
 4   # in 1 query to the data-store.
 5 
 6   zoo.exhibits.each do |exhibit|
 7     # n+1 queries in other ORMs, not in DataMapper
 8     puts "Zoo: #{zoo.name}, Exhibit: #{exhibit.name}"
 9   end
10 end

The idea is that you aren’t going to load a set of objects and use only an association in just one of them. This should hold up pretty well against a 99% rule.

When you don’t want it to work like this, just load the item you want in it’s own set. So DataMapper thinks ahead. We like to call it “performant by default”. This feature single-handedly wipes out the “N+1 Query Problem”.

DataMapper also waits until the very last second to actually issue the query to your data-store. For example, zoos = Zoo.all won’t run the query until you start iterating over zoos or call one of the ‘kicker’ methods like #length. If you never do anything with the results of a query, DataMapper won’t incur the latency of talking to your data-store.

All Ruby, All The Time

DataMapper goes further than most Ruby ORMs in letting you avoid writing raw query fragments yourself. It provides more helpers and a unique hash-based conditions syntax to cover more of the use-cases where issuing your own SQL would have been the only way to go.

For example, any finder option that are non-standard is considered a condition. So you can write Zoo.all(:name => 'Dallas') and DataMapper will look for zoos with the name of ‘Dallas’.

It’s just a little thing, but it’s so much nicer than writing Zoo.find(:all, :conditions => [ 'name = ?', 'Dallas' ]) and won’t incur the Ruby overhead of Zoo.find_by_name('Dallas'), nor is it more difficult to understand once the number of parameters increases.

What if you need other comparisons though? Try these:

 1 Zoo.first(:name => 'Galveston')
 2 
 3 # 'gt' means greater-than. 'lt' is less-than.
 4 Person.all(:age.gt => 30)
 5 
 6 # 'gte' means greather-than-or-equal-to. 'lte' is also available
 7 Person.all(:age.gte => 30)
 8 
 9 Person.all(:name.not => 'bob')
10 
11 # If the value of a pair is an Array, we do an IN-clause for you.
12 Person.all(:name.like => 'S%', :id => [ 1, 2, 3, 4, 5 ])
13 
14 # Does a NOT IN () clause for you.
15 Person.all(:name.not => [ 'bob', 'rick', 'steve' ])
16 
17 # Ordering
18 Person.all(:order => [ :age.desc ])
19 # .asc is the default

To query a model by it’s associations, you can use a QueryPath:

1   Person.all(:links => [ :pets ], Person.pets.name => 'Pixel')

You can even chain calls to all or first to continue refining your query or search within a scope. See Finders for more information.

Open Development

DataMapper sports a very accessible code-base and a welcoming community. Outside contributions and feedback are welcome and encouraged, especially constructive criticism. Go ahead, fork DataMapper, we’d love to see what you come up with!

Make your voice heard! Submit a ticket or patch, speak up on our mailing-list, chat with us on irc, write a spec, get it reviewed, ask for commit rights. It’s as easy as that to become a contributor.

Copyright Dan Kubb, Sam Smoot 2009

Web Design by Luke Matthew Sutton - Community Maintained

Filed under  //   Framework   orm   ruby  

Comments [0]

2009-10-04 - make for h @ppy_things;

Web側

全部Rubyで書いてあります. コントローラSinatra, ビューにHamlを使っています. データベースへのアクセスSQLを直接書いているので, 特にどうこうはありません. あとはグラフを描画するためにGruffを使っています.

サーバーURLからもわかりますが, さくらさんです. データベースMySQL. 最初はcoreserverの方でやっていましたけど, Gruffが利用するRMagickをインストールするコトができなかったので, しぶしぶ乗り換えた次第. ご迷惑をおかけしております.

バックグラウンド

バックグラウンドはすべてErlangで書いています. 動作自体は各ユーザーさんのフォロワーを取得して, 例のスパムがいたらブロックするだけです.

ちなみにボクのマシンで動作させています. 当然Web側のデータベースともやり取りを行わなければいけない(ユーザーさんの取得, ブロック情報の更新)ので, その間はSSHを介してごちゃごちゃやっています*

Filed under  //   Framework   Haml   ruby   Sinatra  

Comments [0]

ruby:MemCache

hdknr@debsq:~/tmp/cached_mem$ more config/environment.rb

memcache_options = {
:c_threshold => 10_000,
:compression => false,
:debug => false,
:namespace => 'vis_mod',
:readonly => false,
:urlencode => false
}
CACHE = MemCache.new memcache_options
CACHE.servers = 'localhost:11211'

hdknr@debsq:~/tmp/cached_mem$ ruby script/console
Loading development environment (Rails 2.3.4)
@@@ config/environtment.rb
>> sql ="SELECT * FROM `categories` WHERE (`categories`.`id` = 1)"
=> "SELECT * FROM `categories` WHERE (`categories`.`id` = 1)"
>> d = Digest::MD5.hexdigest(sql)
=> "1b837a35dbfd6bf42f95e110df28c9e5"
>> Category.find_by_sql(sql)
=> [#]
>> CACHE.set(d,Category.find_by_sql(sql))
=> "STORED\r\n"
>> CACHE.get(d)
=> [#]

memcachedログ。

32: Client using the ascii protocol
>32 STORED
>32 sending key vis_mod:1b837a35dbfd6bf42f95e110df28c9e5C 0 247
Category:@attributes_cache{
>32 END

Filed under  //   MemCache   memcached   rails   ruby  

Comments [0]

Ruby on RailsでRuby-GetText-Packageを使う (Rails-2.1.x以前) - よたらぼ 保管庫

ローカライズドテンプレートの使用

foo_ja.hml.erb, foo_ja_JP.html.erbと言う風にテンプレート自体を英語の元ファイルから分離させてしまうこともできます。例えば以下のようにファイルを配置します。

/app/views/blog/list.html.erb
/app/views/blog/list_ja.html.erb

このケースでは日本語(jaロケール)の場合のみ、2番目のファイルが呼び出され、それ以外の時は1番目のファイルが呼び出されます。 render_partialの場合は、_foo.html.erb, _foo_ja.html.erbとすると、日本語の場合のみ_foo_ja.html.erbが呼び出されます。

Note メンテナンス性を考えるとこの機能はなるべく使わないことを推奨します。 こちらにその理由がありますのでご参照ください。なお、この日記のエントリに書かれているソースコードはすでにRuby-GetText-Package本体に取り込まれていますので無視してください。

使わない方がいいのか。

Filed under  //   gettext   locale   rails   ruby  

Comments [0]

Module: ActiveRecord::Calculations::ClassMethods

count(*args)

Count operates using three different approaches.

  • Count all: By not passing any parameters to count, it will return a count of all the rows for the model.
  • Count using column: By passing a column name to count, it will return a count of all the rows for the model with supplied column present
  • Count using options will find the row count matched by the options used.

The third approach, count using options, accepts an option hash as the only parameter. The options are:

  • :conditions: An SQL fragment like "administrator = 1" or [ "user_name = ?", username ]. See conditions in the intro to ActiveRecord::Base.
  • :joins: Either an SQL fragment for additional joins like "LEFT JOIN comments ON comments.post_id = id" (rarely needed) or named associations in the same form used for the :include option, which will perform an INNER JOIN on the associated table(s). If the value is a string, then the records will be returned read-only since they will have attributes that do not correspond to the table‘s columns. Pass :readonly => false to override.
  • :include: Named associations that should be loaded alongside using LEFT OUTER JOINs. The symbols named refer to already defined associations. When using named associations, count returns the number of DISTINCT items for the model you‘re counting. See eager loading under Associations.
  • :order: An SQL fragment like "created_at DESC, name" (really only used with GROUP BY calculations).
  • :group: An attribute name by which the result should be grouped. Uses the GROUP BY SQL-clause.
  • :select: By default, this is * as in SELECT * FROM, but can be changed if you, for example, want to do a join but not include the joined columns.
  • :distinct: Set this to true to make this a distinct calculation, such as SELECT COUNT(DISTINCT posts.id) …
  • :from - By default, this is the table name of the class, but can be changed to an alternate table name (or even the name of a database view).

Examples for counting all:

  Person.count         # returns the total count of all people

Examples for counting by column:

  Person.count(:age)  # returns the total count of all people whose age is present in database

Examples for count with options:

  Person.count(:conditions => "age > 26")
  Person.count(:conditions => "age > 26 AND job.salary > 60000", :include => :job) # because of the named association, it finds the DISTINCT count using LEFT OUTER JOIN.
  Person.count(:conditions => "age > 26 AND job.salary > 60000", :joins => "LEFT JOIN jobs on jobs.person_id = person.id") # finds the number of rows matching the conditions and joins.
  Person.count('id', :conditions => "age > 26") # Performs a COUNT(id)
  Person.count(:all, :conditions => "age > 26") # Performs a COUNT(*) (:all is an alias for '*')

Note: Person.count(:all) will not work because it will use :all as the condition. Use Person.count instead.

Filed under  //   ActiveRecord   rails   ruby  

Comments [0]

rails : ruby,gem,rails install on Debian Squeeze

hdknr@debsq:~$ sudo aptitude  install ruby1.8 -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  libruby1.8{a} ruby1.8
更新: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
1,969kB のアーカイブを取得する必要があります。展開後に 6,631kB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main libruby1.8 1.8.7.174-2 [1,678kB]
取得:2 http://ftp.jp.debian.org squeeze/main ruby1.8 1.8.7.174-2 [291kB]                                                                                             
1,969kB を 14s 秒でダウンロードしました (134kB/s)                                                                                                                    
未選択パッケージ libruby1.8 を選択しています。
(データベースを読み込んでいます ... 現在 30000 個のファイルとディレクトリがインストールされています。)
(.../libruby1.8_1.8.7.174-2_i386.deb から) libruby1.8 を展開しています...
未選択パッケージ ruby1.8 を選択しています。
(.../ruby1.8_1.8.7.174-2_i386.deb から) ruby1.8 を展開しています...
man-db のトリガを処理しています ...
libruby1.8 (1.8.7.174-2) を設定しています ...
ruby1.8 (1.8.7.174-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了


hdknr@debsq:~$ sudo aptitude install irb1.8 -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  irb1.8 libreadline-ruby1.8{a}
更新: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
582kB のアーカイブを取得する必要があります。展開後に 950kB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main libreadline-ruby1.8 1.8.7.174-2 [271kB]
取得:2 http://ftp.jp.debian.org squeeze/main irb1.8 1.8.7.174-2 [311kB]
582kB を 5s 秒でダウンロードしました (110kB/s)
未選択パッケージ libreadline-ruby1.8 を選択しています。
(データベースを読み込んでいます ... 現在 30582 個のファイルとディレクトリがインストールされています。)
(.../libreadline-ruby1.8_1.8.7.174-2_i386.deb から) libreadline-ruby1.8 を展開しています...
未選択パッケージ irb1.8 を選択しています。
(.../irb1.8_1.8.7.174-2_all.deb から) irb1.8 を展開しています...
man-db のトリガを処理しています ...
libreadline-ruby1.8 (1.8.7.174-2) を設定しています ...
irb1.8 (1.8.7.174-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了


hdknr@debsq:~$ wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz

hdknr@debsq:~$ tar xfz rubygems-1.3.5.tgz
hdknr@debsq:~$ cd rubygems-1.3.5/
hdknr@debsq:~/rubygems-1.3.5$

hdknr@debsq:~/rubygems-1.3.5$ sudo ruby1.8 setup.rb
RubyGems 1.3.5 installed
./lib/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- rdoc/rdoc (LoadError)
     from ./lib/rubygems/custom_require.rb:31:in `require'
     from ./lib/rubygems/commands/setup_command.rb:352:in `run_rdoc'
     from ./lib/rubygems/commands/setup_command.rb:247:in `install_rdoc'
     from ./lib/rubygems/commands/setup_command.rb:120:in `execute'
     from ./lib/rubygems/command.rb:257:in `invoke'
     from ./lib/rubygems/command_manager.rb:132:in `process_args'
     from ./lib/rubygems/command_manager.rb:102:in `run'
     from ./lib/rubygems/gem_runner.rb:58:in `run'
     from setup.rb:35

hdknr@debsq:~/rubygems-1.3.5$ sudo aptitude install rdoc1.8 -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  rdoc1.8
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
385kB のアーカイブを取得する必要があります。展開後に 971kB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main rdoc1.8 1.8.7.174-2 [385kB]
385kB を 7s 秒でダウンロードしました (52.3kB/s)                                                                    
未選択パッケージ rdoc1.8 を選択しています。
(データベースを読み込んでいます ... 現在 30647 個のファイルとディレクトリがインストールされています。)
(.../rdoc1.8_1.8.7.174-2_all.deb から) rdoc1.8 を展開しています...
man-db のトリガを処理しています ...
rdoc1.8 (1.8.7.174-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了

hdknr@debsq:~/rubygems-1.3.5$ sudo ruby1.8 setup.rb
RubyGems 1.3.5 installed

=== 1.3.5 / 2009-07-21

Bug fixes:

* Fix use of prerelease gems.
* Gem.bin_path no longer escapes path with spaces. Bug #25935 and #26458.

Deprecation Notices:

* Bulk index update is no longer supported (the code currently remains, but not
  the tests)
* Gem::manage_gems was removed in 1.3.3.
* Time::today was removed in 1.3.3.


------------------------------------------------------------------------------

RubyGems installed the following executables:
     /usr/bin/gem1.8

  hdknr@debsq:~/rubygems-1.3.5$ sudo gem1.8 install rails
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.4
Successfully installed activerecord-2.3.4
Successfully installed rack-1.0.0
Successfully installed actionpack-2.3.4
Successfully installed actionmailer-2.3.4
Successfully installed activeresource-2.3.4
Successfully installed rails-2.3.4
8 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.4...
Installing ri documentation for activerecord-2.3.4...
Installing ri documentation for rack-1.0.0...
Installing ri documentation for actionpack-2.3.4...
Installing ri documentation for actionmailer-2.3.4...
Installing ri documentation for activeresource-2.3.4...
Installing ri documentation for rails-2.3.4...
Installing RDoc documentation for rake-0.8.7...
Installing RDoc documentation for activesupport-2.3.4...
Installing RDoc documentation for activerecord-2.3.4...
Installing RDoc documentation for rack-1.0.0...
Installing RDoc documentation for actionpack-2.3.4...
Installing RDoc documentation for actionmailer-2.3.4...
Installing RDoc documentation for activeresource-2.3.4...
Installing RDoc documentation for rails-2.3.4...


hdknr@debsq:~$ sudo aptitude install libopenssl-ruby1.8
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了
以下の新規パッケージがインストールされます:
  libopenssl-ruby1.8
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
384kB のアーカイブを取得する必要があります。展開後に 770kB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main libopenssl-ruby1.8 1.8.7.174-2 [384kB]
384kB を 0s 秒でダウンロードしました (602kB/s)
未選択パッケージ libopenssl-ruby1.8 を選択しています。
(データベースを読み込んでいます ... 現在 30717 個のファイルとディレクトリがインストールされています。)
(.../libopenssl-ruby1.8_1.8.7.174-2_i386.deb から) libopenssl-ruby1.8 を展開しています...
libopenssl-ruby1.8 (1.8.7.174-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了

hdknr@debsq:~$ sudo aptitude install mysql-client mysql-server -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます     
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了       
以下の新規パッケージがインストールされます:
  libdbd-mysql-perl{a} libdbi-perl{a} libhtml-template-perl{a} libmysqlclient16{a} libnet-daemon-perl{a}
  libplrpc-perl{a} mysql-client mysql-client-5.1{a} mysql-common{a} mysql-server mysql-server-5.1{a} psmisc{a}
更新: 0 個、新規インストール: 12 個、削除: 0 個、保留: 0 個。
22.5MB のアーカイブを取得する必要があります。展開後に 53.6MB のディスク領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main mysql-common 5.1.37-2 [66.7kB]
取得:2 http://ftp.jp.debian.org squeeze/main libnet-daemon-perl 0.43-1 [46.6kB]
取得:3 http://ftp.jp.debian.org squeeze/main libplrpc-perl 0.2020-2 [36.0kB]
取得:4 http://ftp.jp.debian.org squeeze/main libdbi-perl 1.609-1 [798kB]
取得:5 http://ftp.jp.debian.org squeeze/main libmysqlclient16 5.1.37-2 [1,927kB]
取得:6 http://ftp.jp.debian.org squeeze/main libdbd-mysql-perl 4.012-1+b1 [135kB]
取得:7 http://ftp.jp.debian.org squeeze/main mysql-client-5.1 5.1.37-2 [8,247kB]
取得:8 http://ftp.jp.debian.org squeeze/main psmisc 22.8-1 [87.8kB]                                               
取得:9 http://ftp.jp.debian.org squeeze/main mysql-server-5.1 5.1.37-2 [11.0MB]                                   
取得:10 http://ftp.jp.debian.org squeeze/main libhtml-template-perl 2.9-1 [65.7kB]                                
取得:11 http://ftp.jp.debian.org squeeze/main mysql-client 5.1.37-2 [61.0kB]                                      
取得:12 http://ftp.jp.debian.org squeeze/main mysql-server 5.1.37-2 [61.1kB]                                      
22.5MB を 18s 秒でダウンロードしました (1,192kB/s)                                                                
パッケージを事前設定しています ...
未選択パッケージ mysql-common を選択しています。
(データベースを読み込んでいます ... 現在 30753 個のファイルとディレクトリがインストールされています。)
(.../mysql-common_5.1.37-2_all.deb から) mysql-common を展開しています...
未選択パッケージ libnet-daemon-perl を選択しています。
(.../libnet-daemon-perl_0.43-1_all.deb から) libnet-daemon-perl を展開しています...
未選択パッケージ libplrpc-perl を選択しています。
(.../libplrpc-perl_0.2020-2_all.deb から) libplrpc-perl を展開しています...
未選択パッケージ libdbi-perl を選択しています。
(.../libdbi-perl_1.609-1_i386.deb から) libdbi-perl を展開しています...
未選択パッケージ libmysqlclient16 を選択しています。
(.../libmysqlclient16_5.1.37-2_i386.deb から) libmysqlclient16 を展開しています...
未選択パッケージ libdbd-mysql-perl を選択しています。
(.../libdbd-mysql-perl_4.012-1+b1_i386.deb から) libdbd-mysql-perl を展開しています...
未選択パッケージ mysql-client-5.1 を選択しています。
(.../mysql-client-5.1_5.1.37-2_i386.deb から) mysql-client-5.1 を展開しています...
未選択パッケージ psmisc を選択しています。
(.../psmisc_22.8-1_i386.deb から) psmisc を展開しています...
man-db のトリガを処理しています ...
mysql-common (5.1.37-2) を設定しています ...
未選択パッケージ mysql-server-5.1 を選択しています。
(データベースを読み込んでいます ... 現在 31068 個のファイルとディレクトリがインストールされています。)
(.../mysql-server-5.1_5.1.37-2_i386.deb から) mysql-server-5.1 を展開しています...
未選択パッケージ libhtml-template-perl を選択しています。
(.../libhtml-template-perl_2.9-1_all.deb から) libhtml-template-perl を展開しています...
未選択パッケージ mysql-client を選択しています。
(.../mysql-client_5.1.37-2_all.deb から) mysql-client を展開しています...
未選択パッケージ mysql-server を選択しています。
(.../mysql-server_5.1.37-2_all.deb から) mysql-server を展開しています...
man-db のトリガを処理しています ...
libnet-daemon-perl (0.43-1) を設定しています ...
libplrpc-perl (0.2020-2) を設定しています ...
libdbi-perl (1.609-1) を設定しています ...
libmysqlclient16 (5.1.37-2) を設定しています ...
libdbd-mysql-perl (4.012-1+b1) を設定しています ...
mysql-client-5.1 (5.1.37-2) を設定しています ...
psmisc (22.8-1) を設定しています ...
mysql-server-5.1 (5.1.37-2) を設定しています ...
Stopping MySQL database server: mysqld.
090925 21:36:19 [Note] Plugin 'FEDERATED' is disabled.
090925 21:36:19  InnoDB: Started; log sequence number 0 44233
090925 21:36:19  InnoDB: Starting shutdown...
090925 21:36:21  InnoDB: Shutdown completed; log sequence number 0 44233
090925 21:36:21 [Warning] Forcing shutdown of 1 plugins
Starting MySQL database server: mysqld ..
Checking for corrupt, not cleanly closed and upgrade needing tables..
libhtml-template-perl (2.9-1) を設定しています ...
mysql-client (5.1.37-2) を設定しています ...
mysql-server (5.1.37-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています               
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます      
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了       
タスクの記述を読み込んでいます... 完了  

MySQLのインストール。
http://hdknr.posterous.com/ruby-gem-install-mysq-on-squeeze-libmysqlclie

passenger & nginx のインストール。
http://hdknr.posterous.com/rails-passenger-and-nginx-install-on-debian-s

Filed under  //   Debian   gem   rails   ruby   Squeeze  

Comments [0]

ruby : gem : install mysq on Squeeze : libmysqlclient-dev が必要です!

hdknr@debsq:~$ sudo gem1.8 install mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:10:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:10


Gem files will remain installed in
/usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to
/usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

hdknr@debsq:~$ sudo aptitude install ruby1.8-dev -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了
以下の新規パッケージがインストールされます:
ruby1.8-dev
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
834kB のアーカイブを取得する必要があります。展開後に 1,872kB のディスク
領域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main ruby1.8-dev 1.8.7.174-2 [834kB]
834kB を 2s 秒でダウンロードしました (410kB/s)
未選択パッケージ ruby1.8-dev を選択しています。
(データベースを読み込んでいます ... 現在 31249 個のファイルとディレクト
リがインストールされています。)
(.../ruby1.8-dev_1.8.7.174-2_i386.deb から) ruby1.8-dev を展開しています...
ruby1.8-dev (1.8.7.174-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了
タスクの記述を読み込んでいます... 完了

hdknr@debsq:~$ sudo gem1.8 install mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/bin/ruby1.8
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in
/usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to
/usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out

hdknr@debsq:~$ sudo aptitude install libmysql-ruby1.8 -y
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了
以下の新規パッケージがインストールされます:
libmysql-ruby1.8
更新: 0 個、新規インストール: 1 個、削除: 0 個、保留: 0 個。
55.9kB のアーカイブを取得する必要があります。展開後に 217kB のディスク領
域が新たに消費されます。
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main libmysql-ruby1.8 2.8.1-1+b1
[55.9kB]
55.9kB を 0s 秒でダウンロードしました (235kB/s)
未選択パッケージ libmysql-ruby1.8 を選択しています。
(データベースを読み込んでいます ... 現在 31279 個のファイルとディレクト
リがインストールされています。)
(.../libmysql-ruby1.8_2.8.1-1+b1_i386.deb から) libmysql-ruby1.8 を展開
しています...
libmysql-ruby1.8 (2.8.1-1+b1) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了
タスクの記述を読み込んでいます... 完了

hdknr@debsq:~$ dpkg -L libmysqlclient16
/.
/usr
/usr/lib
/usr/lib/libmysqlclient.so.16.0.0
/usr/lib/libmysqlclient_r.so.16.0.0
/usr/share
/usr/share/doc
/usr/share/doc/libmysqlclient16
/usr/share/doc/libmysqlclient16/changelog.gz
/usr/share/doc/libmysqlclient16/EXCEPTIONS-CLIENT.gz
/usr/share/doc/libmysqlclient16/changelog.Debian.gz
/usr/share/doc/libmysqlclient16/copyright
/usr/lib/libmysqlclient_r.so.16
/usr/lib/libmysqlclient.so.16

hdknr@debsq:~$ dpkg -L libmysql-ruby1.8
/.
/usr
/usr/lib
/usr/lib/ruby
/usr/lib/ruby/1.8
/usr/lib/ruby/1.8/i486-linux
/usr/lib/ruby/1.8/i486-linux/mysql.so
/usr/share
/usr/share/doc
/usr/share/doc/libmysql-ruby1.8
/usr/share/doc/libmysql-ruby1.8/changelog.Debian.gz
/usr/share/doc/libmysql-ruby1.8/copyright
/usr/share/doc/libmysql-ruby1.8/examples
/usr/share/doc/libmysql-ruby1.8/examples/test.rb.gz
/usr/share/doc/libmysql-ruby1.8/README_ja.html
/usr/share/doc/libmysql-ruby1.8/README.html
/usr/share/doc/libmysql-ruby1.8/tommy.css

hdknr@debsq:~$ sudo aptitude install libmysqlclient-dev
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
タスクの記述を読み込んでいます... 完了
以下の新規パッケージがインストールされます:
libmysqlclient-dev zlib1g-dev{a}
更新: 0 個、新規インストール: 2 個、削除: 0 個、保留: 0 個。
2,479kB のアーカイブを取得する必要があります。展開後に 6,808kB のディス
ク領域が新たに消費されます。
先に進みますか? [Y/n/?] Y
拡張状態情報を書き込んでいます... 完了
取得:1 http://ftp.jp.debian.org squeeze/main zlib1g-dev
1:1.2.3.3.dfsg-15 [159kB]
取得:2 http://ftp.jp.debian.org squeeze/main libmysqlclient-dev 5.1.37-2
[2,321kB]
2,479kB を 4s 秒でダウンロードしました (563kB/s)
未選択パッケージ zlib1g-dev を選択しています。
(データベースを読み込んでいます ... 現在 31288 個のファイルとディレクト
リがインストールされています。)
(.../zlib1g-dev_1%3a1.2.3.3.dfsg-15_i386.deb から) zlib1g-dev を展開して
います...
未選択パッケージ libmysqlclient-dev を選択しています。
(.../libmysqlclient-dev_5.1.37-2_i386.deb から) libmysqlclient-dev を展
開しています...
man-db のトリガを処理しています ...
zlib1g-dev (1:1.2.3.3.dfsg-15) を設定しています ...
libmysqlclient-dev (5.1.37-2) を設定しています ...
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
拡張状態情報を読み込んでいます
パッケージの状態を初期化しています... 完了
拡張状態情報を書き込んでいます... 完了
タスクの記述を読み込んでいます... 完了

hdknr@debsq:~$ sudo gem1.8 install mysql
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
No definition for next_result
No definition for field_name
No definition for field_table
No definition for field_def
No definition for field_type
No definition for field_length
No definition for field_max_length
No definition for field_flags
No definition for field_decimals
No definition for time_inspect
No definition for time_to_s
No definition for time_get_year
No definition for time_get_month
No definition for time_get_day
No definition for time_get_hour
No definition for time_get_minute
No definition for time_get_second
No definition for time_get_neg
No definition for time_get_second_part
No definition for time_set_year
No definition for time_set_month
No definition for time_set_day
No definition for time_set_hour
No definition for time_set_minute
No definition for time_set_second
No definition for time_set_neg
No definition for time_set_second_part
No definition for time_equal
No definition for error_errno
No definition for error_sqlstate
Installing RDoc documentation for mysql-2.8.1...
No definition for next_result
No definition for field_name
No definition for field_table
No definition for field_def
No definition for field_type
No definition for field_length
No definition for field_max_length
No definition for field_flags
No definition for field_decimals
No definition for time_inspect
No definition for time_to_s
No definition for time_get_year
No definition for time_get_month
No definition for time_get_day
No definition for time_get_hour
No definition for time_get_minute
No definition for time_get_second
No definition for time_get_neg
No definition for time_get_second_part
No definition for time_set_year
No definition for time_set_month
No definition for time_set_day
No definition for time_set_hour
No definition for time_set_minute
No definition for time_set_second
No definition for time_set_neg
No definition for time_set_second_part
No definition for time_equal
No definition for error_errno
No definition for error_sqlstate

hdknr@debsq:~$ irb1.8
irb(main):001:0> require 'mysql'
=> true

Filed under  //   Debian   gem   MySQL   rails   ruby  

Comments [0]