Rubygems

From 탱이의 잡동사니
Jump to navigation Jump to search

Overview

Ruby gems 내용 정리

Basic

RubyGems 는 시스템에서 루비 소프트웨어 패키지를 쉽게 다운로드, 설치, 관리하도록 한다. 소프트웨어 패키지는 "gem"이라고 불리고 루비 어플리케이션이나 라이브러리를 담고 있다.

gem 은 루비 어플리케이션의 기능을 추가하거나 수정하는데 사용할 수 있다.

GEM

각각의 gem 은 이름, 버전, 플랫폼을 가지고 있다. 예를 들어 rake gem 은 0.8.7 버전을 가지고 있고, 플랫폼은 ruby 이다. 이 말은 Ruby 가 돌아가는 어떤 플랫폼에서도 사용 가능하다는 의미이다.

플랫폼은 CPU 아키텍쳐, 운영체제 종류나 가끔은 운영체제 버전에 기반한다. 예를 들어 플랫폼에는 "x86-minggw32"나 "java" 같은게 있다. 플랫폼은 같은 플랫폼에서 빌드한 루비에서한 gem 이 동작하는 것을 나타낸다. RubyGems 는 자동으로 해당 플랫폼에 맞는 버전을 다운로드 한다. gem help platform 을 입력하면 더 자세한 설명을 확인할 수 있다.

$ gem help platform
RubyGems platforms are composed of three parts, a CPU, an OS, and a
version.  These values are taken from values in rbconfig.rb.  You can view
your current platform by running `gem environment`.

RubyGems matches platforms as follows:

  * The CPU must match exactly, unless one of the platforms has
    "universal" as the CPU.
  * The OS must match exactly.
  * The versions must match exactly unless one of the versions is nil.

For commands that install, uninstall and list gems, you can override what
RubyGems thinks your platform is with the --platform option.  The platform
you pass must match "#{cpu}-#{os}" or "#{cpu}-#{os}-#{version}".  On mswin
platforms, the version is the compiler version, not the OS version.  (Ruby
compiled with VC6 uses "60" as the compiler version, VC8 uses "80".)

Example platforms:

  x86-freebsd        # Any FreeBSD version on an x86 CPU
  universal-darwin-8 # Darwin 8 only gems that run on any CPU
  x86-mswin32-80     # Windows gems compiled with VC8

When building platform gems, set the platform in the gem specification to
Gem::Platform::CURRENT.  This will correctly mark the gem with your ruby's
platform.

gem 의 내부에는 다음과 같은 내용이 있다.

(테스트와 지원 유틸리티를 포함한)코드
문서
gemspec

그리고, 각 gem 은 다음과 같은 표준 구조를 따른다.

$ tree freewill
freewill/
├── bin/
│   └── freewill
├── lib/
│   └── freewill.rb
├── test/
│   └── test_freewill.rb
├── README
├── Rakefile
└── freewill.gemspec
lib 디렉토리를 gem 을 위한 코드가 위치한다.
개발자가 어떤 테스트 프레임워크를 사용하냐에 따라, test 나 spec 디렉토리에 테스트 코드가 포함될 수 있다.
gem 은 보통 rake 프로그램에서 테스트 자동화, 코드 생성, 다른 작업을 수행하는데 사용되는 Rakefile 을 가지고 있다.
이 gem 은 bin 디렉토리 안에 실행파일도 가지고 있다. bin 디렉토리는 gem 이 설치될 때 사용자의 PATH에 로드된다.
문서를 보통 README 파일이나 코드 안에 포함된다. gem 을 설치하면, 문서는 자동으로 생성된다. 대부분의 gem 은 RDoc 문서를 사용하지만, YARD 문서를 사용할 수도 있다.
gemspec 파일에는 gem 에서 사용되는 파일, 테스트 정보, 플랫폼, 버전 번호, 저자의 이메일, 이름 등의 정보가 포함된다.

See also