Append to end of file before 'end' declaration

So I’m building my own updating controller that will allow users to
update the version of my app they’re running. I was unable to find a
plugin that did this :frowning:

So now this looks for the last end in a file (such as routes.rb or a
controller and allows the update to add data at the end, right before
the ‘end’ declaration (append is the right work I think).

So I have this little part working, but I’m not sure how to replace the
line.

file.split("\n").reverse.each do |line|

gives us the file in reverse

if line =~ /^(.+)end/

now we need to append here

line number = file.lineno

end
end

file = string that holds the file text
@append = string to append

also after the replacement is done, since it’s in an ‘if’ do I write
‘break’ once or twice (to break the ‘do’ loop).

What do you mean when you say ?

“update the version of my app they’re running”

if you app a gem / plugin ?

are you trying to create a differential/incremental writer?

It sound to me you are trying to do something that can be done with GIT.

Radhames Brito wrote:

What do you mean when you say ?

“update the version of my app they’re running”

if you app a gem / plugin ?

are you trying to create a differential/incremental writer?

It sound to me you are trying to do something that can be done with GIT.

I was thinking about GIT, but was unable to find a way to update with a
GIT. It’s a Ruby On Rails framework I guess. It’s not a gem or plugin.
Yes a differential writer would work.

Mohammad El-abid wrote:

Radhames Brito wrote:

What do you mean when you say ?

“update the version of my app they’re running”

if you app a gem / plugin ?

are you trying to create a differential/incremental writer?

It sound to me you are trying to do something that can be done with GIT.

I was thinking about GIT, but was unable to find a way to update with a
GIT. It’s a Ruby On Rails framework I guess. It’s not a gem or plugin.
Yes a differential writer would work.

I should add that this is so I can add routes to the route.rb file. So I
don’t want to overwrite the user’s custom routes.

I am guessing but, i think your app should be a gem but you dont know
how to
make it a gem,
because what you want to do , it done with rubygems.