what is the ideal directory structure of a ruby application.
I want it to be deployed on EC2. It should have Gemfile and Rake file for executing rake tasks.
It should contain a lib file for utilities.
Should I just be using the command
newgem --simple test
Take a look at this RailsCast.
'bundle gem simple_test' works great for me.
$ bundle gem simple_test
create simple_test/Gemfile
create simple_test/Rakefile
create simple_test/.gitignore
create simple_test/simple_test.gemspec
create simple_test/lib/simple_test.rb
create simple_test/lib/simple_test/version.rb
Initializating git repo in /Users/sean/dev/foo/simple_test
$
Related
When I run bundle exec rails console production or rails console production via SSH on the server in the Current folder of the Capistrano deploy I get:
Usage:
rails new APP_PATH [options]
Options:
(...)
with an explanation to start a new app. Locally it works. Why can't I start a console remotely?
I'm assuming that you updated to rails 4 from version 3 and your app can't find the executables in the bin directory. Run this to see your rails version:
$ rails -v
If your rails version is 4 or above, try running this:
$ rake rails:update:bin
Source: Rails 4 Release Notes
6.1 Notable changes
Your app's executables now live in the bin/ dir. Run rake rails:update:bin to get bin/bundle, bin/rails, and bin/rake.
I am using capistrano to deploy, including the capistrano/bundler gem. Since the ./bin directory is version controlled in Rails 4, we need to prevent Capistrano from linking it on deployments by removing bin from set :linked_dirs.
Now in order to prevent bundler from overwriting the version controlled binstubs, we can add the line set :bundle_binstubs, nil which will prevent capistrano-bundler from setting the --binstubs option when running bundle install.
My config/deploy.rb file now has these lines:
# Default value for linked_dirs is []
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :bundle_binstubs, nil
Note the lack of the bin directory in the :linked_dirs line.
I have the same problem, and turns out when you deploy through cap shared/bin is symlink to current/bin.
Here's what works for me:
rm current/bin
mkdir current/bin
rake rails:update:bin
This should help, but it is somewhat a temporary solution, I'm trying to find out how to make cap not auto symlink-ing current/bin.
In case of Rails 5.2
I had to remove bin directory by running below command in project root directory.
rm -rf bin
and then I ran another command in project root directory:
rake app:update:bin
It will show you output like below:
create bin
create bin/bundle
create bin/rails
create bin/rake
create bin/setup
create bin/update
create bin/yarn
That's it.
It's been a little while since this was answered.
In my case I needed to run:
rake app:update:bin
Note- app rather than rails.
I was missing the bin directory all-together in my Rails 5.1 App
I faced this issue on my production server when I updated my application from Rails 5.2 to 6.0.4. Simply follow these steps:
cd to_your_project_dir
rm -r bin
rake app:update:bin
I'm developing a GEM that I've forked and I'm trying to modify it slightly for my app.
I'm finding it difficult and time consuming because for every change I make I have to
uninstall
build
re-install
run the app
Is there an easier way of which doesn't require repeating all steps above?
To use it in some app using bundler
If what you mean is for using it in a app to test it / use it, you can just specify a path for your gem or even point to a git repo in the Gemfile http://gembundler.com/gemfile.html
Like
gem "mygem", :path => "~/code/gems/mygem"
To use it as a standalone gem. i.e: like rspec or rake that can run outside of an app.
Just specify the path to your gem binary when running the gem command, like:
$ ~/path_to_my_gem/bin/mygem some args
If you can execute inside your gem directory (i.e: the command does not create files in the current directory, or needs any specific files from the current directory), just do this:
$ ./bin/mygem some args
Note that this last one is just for future reference, I think it's not applicable in the OP context.
use require_relative to include your files:
require_relative 'yourgem/yourclass'
This is the documentation for the function.
Hi cloned a simple app ( https://github.com/cfx/twix) on github that allows me to send Twitter messages from the console, but I'm not sure how to run it.
I now have a folder in my users/name director called Twix. Inside twix, I have these folders created by the app.
README Rakefile bin lib test
The readme doesn't provide a lot of instruction to get things started. It just tells you what to do after the program's running (see below).
Questions: What command do I use to get this started? What folder do I need to be in?
The README
Twix 0.0.1
Simple twitter client for console
Keys:
q - quit
t - write new message
If you want to post your twit, finish you message with !SEND
If you want abort and back to your feed, finish your message with !EXIT
new features soon
This program is packaged as a gem. The following command will install the gem (run it in the Twix directory):
rake package && gem install pkg/twix-0.0.1.gem
You can now run the program from anywhere with the twix command.
Edit
The first thing I saw in the repository was the Rakefile, meaning there were some rake tasks defined. When you find yourself in this case, running rake -T is your best bet as it will show you the rake tasks available. Its output was the following:
(in /home/benoit/code/clones/twix)
rake clobber_package # Remove package products
rake gem # Build the gem file twix-0.0.1.gem
rake package # Build all the packages
rake repackage # Force a rebuild of the package files
I picked the command that would be the most likely to build the gem: the package one. I guess the gem task would have worked as well.
Running rake package gave me the following output:
(in /home/benoit/code/clones/twix)
mkdir -p pkg
WARNING: no homepage specified
Successfully built RubyGem
Name: twix
Version: 0.0.1
File: twix-0.0.1.gem
mv twix-0.0.1.gem pkg/twix-0.0.1.gem
All that was left was to install the pkg/twix-0.0.1.gem created by the previous command:
gem install pkg/twix-0.0.1.gem
There's another case you could have encountered: the presence of a twix.gemspec in the root directory of the application. In this case, running:
gem build twix.gemspec
would have built the gem, the installation step remains the same.
ruby ./bin/twix
or
ruby -I lib ./bin/twix
I would like to have ctags generate a TAGS file of all my bundled gems or all the gems under the rvm gemset directory bundler installs its gems. Ideally, a bundle install or bundle update should generate a TAGS file at the last step using a ruby script I'll provide. Afterthat emacs joy.
Is there any kind of a bundler after hook I can use?
You could look at what Tim Pope does in his Hookup project:
https://github.com/tpope/hookup
I'd imagine it wouldn't be too hard to an an extra step after the bundler run.
Personally I just have a good old Makefile in my Ruby project:
.PHONY: tags
tags:
ETAGS=ctags
rm -rf TAGS
ctags -a -e -f TAGS --tag-relative -R app lib vendor
I have a shell script I run in the morning which sets up my dev environment which also runs make tags.
According to https://github.com/bundler/bundler/blob/dd1e11d8f8e869ffab4fc68d4854b27e1f486de4/lib/bundler/source/path.rb, there is the ability to run 'post_install' hooks. It uses meta-programming to deduce the method name, and the gem is supposed to implement that method. Will try and check if this works
My approach has been two pronged:
1) Put a rake task in place that generates tags for all code in the project as well as all required gems:
desc 'Create ctags'
task :tags do
system "ctags -R --language-force=ruby app config lib `rvm gemdir`/gems"
end
2) Using the excellent "foreman" gem (which I was using anyway) to run inotifywait and fire off the rake task if a file changes:
tags: while inotifywait -q -r -e MODIFY --exclude swp$ app/ config/ lib/ ; do bundle exec rake tags; done
If you are not using foreman you can of course just run that line without the first "tags:" part manually in a shell.
My gem semantictext has a bunch of test data that it reads for regression testing.
Here's the project: http://github.com/dafydd/semantictext
Here's an example test that I want to be able to run directly from the gem: http://github.com/dafydd/semantictext/blob/master/test/test_document.rb (look for text "SANDBOX")
I normally develop it in a directory called "semantictext" and have the environment variable SANDBOX set to the path of the directory above "semantictext" - so that I can reference any file in the project using ENV['SANDBOX'].
When the gem is installed as a package, is there a way that the test/unit test running from rake can:
1) know that it's running from a gem? and
2) know the path to it's semantictext directory within the local rubygems repository?
I want to make it effortless to be able to run all the tests from any gem installation. This would make my continuous integration a bit easier and allow me to write better gems.
Thanks,
Dafydd
You can find out the directory of the current file using:
File.dirname(__FILE__)
This will allow you to build up a relative path to whatever file you need to access.