Gems collection
Some interesting gems to consider.
# | |
# vendor/plugins/redmine_gist/init.rb | |
# | |
require 'redmine' | |
require 'open-uri' | |
Redmine::Plugin.register :redmine_gist do | |
name 'Redmine Gist embed plugin' | |
author 'Yasushi Abe <yasushi.abe@gmail.com>' | |
description 'This is a plugin for Redmine' |
# via http://tagaholic.me/2009/05/29/exploring-how-to-configure-irb.html#echo | |
def irb_verbosity_toggle | |
irb_context.echo ? irb_context.echo = false : irb_context.echo = true | |
end |
Some interesting gems to consider.
class Base | |
def initialize args | |
update args | |
end | |
def update args | |
args.each do |k,v| | |
send "#{k}=", v if respond_to? k | |
end |
gem install thor
mkdir -p ~/vagrants && cd ~/vagrants
curl -LO https://raw.github.com/gist/1528832/vagrantify
chmod 755 vagrantify
./vagrantify init webserver
require 'fog' | |
require 'chef/config' | |
Chef::Config.from_file('./.chef/knife.rb') | |
EC2 = Fog::Compute.new provider: 'AWS', | |
region: Chef::Config[:knife][:region], | |
aws_access_key_id: Chef::Config[:knife][:aws_access_key_id], | |
aws_secret_access_key: Chef::Config[:knife][:aws_secret_access_key] | |
servers = EC2.servers.select { |s| s.tags["Name"] =~ /ec2\-test\-/ && s.state == "running" } |
application "redmine" do | |
path "/opt/redmine" | |
owner "nobody" | |
group "nogroup" | |
repository "git://github.com/redmine/redmine.git" | |
revision "2.0-stable" | |
packages ["build-essential", | |
"git", | |
"postgresql-server-dev-all", | |
"libgraphicsmagick++-dev", |
# Put this in ~/chef-repo/data_bags/aws/main.rb | |
# Upload it to the Chef Server with: | |
# | |
# knife data bag item rb aws main.rb | |
# | |
# Export the two AWS values for your account. | |
{ | |
'id' => "main", | |
'aws_access_key_id' => ENV['AWS_ACCESS_KEY_ID'], |
Example of mocking out a library in Chef so you can test the provider in isolation.
If you want to test the library itself you can do more normal Ruby things.
#!./bin/knife exec | |
# A knife exec script to change chef node's name, preserving all the attributes. | |
# | |
# Usage: knife exec rename-node.rb old-name new-name | |
# | |
# Script retrieves the Node object, changes its 'name' attribute, | |
# creates new Node object with updated name and rest of attributes | |
# untouched. Then it deletes old Node and Client objects from | |
# database, and logs into the server to update it: |