2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AWS Cloud9 に Ruby 開発環境をセットアップする

2
Posted at

AWS Cloud9 で Rubyのプログラム開発をする際の開発環境をセットアップしてみました。

結論

初めから Ruby2.6 がインストールされているので、特に何もしなくても Rubyによるプログラミングが始められそうです。

環境

  • AWS Cloud9

前提条件

  • AWS アカウント登録済み
  • AWS Cloud9 サービス利用中

AWS Cloud9 に Ruby の開発環境をセットアップする

作業用ディレクトリの作成

実行中の Cloud9 環境に作業用のディレクトリを作成します。

  • 左側ツリーのトップディレクトリを右クリックして [New Folder] を選択
  • フォルダ名を入力します

Ruby のバージョンを確認

ターミナルを開き、現在の環境のRubyのバージョンを確認します。

$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

今回はこのままで進めます。

gem のリストを確認

現在の環境にインストール済みのgems一覧を確認します。
思ったより沢山インストール済みです。

$ gem list --local

*** LOCAL GEMS ***

actioncable (5.0.0)
actionmailer (5.0.0)
actionpack (5.0.0)
actionview (5.0.0)
activejob (5.0.0)
activemodel (5.0.0)
activerecord (5.0.0)
activesupport (5.0.0)
arel (7.1.4)
bigdecimal (default: 1.4.1)
builder (3.2.3)
bundler (default: 1.17.3)
bundler-unload (1.0.2)
cmath (default: 1.0.0)
concurrent-ruby (1.1.5)
crass (1.0.4)
csv (default: 3.0.9)
date (default: 2.0.0)
did_you_mean (1.3.0)
e2mmap (default: 0.1.0)
erubis (2.7.0)
etc (default: 1.0.1)
executable-hooks (1.6.0)
fcntl (default: 1.0.0)
fiddle (default: 1.0.0)
fileutils (default: 1.1.0)
forwardable (default: 1.2.0)
gem-wrappers (1.4.0)
globalid (0.4.2)
i18n (0.9.5)
io-console (default: 0.4.7)
ipaddr (default: 1.2.2)
irb (default: 1.0.0)
json (default: 2.1.0)
logger (default: 1.3.0)
loofah (2.3.0)
mail (2.7.1)
matrix (default: 0.1.0)
method_source (0.9.2)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.11.3)
mutex_m (default: 0.1.0)
net-telnet (0.2.0)
nio4r (1.2.1)
nokogiri (1.10.4)
openssl (default: 2.1.2)
ostruct (default: 0.1.0)
power_assert (1.1.3)
prime (default: 0.1.0)
psych (default: 3.1.0)
rack (2.0.7)
rack-test (0.6.3)
rails (5.0.0)
rails-dom-testing (2.0.3)
rails-html-sanitizer (1.3.0)
railties (5.0.0)
rake (12.3.2)
rdoc (default: 6.1.0)
rexml (default: 3.1.9)
rss (default: 0.2.7)
rubygems-bundler (1.4.5)
rvm (1.11.3.9)
scanf (default: 1.0.0)
sdbm (default: 1.0.0)
shell (default: 0.7)
sprockets (4.0.0)
sprockets-rails (3.2.1)
stringio (default: 0.0.2)
strscan (default: 1.0.0)
sync (default: 0.5.0)
test-unit (3.2.9)
thor (0.20.3)
thread_safe (0.3.6)
thwait (default: 0.1.0)
tracer (default: 0.1.0)
tzinfo (1.2.5)
webrick (default: 1.4.2)
websocket-driver (0.6.5)
websocket-extensions (0.1.4)
xmlrpc (0.3.0)
zlib (default: 1.0.0)

bunder を更新

bundler (default: 1.17.3) を更新します。
最新は (2.0.2)

$ gem update bundler
Updating installed gems
Updating bundler
Fetching bundler-2.0.2.gem
Successfully installed bundler-2.0.2
Parsing documentation for bundler-2.0.2
Installing ri documentation for bundler-2.0.2
Installing darkfish documentation for bundler-2.0.2
Done installing documentation for bundler after 5 seconds
Parsing documentation for bundler-2.0.2
Done installing documentation for bundler after 2 seconds
Gems updated: bundler

bundler で ライブラリをインストール

bundle init

$ bundle init
Writing new Gemfile to /home/ec2-user/environment/ruby_test/Gemfile

Gemfile に インストールするライブラリを追加

gem "dotenv"

bundle install

$ bundle install
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using bundler 2.0.2
Fetching dotenv 2.7.5
Installing dotenv 2.7.5
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ gem list --local

*** LOCAL GEMS ***

actioncable (5.0.0)
actionmailer (5.0.0)
actionpack (5.0.0)
actionview (5.0.0)
activejob (5.0.0)
activemodel (5.0.0)
activerecord (5.0.0)
activesupport (5.0.0)
arel (7.1.4)
bigdecimal (default: 1.4.1)
builder (3.2.3)
bundler (2.0.2, default: 1.17.3)
bundler-unload (1.0.2)
cmath (default: 1.0.0)
concurrent-ruby (1.1.5)
crass (1.0.4)
csv (default: 3.0.9)
date (default: 2.0.0)
did_you_mean (1.3.0)
dotenv (2.7.5)
e2mmap (default: 0.1.0)
erubis (2.7.0)

dotenv がインストールされました。

テスト

ライブラリが読み込めて利用できることをテストします。

hello.rb
require 'rubygems'
require 'bundler/setup'
require 'dotenv/load'

def hello(name)
    puts "#{ENV['HELLO']} #{name}!!"
end

hello("ruby")

.envファイル

.env
HELLO=Hello

実行結果

$ ruby -cw hello.rb 
Syntax OK
$ ruby -w hello.rb 
Hello ruby!!

kintone のアプリの情報の取得

フィールドの一覧を取得する
https://developer.cybozu.io/hc/ja/articles/204783170#anchor_getform_fields

拙稿からコードをコピーして実行してみます。
https://qiita.com/sy250f/items/82f84904daf7601eeb08#%E3%83%95%E3%82%A9%E3%83%BC%E3%83%A0%E3%81%AE%E8%A8%AD%E5%AE%9A%E3%81%AE%E5%8F%96%E5%BE%97

アプリID=100のアプリのフィールド一覧を取得します。

実行結果

$ ruby -cw get_app_fields.rb 
Syntax OK
$ ruby -w get_app_fields.rb 
{"revision"=>"24",
 "properties"=>
  {"備考"=>
    {"type"=>"MULTI_LINE_TEXT",
     "code"=>"備考",
     "label"=>"備考",
     "noLabel"=>false,
     "required"=>false,
     "defaultValue"=>""},
   "レコード番号"=>
    {"type"=>"RECORD_NUMBER",
     "code"=>"レコード番号",
     "label"=>"レコード番号",
     "noLabel"=>false},
   "作業者"=>
    {"type"=>"STATUS_ASSIGNEE",
     "code"=>"作業者",
     "label"=>"作業者",
     "enabled"=>true},
   "割引率"=>
    {"type"=>"NUMBER",
     "code"=>"割引率",
     "label"=>"割引率",
     "noLabel"=>false,
     "required"=>false,
     "minValue"=>"",
     "maxValue"=>"",
     "digit"=>false,
     "unique"=>false,
     "defaultValue"=>"",
     "displayScale"=>"",
     "unit"=>"",
     "unitPosition"=>"BEFORE"},
   "更新者"=>
    {"type"=>"MODIFIER", "code"=>"更新者", "label"=>"更新者", "noLabel"=>false},
   "作成者"=>{"type"=>"CREATOR", "code"=>"作成者", "label"=>"作成者", "noLabel"=>false},
   "ステータス"=>
    {"type"=>"STATUS", "code"=>"ステータス", "label"=>"ステータス", "enabled"=>true},
   "更新日時"=>
    {"type"=>"UPDATED_TIME",
     "code"=>"更新日時",
     "label"=>"更新日時",
     "noLabel"=>false},
   "金額"=>
    {"type"=>"NUMBER",
     "code"=>"金額",
     "label"=>"金額",
     "noLabel"=>false,
     "required"=>false,
     "minValue"=>"",
     "maxValue"=>"",
     "digit"=>true,
     "unique"=>false,
     "defaultValue"=>"",
     "displayScale"=>"",
     "unit"=>"",
     "unitPosition"=>"BEFORE"},
   "カテゴリー"=>
    {"type"=>"CATEGORY", "code"=>"カテゴリー", "label"=>"カテゴリー", "enabled"=>false},
   "file"=>
    {"type"=>"FILE",
     "code"=>"file",
     "label"=>"file",
     "noLabel"=>false,
     "required"=>false,
     "thumbnailSize"=>"150"},
   "商品名"=>
    {"type"=>"SINGLE_LINE_TEXT",
     "code"=>"商品名",
     "label"=>"商品名",
     "noLabel"=>false,
     "required"=>false,
     "minLength"=>"",
     "maxLength"=>"64",
     "expression"=>"",
     "hideExpression"=>false,
     "unique"=>true,
     "defaultValue"=>""},
   "備考_0"=>
    {"type"=>"MULTI_LINE_TEXT",
     "code"=>"備考_0",
     "label"=>"備考",
     "noLabel"=>false,
     "required"=>false,
     "defaultValue"=>""},
   "備考_4"=>
    {"type"=>"MULTI_LINE_TEXT",
     "code"=>"備考_4",
     "label"=>"備考",
     "noLabel"=>false,
     "required"=>false,
     "defaultValue"=>""},
   "備考_3"=>
    {"type"=>"MULTI_LINE_TEXT",
     "code"=>"備考_3",
     "label"=>"備考",
     "noLabel"=>false,
     "required"=>false,
     "defaultValue"=>""},
   "作成日時"=>
    {"type"=>"CREATED_TIME",
     "code"=>"作成日時",
     "label"=>"作成日時",
     "noLabel"=>false},
   "備考_2"=>
    {"type"=>"MULTI_LINE_TEXT",
     "code"=>"備考_2",
     "label"=>"備考",
     "noLabel"=>false,
     "required"=>false,
     "defaultValue"=>""},
   "備考_1"=>
    {"type"=>"MULTI_LINE_TEXT",
     "code"=>"備考_1",
     "label"=>"備考",
     "noLabel"=>false,
     "required"=>false,
     "defaultValue"=>""}}}

rubyプログラムから kintoneアプリのフィールド一覧を取得できました。

関連リンク

Ruby関連

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?