Configuring guard to monitor controller sub-directories - ruby

I'm new to ruby and I'm trying to configure guard to monitor controllers in a nested directory.
Here is the directory structure
/app
/controllers
/manage
/my_controller.rb
Here is the watch expression that should fire when the file my_controller.rb is edited
watch(%r{^app/controllers/(.+)/(.+)_(controller)\.rb$})
{ |m| [
"spec/routing/#{m[2]}_routing_spec.rb",
"spec/#{m[3]}s/#{m[1]}/#{m[2]}_#{m[3]}_spec.rb",
"spec/acceptance/#{m[2]}_spec.rb"]
}
Note that i don't have routing or acceptance tests, I'm just trying to modify the existing controller watch statement to work with the controller in a nested directory. Also, note that I was able to successfully watch the spec file for changes by adding the following line
watch(%r{^spec/.+/.+_spec\.rb$})
Any insight would be appreciated.

Well, #rainkinz had it right. There was a typo in the specfile name that I couldn't see. I used the -d switch when running guard which printed debug statements that brought the error to my attention.

Related

Executing shell command after Webpack post build

I have a Laravel project and as you know when you deploy your app everything in your public directory should be copied over to your htdocs or public_html directory to hide your application's code.
I am using webpack to build my react code and everything else and each time I change my javascript webpack does what I want, it sees I make a change and then it builds it.
However I want to add one additional command after it builds and that is to copy everything from the public directory into the correct directory in htdocs/public_html.
So far I read up on this question here Run command after webpack build
It works and I can get the echo to work but I'm not sure why cp isn't working. Echo works but how do I know what shell commands I can use?
I tried 'cp' and even 'copy-item' which is powershell, but none are working.
This is my plugin so far, I figured I needed to change the directory to be safe
before copying anything over but again, nothing is working.
mix.webpackConfig(webpack => {
return {
plugins: [
new WebpackShellPlugin({
onBuildStart: ['echo "Starting Build ..."'],
onBuildEnd: ["cd 'E:\\xammp\\apps\\FactorioCalculator'",
"cp '.\\public\\*' '..\\..\\htdocs\\FactorioCalculator\\' -f -r"]
})
]
};
});
You could always use the copyDirectory mix method. Just put something like the following at the bottom of your webpack.mix.js file:
mix.copyDirectory('public', '../../htdocs/FactorioCalculator/')
You might have to change your path to ..\\..\\htdocs\\FactorioCalculator\\ as per the path in your question (I only have my mac with me so I'm unable to test on my other machine).
To answer you original question, if you want to execute a command each time webpack finishes building you can use the mix.then() which takes a closure.

WEBrick run on hanami 1.0.0 shows errors because of wrong inflection

I generated model with hanami generate model stimulus. Then I fixed "stimuluses" to "stimuli" in the migration file name and inside, the table name.
Everytime I load a page I get this error in the server console window:
[ROM::Relation[Stimuluses]] failed to infer schema. Make sure tables exist before ROM container is set up. This may also happen when your migration tasks load ROM container, which is not needed for migrations as only the connection is required (schema parsing returned no columns, table "stimuluses" probably doesn't exist)
I looked into the libraries and found that this functionality has Inflecto library. Then I tried both adding to hanami project this:
# /config/initializers/inflecto.rb
require 'inflecto'
Inflecto.inflections do |inflect|
inflect.irregular('stimulus', 'stimuli')
end
And editing the defualt library file:
# gems/inflecto-0.0.2/lib/inflecto/defaults.rb
Inflecto.inflections do |inflect|
...
inflect.irregular('stimulus', 'stimuli')
...
end
But the message is still there after restarting the server.
Is this something I should solve and if yes, how to do this?
EDIT:
Also tried:
# /config/initializers/inflector.rb
require 'hanami/utils/inflector'
Hanami::Utils::Inflector.inflections do
exception 'stimulus', 'stimuli'
end
I'm assuming we are talking about Hanami v1.0.0, right?
You nearly succeeded. What hit you is that initializers seem to be not loaded when executing hanami commands and maybe a bug in code reloading. So instead of an initializer put it into a file that gets loaded when hanami commands are executed or require the initializer file in such a place. E.g.,
# config/initializers/inflections.rb
require 'hanami/utils/inflector'
Hanami::Utils::Inflector.inflections do
exception 'stimulus', 'stimuli'
end
and then in your environment file
# config/environment.rb
# ...
require_relative 'initializers/inflections.rb'
# ...
I'm not sure if that is a good place to put custom inflection rules, but at least it works.

Why would I get "Errno::ENOENT: No such file or directory" when viewing a Sinatra form?

I am trying to follow this tutorial:
http://net.tutsplus.com/tutorials/ruby/singing-with-sinatra/
Got stuck in "We’ll also make use of a “view file”, which allows us to split the markup for a view into a separate file. "
I have my basics.rb file running fine.
And My files are stored as follows:
Desktop/RubyForm/basics.rb
Desktop/RubyForm/view/form.erb
However, now when i go to http://localhost:9393/form , I am greeted with:
Errno::EIO at /form
Input/output error - <STDERR> file: lint.rb location: write line: 398
sinatra.error
Errno::ENOENT: No such file or directory -
/Users/HelenasMac/Desktop/views/form.erb
UPDATE! : Got the form to work right after running ruby basics.rb and going to http://localhost:4567/form .
However, after I run "shotgun basics.rb" , I have to go to
http://localhost:9393/form, and that's when the form doesn't show up.
What am I doing wrong? Disclaimer: mega beginner to ruby and using the terminal.
Thanks in advance!
If you cannot get shotgun to work then the new recommended way to reload Sinatra seems to be rerun.
To use it:
> gem install rerun
> cd /Users/HelenasMac/Desktop/RubyForm
> rerun ruby basics.rb
Explicity Set a Views Directory
Unless you're using inline template for your views with enable :inline_templates, you may need to explicitly define a template directory if the default values aren't working for you. The docs describe how to set your views directory as follows:
:views - view template directory
A string specifying the directory where view templates are located. By default, this is assumed to be a directory named “views” within the application’s root directory (see the :root setting). The best way to specify an alternative directory name within the root of the application is to use a deferred value that references the :root setting:
set :views, Proc.new { File.join(root, "templates") }
You may also need to explicitly set :root, and make sure that both :root and :views make sense from your current working directory.

How to change the default 'test' folder in Autotest with Ruby

My test folder is inside lib/foo/test instead of /test. How can I tell Autotest to look at lib/foo/test for the tests to run? I tried to add some hooks with mappings in the .autotest file but got no success. Thanks in advance.
I'm sorry for not providing a direct answer, but I've stopped using Autotest myself and switched to Guard. Guard is a plain Ruby process that sits outside test::unit or rspec and as such it's much more configurable.
https://github.com/guard/guard
What you want is easy to accomplish in Guard, just write a Guardfile in the project root and mention the directory to watch:
watch("lib/foo/test") { |m| "test/lib/foo/test/#{m[1]}_test.rb" }
obviously tailoring it further to your need.

Perl::WSDL. Generated methods in different directory than script

I am trying to write a script for using with op5/nagios.
What it tries to do is to connect to database an get a value there, and then send a request to a webservice and match the response from the webservice with the value from the database.
Now writing the script wasn't the problem. The problem arrises when trying to run it from OP5.
When including the interface to script I use the following syntax
use MyInterfaces::PortalServicesImplService::PortalServicesImplPort;
This works just fine when I execute the script located on the same level as "MyInterfaces".
The problem is that the script itself is located in the folder /opt/plugins/custom/SOAP where both the script and the folders generated by wsdl2perl.pl is located. However when OP5 executes the script is does so from the folder /opt/monitor.
So I tried to include the "PortalServicesImplPort" using this syntax
use lib "/opt/plugins/custom/SOAP/MyInterfaces/PortalservicesImplServices/PortalServicesImplPort
The code compiles but when trying to run it I get an error message saying
Can't locate object method "new" via package "MyInterfaces::PortalServicesImplService::PortalServicesImplPort" (perhaps you forgot to load "MyInterfaces::PortalServicesImplService::PortalServicesImplPort"?)
Am I doing something wrong when importing methods from another location or doesn't SOAP::WSDL support placing the auto generated files in a different directory from where you are executing the script?
Seems I managed to solve this myself by adding use lib "/opt/plugins/custom/SOAP

Resources