When someone installs this plugin, I would like a file to be copied into the config/initializers directory of the app. I could do this in install.rb by copying a template file that resides somewhere in the plugin. Another option would be to require the user to run a generator after install. I know rspec-rails makes you run a generator after you install it, is that the recommended behavior?
And is there anything wrong with copying files into the application in install.rb?
Thanks!
Lou
Does the user need to manually tweak the file? If so, then I would use a generator with parameters. If not, I would prefer that you do it with install.rb. My $.02
Related
I would like to know when we run commands like rails new, rails generate. Which files are actually executed. In general for other tools like rake, rspec( not sure they are called command line tools ) or any other such gem, which files are executed first( at the beginning ).
Thanks.
Most of them are located in this folder https://github.com/rails/rails/tree/3be590edbedab8ddcacdf72790d50c3cf9354434/railties/lib/rails/commands
For instance this https://github.com/rails/rails/blob/3be590edbedab8ddcacdf72790d50c3cf9354434/railties/lib/rails/commands/application/application_command.rb calls the app generator https://github.com/rails/rails/blob/3be590edbedab8ddcacdf72790d50c3cf9354434/railties/lib/rails/generators/rails/app/app_generator.rb
I've just built an app with Electron.
Installing and running electron-packager . creates a folder my-app-win32-x64 with a bunch of assets and DLLs.
This isn't exactly something I can distribute to consumers.
What's the simplest way to generate a Windows installer for my electron executable?
It looks like according to their wiki you can. Follow the instructions here! https://github.com/electron/windows-installer
You may try electron-wix-msi it will help you to create a exe file.
it will basically ask you for your source file Path example D:\xyz\my-app-win32-x64
and will create a desired file at app source path.
I installed Devise in my Rails app and I want to read through the source code and learn how it works. I looked through the entire folder structure of my Rails app, but couldn't find any code (except for the method calls).
I know I can see the source from the Github repository but I would like to see it in my editor and on my local machine.
I'm guessing this code must be in some main Ruby directory, but I'm having trouble locating it. Any help is appreciated. Thanks.
Besides Sergio's suggestion, there is another option.
Within your Rails path
$ bundle open devise
This will open the installed gem in editor with the version specified in Gemfile, very handy.
Try gem unpack, it will copy source of a gem to current directory. For example,
gem unpack rails
Documentation: gem unpack.
Simply run bundle show <gem-name>,
it will list the absolute path of gem source code and in next step simply open source code using text editor like this
subl <gem-code-absolute-path>
For Example
Let's assume you want to read kaminari gem code
bundle show kaminari
/home/abdullah/.rvm/gems/ruby-2.3.0#your_gem_name/gems/kaminari-0.16.3
next step (subl is command to open with Sublime Text Editor)
subl /home/abdullah/.rvm/gems/ruby-2.3.0#your_gem_name/gems/kaminari-0.16.3
Run gem environment - this will display you all the information about your gems, including their location.
Additionally I would advise you to install some IDE with go to source feature - RubyMine is just brilliant (and has 30-day-long free trial), if you want to go for absolutely free go with NetBeans together with Ruby plugin. This feature allows you to navigate quickly to source of clicked method, regardless whether it is defined inside your code or inside the gem.
Clone the github repo in your local machine and explore it using your prefered editor:
git clone https://github.com/plataformatec/devise.git
I know there is no direct support for Ruby gems in the Rhomobile framework. I have read their (sparse!) documentation to migrate in gem support through extensions, but I cannot for the life of me figure out how exactly this should be implemented.
Besides the document linked above being very disjointed, what I can find can't be easily translated to what I need. I am trying to bring devise into my app, but the gem structure is very hierarchical and the example given in the Rhomobile documentation suggests that a given library should be a singular .rb file.
The exact example given is as follows:
Assuming your application is called “mynewapp”, create a directory
under app called lib (or whatever you wish to call it):
$ cd mynewapp
$ mkdir app/lib
$ cp /path/to/my_lib.rb app/lib/my_lib.rb
Then just require lib/my_lib in a given file within my app. Eg:
require 'lib/my_lib'
To translate to the devise gem, my assumption is that I couldn't do something similar, but would instead have to flatten the directory structure out in some way before I could use it. Is that the case or am I missing something? That's a lot of re-writing code...
Also, if anyone knows of any kind of guide to adding gems to the Rhodes framework, I would love to see it! I've looked through most of the official documentation and some non-official and nothing seems to address this at all.
Wow. I don't know how I overlooked this, but it's really simple and nothing like what I was assuming.
If you are using Rhodes via the RubyGems installation, you must add external Ruby libraries to your RubyGems installation directory for the ‘rhodes-framework’ gem. Your RubyGems installation directory can be found with gem env in a terminal.
From the same page linked in question.
My paths didn't match what was listed in that document because I'm using RVM, but I just ran find / -name rhodes-* and just looked for the one followed by /lib/framework.
I am attempting to take a whack at creating my first Rails application template and I am running into a slight issue with the copy_file method.
First some background.... Apparently the Ruby OpenSSL package does not ship with a CA store, so any attempt to connect to an HTTPS service will fail out of the box. The way around this(for Rails 3 apps) is to add the line OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE to the top of your config/environment.rb file. I need to do this on the fly in my template so I can install jQuery.
So I have that all figured out, my general thought is to:
Make a backup of my config/environment.rb file.
Prepend the data to original
Run the jquery:install --ui task
Restore the original config/environment.rb file.
See my template Gist, Lines 25..34 is the relevant section.
So all of that works until step #4 which fails with Error: Could not find "env.orig" in any of your source paths on line #31.
This is VERY perplexing to me because line #28 works, I can see the env.orig file on disk, so why won't the reverse work?
What am I doing wrong?
Update 1:
After looking at the Thor source thor\actions.rb it became clear that Thor uses different paths (not your current project path) for the source and destination. Furthermore my copy was actually not working, it was actually coping the ERB template file, not the already generated file.
After a breather it occurred to me use the right tool for the job so now I have: run 'cp environment.rb environment.~' and run 'mv environment.~ environment.rb' which works just fine. I am fairly certain this would not work on a windows box without the unix tools installed, but I can live with that. Does anyone have a better way?
See my Update for a Why, but the solution was to use the right tool for the job so now I have: run 'cp environment.rb environment.~' and run 'mv environment.~ environment.rb' which works just fine. I am fairly certain this would not work on a windows box without the unix tools installed, but I can live with that.