This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generators | |
# If we load in the generator this way it will *always* be loaded | |
scope "merb-gen" do | |
Merb.add_generators File.join(File.dirname(__FILE), 'lib', 'generators', 'model') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
migration_test:(master) $ merb-gen model --migration Feed id:Serial url:string description:text | |
/usr/lib/ruby/gems/1.8/gems/merb_datamapper-0.9.4/lib/generators/model.rb:24: undefined local variable or method `migration' for Merb::Generators::DataMapperModelGenerator:Class (NameError) | |
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' | |
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' | |
from /usr/lib/ruby/gems/1.8/gems/merb-gen-0.9.4/lib/merb-gen.rb:34 | |
from /usr/lib/ruby/gems/1.8/gems/merb-gen-0.9.4/lib/merb-gen.rb:33:in `each' | |
from /usr/lib/ruby/gems/1.8/gems/merb-gen-0.9.4/lib/merb-gen.rb:33 | |
from /usr/lib/ruby/gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:550:in `call' | |
from /usr/lib/ruby/gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:550:in `run' | |
from /usr/lib/ruby/gems/1.8/gems/merb-core-0.9.4/lib/merb-core/bootloader.rb:550:in `each' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Posts < Application | |
get '/' | |
@post = Post.all | |
end | |
get '/:id' do |id| | |
@post = Post.first(id) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Named Routes | |
merb_gen_y_index: /generate/ | |
Anonymous Routes | |
/generate/:controller(/:action(/:id)?)?(\.:format)? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An uploader for merb, stored in app/uploaders/my_uploader.rb | |
# | |
# Usage: | |
# | |
# identifier = "some_string_probably_filename.png" | |
# uploader = MyUploader.new(identifier) | |
# | |
# Storing files to the filesystem | |
# uploader.storage = :file | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass | |
class << self | |
def hooks | |
@hooks ||= Hash.new([]) | |
end | |
def add_hook(kind, &block) | |
self.hooks[kind] << block | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Model | |
class Author | |
class << self | |
def search(conditions={}) | |
conditions = conditions.reject { |k,v| v.blank? } | |
conditions[:books] = { :title => conditions.delete(:book_name) } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export PROJDIR="$HOME/Projects" | |
p() { | |
cd $PROJDIR/$1/ | |
} | |
_projectcomplete() { | |
COMPREPLY=($(compgen -W '$(`which ls` $PROJDIR/)' -- ${COMP_WORDS[COMP_CWORD]})) | |
return 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Consistent API so we can change the underpinnings without breakage | |
# Everything done inside the block will adopt :activerecord as trait | |
Rails.generator(:model).add(:activerecord) do | |
# this will be handled as a binary file | |
action 'file.png' | |
# as a template | |
action 'some_ruby_file.rb' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Controller | |
def index | |
<%= partial 'index' %> | |
end | |
end |