I've been playing around with Ruby for a while now and wanted to write my own gem. I wanted to write something simple but useful. My idea was to create a simple console gem that would alert a user when a new post was created in a certain subreddit. Right now it's hardcoded to one subreddit, and I'm using Mac's say command to notify me when there's a new post. My first question is, is this even gem-worthy? I could turn this into a simple Rails app, which might make things logistically easier. But I really wanna write up a gem.
If I do decide to carry on with the project as a gem, there are a few obstacles I have to get past. Right now I'm using whenever to run that runs my script every minute. To update your cron jobs, you have to run whenever --update-crontab in the directory of the project in order to set the cron job. This has become an issue for me, because I would like to be able to make the gem usable on installation without having a user do anything. So instead of having to run the command above, I'd like a user to just be able to download the gem and then, eventually, choose what subreddits and the frequency of the cron job (via a console menu).
Sorry for the length of the post, just looking for some input.
My first question is, is this even gem-worthy?
Yes.
I would like to be able to make the gem usable on installation without having a user do anything.
Use a ./bin directory that contains an executable script, that uses a sleep method.
My advice is don't alter the user's cron. Instead, include README help that explains how to cronify your bin executable.
Related
While using the guard-cucumber plugin I found it wasn't working with terminal-notifier-guard
What's the best way to figure out what's going wrong and start making lasting fixes?
Some important criteria are:
I want to get up and running as fast as possible.
Once I'm up and running I want to be able to iterate as fast as possible.
I want to alter my project as little as possible.
I want to be able to keep my changes in version control so I don't lose track of them.
I want to be able to get feedback on my changes if I want.
I want to test my changes in an isolated env.
I don't want to change the guard-cucumber gem installed on my system.
This is my process:
Fork the project and clone it.
Create a new branch
Change the name to guard-cucumber-cats in the gemspec.
In the cloned gem, Do some work.
Add a breakpoint near my work with pry:
require 'pry'
binding.pry
rake install to install guard-cucumber-cats on my machine.
In my project, add guard-cucumber-cats as a dep and comment out guard-cucumber in gemspec. For example:
# spec.add_development_dependency "guard-cucumber", "~> 2.1.2"
spec.add_development_dependency "guard-cucumber-cats"
Run my project, hit debug, mess around with code.
Repeat 4-8
Thinking about process in terms of criteria:
Getting up and running wasn't too bad
Iterating was pretty painful, having to reinstall the guard-cucumber-cats every time I wanted to test a change was awkward.
Changing one line in my project gemspec doesn't seem bad, however it would be better to be able to change nothing.
All the benefits of git right for the beginning was a huge plus
Same goes for github
I don't have a workflow setup with either vagrant or docker, so my "isolated" test env is basically just me on my laptop. Maybe this is a good opportunity to set up a working containerized dev env? I'm not sure sure, but the way I have it now doesn't seem like it meets this criteria.
Although it seems awkward to have to rename the gem and then install it on my system it is nice that I didn't need to change the actual guard-cucumber on my machine.
Ideally I'd like to be able to do something like:
cp -r my project into some sandboxed env
Clone the forked guard-cucumber into the same sandboxed env
Have everything "just work"
Do work on the cloned guard-cucumber
Repeat 4
I read in another answer to just start edit the system gem but didn't like that solution because I lose the benefits of git and github.
Is there a better process that's working for you? Or areas my process can be improved?
Also, as a side note: this is how you can nest code blocks in a list
Use :path in the project's gemfile.
You are working on gem my_gem and project my_project at the same time. To make this painless use this in the gemfile of your project
# in /path/to/my_project/Gemfile
...
gem 'my_gem', :path => '/path/to/my_gem'
...
And then you can iterate without having to build the gem all time.
There's isn't even a need to rename the gem.
Morning guys,
I am writing a small Ruby CLI app for myself, and I have run into a small issue that I hope you guys can help with. Apologies if this is a stupid question, I am very new to Ruby.
I am using https://github.com/davetron5000/gli as a foundation to build my my app since they make it easy to have all my commands and whatnot.
Question is, while I develop the app, I can run it using bundle exec bin/konstruct, but that only works from the folder where the code lies.
I want to run the app from a test folder so I can see whether the code I'm adding is doing what it should (make files, remove files, see if directory is empty, etc).
When I played around with NodeJS, I could link the app, and it would work anywhere. Is there something like that for Ruby apps that are still in development?
Two simple way:
1. Make bin/konstruct executable. So you can run it without bundle exec. Then link it in any directory in your $PATH with ln -s. (For Unix based systems)
2. Create a alias in your shell. something like this:
alias konstruct="bundle exec /FULL/PATH/TO/bin/konstruct"
(Also for Unix based systems)
I'm creating a module that requires a few things to be done (once only) when the module is installed. There may be a number of things that need to be done, but the most basic thing that I need to do is make an API call to a server to let the external server know that the module was installed, and to get a few updated configuration items.
I read this this question on stackoverflow however in my situation I truly am interested in executing code that has nothing to do with the database, fixtures, updating tables, etc. Also, just to be clear this module has no affect (effect?) on the front end. FYI, I've also read this spectacular article by Alan Storm, but this really only drives home the point in my mind that the install/upgrade scripts are not for executing random PHP.
In my mind, I have several possible ways to accomplish this:
I do what I fear is not a best practice and add some PHP to my setup/install script to execute this php
I create some sort of cronjob that will execute the task I need once only (not sure how this would work, but it seems like it might be a "creative" solution - of course if cron is not setup properly then this will fail, which is not good
I create a core_config_data flag ('mynamespace/mymodule/initialized') that I set once my script has run, and I check on every area of the adminhtml that my module touches (CMS/Pages and my own custom adminhtml controller). This seems like a good solution except for all of the extra overhead every time CMS/Pages is hit or my controller is hit, checking this core_config_data setting. The GOOD thing about this solution would be that if something were to fail with my API call, I can set this flag to false and it will run again, display the appropriate message, and continue to run until it succeeds (or have additional logic that will stop the initialization code after XX number of attempts)
Are any of these options the "best" way, and is there any sort of precedent for this somewhere, such as a respected extension or from Magento themselves?
Thanks in advance for your time!
You raise an interesting question.
At the moment, I am not aware of a means to go about executing any arbitrary PHP on module installation, the obvious method (rightly/wrongly) would be to use the installer setup/upgrade script as per 1 of your Q.
2 and 3 seem like a more resource intensive approach, ie. needlessly checking on every page load (cache or not).
There is also the approach of using ./pear to install your module (assuming you packaged it using Magento). I had a very quick look through ./downloader/pearlib/php/pearmage.php but didn't see any lines which execute (vs copying files). I would have imagined this is the best place to execute something on install (other than 1 mentioned above).
But, I've never looked into this, so I'm fairly interested in other possible answers.
How am I supposed to use ruby with development mode, which is not require me to restart my ruby process every time I made changes , just like Rails development mode, when I made changes no need to restart the code and the new code will be applied directly.
I think you can use gem shotgun for webapps server Reference
I dont think you can go ahead without restarting the app for changes!!!
Using load rather than require allows you to reload a file that you've edited since you've started the Ruby script.
That's what development mode does in Rails.
You don't need to keep restarting your app in every instance, for example when you change you controllers and views you wont have to.
If you change your routes or migrations you will need to restart for that.
I'm having a problem getting started with compass/sass. I eventually managed to install compass, although I had to google around because the instructions on the compass website didn't work for me.
Next step was to create a project. I thought this would be simple enough by typing:
$ compass create path/to/project --using blueprint/basic --sass-dir=sass --css-dir=css
Unfortunately, this didn't work. The first thing to fail was that it told me that --using was not a recognised command (even though that is exactly what it tells you to type in the compass installation instructions). So, I tried creating the project taking away all three of the additional options.
This did create a project, although not in the place I specified. Rather than placing it in path/to/project it created the files and directories straight into my home folder ie /Users/me/
I must be doing something wrong, I can't believe that a tool designed to save time and make life easier could be so difficult to get up and running. I'm not great at using the command line, but I am able to follow instructions!
Any pointers would be appreciated!
It sounds like your running compass v0.8, please upgrade to v0.10 and that command will work.