I am learning ruby and thor.. and I am stuck here:
I have two classes in a module (both use Thor). I am able to use only one in the gem executable. When I add both like below and run it, I get Could not find command "hello".
Test::HammerOfTheGods.start(ARGV)
Test::Git.start(ARGV)
How do you intend both of the different classes to work together? Do you want all the commands from each to be available? If so, can you just use a single class? Thor isn't designed to work this way. The reason you're getting the error is because the first time you call .start, an error will be thrown if the command isn't found.
If you're worried about having a particularly long class definition, you can separate the definition of each command into separate files but using the same class.
Related
I want to create an instance of org.gradle.api.file.Directory. From the Gradle docs I see that the only way to do this is to create the first instance using project.getLayout().getProjectDirectory() and then use the instance method dir(<path>) on this instance to create an instance for another directory.
Is there a way to directly create an instance of Directory class (like using a File object or directly using a string path)?
When I started working with the new Gradle Lazy Configuration API, I encountered the same problem. Even though dir(<path>) allows absolute paths and you may therefore construct a Directory instance for any directory, it appeared to me like bad design.
However, actually it is a pretty consistent design, because using the old API we just called Project.file(...) on our paths, which evaluated relative paths based on the project directory, too. Constructing File instances directly using its constructor was always a bad idea using Gradle. We may now just replace the calls to file(<path>) with calls to layout.projectDirectory.dir(<path>) or .file(<path) and get the same behavior.
Starting from version 6.0, Gradle also provides a method dir(Provider<File>) via its ProjectLayout class. You may construct the Provider<File> using the method provider(Callable<>) of the Project class, but whether this is actually useful depends on your specific use case.
I have a test farm I'm making that can run Cucumber tests and will take the results and write to a database.
Instead of using backticks to run from the command line I'm considering this, which seemed to work rather well from an irb prompt:
config = {paths: ['.\\scenarios\\my.feature'], filters: [], tag_expressions: ['#open_print_pdf'],tag_limits: [], profiles: ['example'], require: []}
Cucumber::Runtime.new(Cucumber::Configuration.new(config)).run!
I like that I then get some objects that I can interrogate to write things I need to the db like:
steps
feature and scenario name
etc.
Before I considered this I was going to run using the JSON formatter, save the file, and then parse it, make it a hash and send to db.
Is the only supported way to run it through the command line. I find it useful to programmatically run it so I have everything I need without needing to do needless IO.
So, is running using Cucumber::Runtime(config).run! officially supported?
Does anyone know if you can run lets say 2 error handlers in the same cookbook and have both of them run, one after another? And if so how would you do that.
Handlers are entirely independent of each other and you can run as many as you want. If you are using the chef_handler cookbook, use the titular resource multiple times.
I'm trying to make a ACR1222L work with this ruby script that I found on github.
The script is made for the older ACR122U, but in my research I've seen that they both should be pretty similar.
My problem is when trying to run the script, I get this error:
C:\Users\Emil\Desktop>driver.rb
Calibration Time!
Place and leave a tag on the device
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/smartcard-0.5.5/lib/smartcard/pcsc/conte
xt.rb:112:in `wait_for_status_change': (0x100000006) (Smartcard::PCSC::Exception)
from C:/Users/Emil/Desktop/driver.rb:24:in `<main>'
Could it be that the "smartcard" gem used by the script does not support the ACR1222L, or am I simply just missing something?
Hope that someone can help!
The Smartcard::PCSC::Exception error code you get (0x100000006) translates to the Windows API error code INVALID_HANDLE_EXCEPTION (0x00000006). This typically indicates that the context handle used in the API call is invalid. With the smartcard gem, the PS/SC context (SCardEstablishContext) is established through the initializer of Smartcard::PCSC::Context. This operation seems to be successful, otherwise you would get an exception on line 13. The source of the INVALID_HANDLE_EXCEPTION seems to be SCardGetStatusChange (invoked by context.wait_for_status_change).
A possible reason for that call to fail with an INVALID_HANDLE_EXCEPTION could be a mismatch in the handle format, for instance caused by a 32-bit/64-bit mismatch. Thus, I would assume that the smartcard gem is designed for 32-bit only (while your path indicates that you are using a 64-bit version of Ruby).
I'm looking to pass runtime parameters to my Ruby code. I have a Java background and, in the majority of cases, if I want to override a configuration I'd use a system property with a sane default value.
For example, if I wrote a test against a REST API to localhost, then want to run it against an integration environment and want to adjust the base URL:
$ rake -Cbaseurl=https://i-env.company.com/tbse/ test
Is there an equivalent to system properties in Ruby?
Is there a standard pattern people are using?
I know how to use/load YAML configurations, as well as reference environment variables.
Ruby's from the UNIX world, where this is command line arguments and environment variables.
Command line arguments should be used for things that are commonly changed and are run dependent. These are things like a verbose flag, an output file, or a target URL. Access these with the Ruby stdlib OptionParser.
Environment variables are for things that change less frequently, and are usually across applications. Things like system executable path ($PATH). Use the built-in Ruby env object to access these.
For other things, like configuration, use a config file. In Ruby, these are usually in the YAML format. Use the Ruby stdlib yaml library for these.