Struggling to run my ruby cli app - ruby

I built a small Cli app in ruby (first ever ruby app), but I'm not able to actually run it.
I started the project off with bundle gem. I have been testing it inside my apps folder by running bundle exec bin/konstruct and everything works fine.
I want to install it locally and test it before I submit it, and so I ran bundle exec rake install after updating all of the info in my gemspec file. It gave successfull output:
konstruct 0.1.1 built to pkg/konstruct-0.1.1.gem.
konstruct (0.1.1) installed.
But when I run the app by entering $ konstruct it gives me an Could not locate Gemfile or .bundle/ directory error, unless I run it from within the root folder of the app.
I have tried to Google but I can't pin the results down to the same issue as I'm having. I've been having this problem even in development (How can I test my Ruby CLI app while still in development?)
I do have a Gemfile and it contains:
source 'https://rubygems.org'
# Specify your gem's dependencies in konstruct.gemspec
gemspec
I don't have a .bundle/ folder though. I'm not sure where/how that folder should be generated. I have run bundle and bundle install many times now.
I have a konstruct.gemspec file which contains: https://github.com/konstruct/konstruct.cli/blob/master/konstruct.gemspec
Most of that file is as it was generated. I just filled it in where I could.
I'm sorry if this is a stupid question, but I am super stuck.

You have the following line in your gemspec:
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
I believe that means if you move your executable file into an exe directory instead of a bin directory, it will work as you expect.
http://guides.rubygems.org/specification-reference/#executables

It turns out I am a first class idiot. Some time ago I added Konstruct in my .path file, which obviously was now overriding the proper konstruct command. Back then what I did din't work, so I just forgot about it.
So the answer to this question: It's not broken. OP is an idiot. :-/

Related

Gem creation: run code on installation

I want to create a gem that installs some binaries on "/usr/local/bin". In order to work, I need to run some "cp"/"ln"/"chmod" commands when the user (me) runs gem install mygem.
Is there any callback/method that is called at the installation and that I can override it?
UPDATE:
I found a better way to achieve it: gemspec has a section to add binary files on the system. I put the answer below, but I still wonder how to run code after/before gem installation.
See this https://github.com/rubygems/rubygems/issues/608 you have to run the default task after installation
I found a better way to achieve it: gemspec has a section to add binary files on the system.
Eg:
spec.bindir = "bin"
...
spec.executables << 'your_app'
Then, put your_app in bin.
PS: I'm the OP, but I will not accept this as solution because I still wonder how to run code after/before gem installation.

How to start Middleman? cannot load such file -- less (LoadError)

I am learning Middleman. I installed Vagrant and have set up everything about that. But I have a problem at the end, when I call "bundle exec middleman", the Middleman should start after that regularly. But I get this message:
"var/lib/gems/2.2.0/gems/tilt-1.4.1/lib/tilt/template.rb:144:in 'require':cannot load such file -- less (LoadError)"
What should I do? I am working on Linux.
Maybe you forgot to add less to your Gemfile:
gem 'less'
As #tadman has pointed out adding
gem 'less'
is (possibly) a solution, but here is a little more detail on why you might have this problem migrating or developing a site:
If you initialise a middleman project with middleman init, then start working on your site with 'middleman serve' everything should be fine. But if, at some point you add a file with a .less extension you will get this error when you next restart middleman. Note that you might not knowingly have added less files - fontawsome for example can add .less versions of the css deep in it's directory structure.
I say that installing less is only possibly a solution since the 'less' gem was broken when I tried it (it was not able to install due to an old dependency on therubyracer
Deleting .less files that you didn't want or know you had is also a solution.

Gem "Malformed Version Number String"

I'm building a gem. I just got the basic project structure laid out, and I tried building it with gem build my_gem.gemspec, which worked fine. Then I installed it with gem install My\ Gem-0.0.1.gem and it still looked like it worked fine. Then I tried to run irb and I got this:
/Users//.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/version.rb:206:in `initialize': Malformed version number string on (ArgumentError)
I tried making some changes and saved them. I ran gem build my_gem.gemspec. Same error.
All irb, rails, and gem sub-commands are generating a stack trace with this at the top. What did I do to break all of these commands and how do I reverse it?
You should manually delete your gem:
cd $GEM_HOME
find . -path \*my_gem\*
If everything looks good (i.e. there are no files which aren't related to your gem):
find . -path \*my_gem\* -delete
Before installing your gem again, make sure you specified version in your .gemspec.
UPD.
Other locations to look for the residue of the gem:
~/.rvm/gems/ruby-<version>#global
~/.rvm/gems/ruby-<version>
/System/Library/Frameworks/Ruby.framework/
# look for "GEM PATHS" section
gem env
# rbenv paths
~/.rbenv/versions
~/.gem/
UPD2
Problem solved! Steps taken:
This showed where exactly is this particular Rubygems executable, which failed to load:
rbenv which gem
# => /Users/<username>/.rbenv/versions/2.2.2/bin/gem
Then it turns out under 2.2.2 directory there were cache, doc and specifications directories, all of which contained a file or sub-directory with the residue of the broken gem. Deleting them all solved the problem.
(2016-May-24)
I solve this problem today.
I was try to learn how to write a gem. and then cause this problem.
My guess is because my gem's name contain whitespace: "hola 1c7"
and gem do not tell you how to solve this prbolem, this is annoying
you should go to:
/usr/local/lib/ruby/gems/2.3.0/specifications
delete that xxx.gemspec
in my case, my gem's name is "hola 1c7"
so I delete "hola 1c7-0.1.2.gemspec"
I think is the space cause problem.
if this not working,
try to search your gems name in /usr/local/lib/ruby/gems/
and delete all the file you can find,
in my case, first I delete
hola 1c7.1.3.2.gem from /usr/local/lib/ruby/gems/2.3.0/cache
so the command is :
/usr/local/lib/ruby/gems/2.3.0/cache$ sudo rm -rf hola\ 1c7-1.3.2.gem
and then
/usr/local/lib/ruby/gems/2.3.0/gems$ sudo rm -rf hola\ 1c7-1.3.2/
My Ruby Version : Ruby 2.3.0
My Linux Version : Ubuntu 16.04 LTS
I couldn't find the files in the reference path, or some of the other suggested paths in this post. Some thing that helped me was to first comment out the error be raised in the version.rb file on line 201. Then use the GEM PATH directory using $ gem env to find the path that had references to the gem. Make sure to remove everything from the doc, cache, and specifications folders. This finally solved my issue.

oocss-compass plugin setup

I'm having trouble in the setup of oocss-compass plugin.
The steps I did:
Downloaded the oocss-compass and placed it on my desktop (https://github.com/he8us/oocss-compass)
Inside the oocss-compass destkop folder I runed:
rvm use #global
gem build oocss-compass.gemspec
gem install oocss-compass-[GEMVERSION].gem
The gem is on my gem list (oocss-compass)
Then on my working folder (not RoR project, just empty folders and html static pages), I runed:
compass create css -r oocss-compass --using oocss-compass
And it returns me an error:
Errno::ENOENT on line ["95"] of /Users/username/.rvm/gems/ruby-1.9.2-p290#global/gems/compass-0.11.7/lib/compass/installers/base.rb: No such file or directory - /Users/username/.rvm/gems/ruby-1.9.2-p290#global/gems/oocss-compass-0.0.1/lib/../templates/project/partials/_base.sass
What can be missing or what i did wrong on the installation?
I've just submitted the modifications to GitHub and published a gem on Rubygems.org ;)
You can update the gem and start building...
Have a nice day,
He8us
I'm the owner of the repository.
I've just did the test and I have the same problem. It's probably because Compass changed the way to create the plugins. I will look at it and come back to you asap.

Ruby gems in lib - spare tire principle

I'm working on a console ruby application (not rails!) I will be installing this application on several machines. I was wondering if there is a way i can build it so i dont have to install the gems i'm using for the app on each machine. I'd like to be able to just copy the directory to each machine and run it. Ideally, i'd like to put the gems in the lib folder or something and reference them from there, so i don't have to even install them on my dev machine. Is there a way to do this?
In .net, we call this the "spare tire" principle.
thanks,
Craig
How about using bundler?
Then you can include a Gemfile that specifies all the necssary gems and just run "bundle install" on each machine to pull them down.
If you really want to bundle them with the app run "bundle package" and the gems will be stored in vendor/cache.
You could take the same approach as rails allows and "vendor" your gems. This involves creating a new directory (rails uses vendor/gems) and unpack the gem into this directory, using gem unpack.
You then configure your load path to include all of the sub-folders below that.
Edit
You can configure your load path by doing something like this
Dir.glob(File.join("vendor", "gems", "*", "lib")).each do |lib|
$LOAD_PATH.unshift(File.expand_path(lib))
end

Resources