Update files created by generator in Rails application - ruby-on-rails

I have a generator that creates some view files.
I'm wondering about the extensibility of the generator - if there is a change in the generator template file, do I need to modify the existing files which were created by the generator manually?
I know that I can overwrite the existing files by running the generator command. But if I have edited the file after the file generation, overwriting can remove some necessary parts.
What is the best method to apply the latest generator template in the existing file?

Run the generator and then use git to determine which parts of the change to the generated views you want to keep.
You can do this through the command line using git add -p to stage certain parts of files before you commit (From Git Tools - Interactive Staging).
Any decent git GUI would also allow you to stage changes in this way too.

Related

Do these files need to be pushed to Github?

I made a Rails application.
Do i need to push these files to Github?
.browserslistrc
.gitattributes
.rspec
.ruby-version
The short answers are "if you want", and "there's no reason not to".
All of these files do something to make it easier to replicate your code base and setup on another machine. None of them contain secrets that shouldn't be shared.
.browserslistrc
The config to share target browsers and Node.js versions between different front-end tools.
.gitattributes
a simple text file that gives attributes to pathnames.
These attributes affect how the contents stored in the repository are copied to the working tree files when commands such as git switch, git checkout and git merge run. They also affect how Git stores the contents you prepare in the working tree in the repository upon git add and git commit.
.rspec
Read command line configuration options from files
.ruby-version
Many Ruby (or Rails) projects will include a simple .ruby-version file, which simply specifies a version number

How to get files produced during a Travis-CI build?

I am using Travis-CI to test code in a repository. There are quite some files after the testing and I would like to have them at a persistent place. How can I do that under the context of Travis-CI?
As an artificial example, suppose my Travis-CI server runs a C program that stores a large number of integers in a specific file. The file can be found at the Travis-CI server after the build. But how can I get that file? In my use case, this file is large and it would not make sense to read it from the console of Travis-CI; in other words, I would not consider using "cat ..." in .travis.yml.
After some search, here is what I got:
The most convenient way seems to deploy the generated files to GitHub pages. The process is explained here: https://docs.travis-ci.com/user/deployment/pages/. In short:
first, create a GitHub page from the repository under test. This can be done through the Github web of the repository. The outcome includes an additional remote branch called gh-=pages generated.
then, in .travis.yml, use the deploy section to specify the condition to do the deployment.

How to modify application.conf during dist creation in Play Framework 2.3.x

We use Jenkins to run builds for Play Framework 2.3.x project. This works fine and it creates a nice distribution packed in a zip file.
I would like that during the build to update one of the files in conf directory (for instance application.conf) and set the Jenkins build number/id in a variable so that I can always track the distribution file to the originating build.
I know it is possible to copy files to the distribution using "mappings in Universal" but I want to modify an existing file instead. This way I could then easily display the information on a page.
You could use the plain old Ant. With the Unzip Task you can unzip the created zip file. Then you can use the Replace Task to replace a string in your application.conf. And at least the Zip Task to package your project again.
For a more Scala-ish way you could use SBT Editsource.

Xcode 4 project template script execution

Is it possible to execute a script within a custom Xcode 4 project file template? I am not referring to a Run Script within the target build phase but a script that is executed once the template is chosen and prepares the project itself.
I am trying to create a template that forces the addition of a (number of) git submodules. To do so, I envisioned to run a script that is executed once the user creates a project file from my custom template. So far, my research did not succeed in finding a way to run a script once the template is used.
You could try adding a .gitmodules to a project template… no idea if that would fly under Xcode's templates.
If that fails, then, no -- but you can just add the .gitmodules file to the directory (or write a script), and the process should be quick and painless despite no direct support from the ide.
You might even take a middle of the road approach, where the project contained a script (PROJECT_ROOT/config_modules.sh) to add these modules to the repo at that directory. Then create another script to search, exec, and delete the config_modules.sh, once you have created all those projects.

How to write an update hook for git submodules?

I would like to copy some files in the submodules in my "vendor/assets" directory to another directory -- "public/assets." I heard about update hooks but I am not sure if they work for submodules. I wrote a simple hook and ran update from commandline, but it didn't work.
My update hook looks like this:
#.git/gooks/update.rb
#!/usr/bin/env ruby
puts "Copying files..."
So is this even possible?
btw, I'm using Braid to manage my submodules.
The update hook is only run when someone has pushed into the current repository, which doesn't sound like what you want. You could use the post-commit hook, if you want to copy these files into place every time you create a commit in your repository. (That should be sufficient, because you'd need to commit the new version of any submodule in the main project when you change the commit that the submodule is meant to be at. This would be a natural point to update the files in public/assets.)
You say that your test hook isn't being run - that may be simply because you have the name wrong. The update hook must be an executable file called .git/hooks/update (n.b. without a .rb suffix). Similarly, a post-commit hook must be .git/hooks/post-commit.
You shouldn't create hooks in any particular submodule for this task, since the action the hook will be taking is specific to the main project. Because of that, it doesn't really matter whether the change you're worried about it due to committing a new version of the submodules or just updating any random file.
For writing hooks, you'll find the official githooks documentation useful, and possibly these additional tips.

Resources