Archive for October, 2008
Rails 2.x automatically dasherizes ActiveRecord inheritors when to_xml is called, but if you want to deal directly with Builder::XmlMarkup you have to go through some hoops to dasherize your element names.
I solved this problem today with a simple subclass. Here's the code:
[sourcecode language='ruby']
# Creates a Builder::Markup implementation that dasherizes all element and attribute names
# Use this just like you would Builder::XmlMarkup
class DasherizingBuilder < Builder::XmlMarkup
def _start_tag(sym, attrs, end_too=false)
super(sym.to_s.dasherize, attrs, end_too)
end
def _end_tag(sym)
super(sym.to_s.dasherize)
end
def _insert_attributes(attrs, order=[])
return if attrs.nil?
new_order= []
order.each {|item| new_order
1 Comment »
October 8, 2008 | code, ruby
I recently wanted to create a simple local gem repository. Not all of the gems we write are relevant to the world at large, so github or rubyforge are not great solutions for hosting them.
You can use the gem server command, but if you already have an apache HTTP server somewhere, incredibly easy to get a private gem repository going, server why not use that?
1. Copy the .gem file to your server
scp your.gem your.server:/your/gem/path
2. Create a folder for hosting your gems on the server
ssh user@your.server
cd /var/www/html
mkdir my_awesome_gems
cd my_awesome_gems
mkdir gems
cp /your/gem/path/*.gem ./gems
3. Generate the gem index
gem comes with a command generate_index which generates all of the files necessary for serving gems over HTTP.
cd /var/www/html/my_awesome_gems
gem generate_index
At this point you should be able to access http://your.server/my_awesome_gems/ and see file listings.
4. Add your new source and install your gem on your client
sudo gem sources -a http://your.server/my_awesome_gems/
You should be able to install your gems from this repository now!
sudo gem install [your gem]
That's it, you're now stashing gems in your own repo!
No Comments »