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.
Related
Every time I make some change in Laravel, I need to do php artisan swoole:http stop and after that php artisan swoole:http start. It doesnt see my changes until I do that. Is there any other way to reloading server, or what..Also, when I do docker-compose up -d it starts running, but in app I am getting Connection is refused.. I am new with Docker and Swoole. Can someone explain to me how to use it? Thank you
I assume you're using octane but in general.
it loads the application into memory and then serves the application from memory. if you're doing local development there is a watcher you can add that will auto-reload when it detects changes.
https://laravel.com/docs/9.x/octane#watching-for-file-changes
As more of a general statement and background: this is how most programming languages work, the code is compiled into an executable and any time you need to make changes, you would have to recompile and re-execute the program.
PHP is an interpreted language so the compilation normally happens as you execute the script which means it can respond to filesystem changes without you having to manually restart or recompile. This may be convenient but it also can be very poor performing.
Various optimizations can be made to change how/when the code is compiled to improve performance (opcache, swoole, etc). When you're running with these optimizations, you will have to follow their guidelines on what needs to be done when you make changes (recompile, restart, or clear caches).
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.
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.
The javascript debugger in Cloud9 is great, but it only appears to work if I run 'node' rather than using something like 'nodemon'.
I'd like the run command to restart if a file changes, and I also want to use the debugger. Anyone know a quick fix for this?
Discovered that there's no need to restart the runner - changes are applied to the run environment / configuration immediately. Even better!
That's what I wanted to write, it applies changes automatically.
Though, if you make changes to routes, you have to restart the server,
at least that's what I was having to do.
Each time I make changes to code I have to restart the server or it won't change the output.
I have tried using thin and webrick.
My development.rb file says "config.cache_classes = false".
I am using RubyMine.
Sometimes my view updates, but the models never update.
Anything else you need to know to help me troubleshoot this problem?
EDIT:
I am away from my coding machine right now, but I started thinking. I have a file called makesandwich.rb in app/models directory and app/models/Lesson.rb calls a function in that file. I have been making changes to the makesandwich.rb file and it hasn't been reloading. Do I need to add that file or should it be included automatically in reload?
I recently had this problem as well. As others have said, it can be caused by setting config. cache_classes or config.threadsafe! to true, which will probably be the problem in most cases.
However, my problem was caused by running rails on a VM. My code was stored on a folder on my host machine, which was then mounted to the VM. Unfortunately, the clock time of my host machine was out of sync with the VM. Here's what would happen when I modified my code:
I'd change some code in a text editor on my host machine
Saving the code would set the modified time of the file to the current time for my host machine
This time was in the future, from the perspective of the VM
When the file update checker looked for modified files, it ignored my file since the modified date was in the future
Again, this is probably a pretty rare case, but it's worth checking this if you're running rails on a VM
If you're working on a Rails 3 project, you might find Zeus helpful. It keeps track of the files in your project, and reloads only the changed code in memory. It makes REPL a lot quicker for Rails 3 development.
https://github.com/burke/zeus
The problem was that I put a function in a separate file and was editing the function there. This will work fine for production, but for development purposes I put the function back in to the Lesson.rb file and the refreshing started working properly.