Running bundle exec linguist --breakdown fails - github-linguist

When I run bundle exec linguist --breakdown on the root directory, I get the following error:
No such file or directory # rb_sysopen -
/Users/George/linguist/lib/linguist/samples.json (Errno::ENOENT)
How can I correct this?

By executing bundle exec rake samples in the linguist directory.
This step is required to generate the samples.json file which contains condensed information on sample files for the Bayesian classifier.

Related

Ruby: 'bundle exec' throws error for all shell commands

In my project, I have a Gem that contains a shell script in its bin folder, let's call the script do_something.sh.
do_something.sh actually executes a ruby script using Jruby command, the script is called ruby_script.rb.
I am trying to call do_something.sh from my project using:
bundle exec do_something.sh
it keeps throwing errors for all shell commands in the script. I erased all the contents of the script and added only one line "echo 'Hello'" and it is still throwing the following error
NoMethodError: undefined method echo' for main:Object
/usr/local/rvm/gems/ruby-2.1.1#projectName/gems/gemName/bin/do_something.sh:10:in'
/usr/local/rvm/gems/ruby-2.1.1#projectName/bin/do_something.sh:23:in load'
/usr/local/rvm/gems/ruby-2.1.1#projectName/bin/do_something.sh:23:in'
Edit#1
All the files has execute permission.
I also tried to put ruby_script.rb in the bin directory where are files are executables (according to a rule in the gemspec file) and tried calling
bundle exec ruby_script.rb
I get the error "bundler: command not found: ruby_script.rb"
bundle exec ruby ruby_script.rb
I get the error "ruby: No such file or directory -- ruby_script.rb (LoadError)"
Why am I getting this error and how can I solve it? I want to be able to either run do_something.sh or ruby_script.rb. Right now, ruby_script.rb is not recognised and do_something.sh does not recognise the commands.
Ok, finally after two days, I was able to make it work.
bundle install installs my GEM and creates a ruby wrapper by default to sh files in the 'bin' directory. So, when I call my script using bundle exec the ruby wrapper gets called first and it calls my script using a ruby 'load' function. This load function expects a ruby file and that is why all my shell script in the file threw errors, because they were expected to be in ruby.
A workaround to this is installing my gem before 'bundle install' using the following command:
gem install --no-wrapper my-gem
Apparently this command disabled creating the ruby wrapper and I was finally able to call the script using bundle execute do_something.sh
Try specifying sh when you run bundle exec. The NoMethodError is from the script being executed in ruby and not sh.
bundle exec sh do_something.sh
In order to make it work. Setting_up_permissions_on_a_script
First: you have to change the mode for the file using chomd +x file_path
Second: Now you can call either by bundle exec file_path or ./file_path
N.B
1: Don't forget to add #!/bin/sh on top of the file.
2: And do check with deploy-a-shell-script-with-ruby-gem-and-install-in-bin-directory will definitely help you.
Hope this help you!
According to Rubygems Specification Reference, executables included in the gem
... must be executable Ruby files. Files that use bash or other interpreters will not work.
In order to to add an executable to a gem please make sure to read the Adding an executable section on Rubygems Guide.
Eventually you'll be able to run the executable like this:
bundle exec do_something
where bundle exec part is optional.

rspec error (LoadError)

I am running the rspec command
bundle exec rspec spec/requests
resulting in the error:
ms$ bundle exec rspec spec/requests/ms/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load': cannot load such file -- /Users/ms/Dropbox/Ruby/Code/<appname>/spec/requests/spec/requests (LoadError)
for simplicity i replaced the name of my app with <appname>. I can see that the path below <appame> is duplicated spec/request/spec/requests
I don't know what I did (nothing?) to make this start automatically this wrong path.
When i test the models it's like this:
cannot load such file -- /Users/i814509/Dropbox/Ruby/Code/<appname>/spec/requests/spec/models (LoadError)
again automatically looking for the spec/requests directory before the one that I'm trying to specificy
You specified spec/requests but it seems to already be the default:
just run bundle exec rspec
Also, if you configured your environment, or don't use rvm/pik, you can just run rspec

ROR Error: project directory contains "gemfile" but shows error "could not locate Gemfile" after executing bundle show

I am executing a command rails new sample_app. After creating a project sample_app, I executed bundle show command but it Could not locate Gemfile.
I Google and found stackoverflow solutions 1 2 3 in which they didn't find gemfile whereas in my case i have. Suggest some solutions.
I think you should be in sample_app directory. For this run on command prompt cd sample_appthen execute bundle installthen bundle show

How to build and run a Ruby command-line tool found on github?

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

what is the ideal directory structure of a ruby application

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
$

Resources