Class: SoksUpgrade
- Inherits:
-
Object
- Object
- SoksUpgrade
- Defined in:
- lib/soks-upgrade-0.0.2.rb
Instance Method Summary collapse
- #load_old_revisions(filename) ⇒ Object
- #new_filename_for_old(old_filename) ⇒ Object
- #save_new_revisions(old_filename, revisions) ⇒ Object
- #upgrade_content(directory) ⇒ Object
- #upgrade_revisions(directory) ⇒ Object
- #upgrade_textile(filename) ⇒ Object
Instance Method Details
#load_old_revisions(filename) ⇒ Object
25 26 27 |
# File 'lib/soks-upgrade-0.0.2.rb', line 25 def load_old_revisions( filename ) File.open( filename ) { |file| return Marshal.load( file ) } end |
#new_filename_for_old(old_filename) ⇒ Object
38 39 40 41 42 |
# File 'lib/soks-upgrade-0.0.2.rb', line 38 def new_filename_for_old( old_filename ) basename = File.basename( old_filename, '.*') new_extension = '.yaml' File.join( File.dirname(old_filename), basename ) + new_extension end |
#save_new_revisions(old_filename, revisions) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/soks-upgrade-0.0.2.rb', line 29 def save_new_revisions( old_filename, revisions ) File.open(new_filename_for_old( old_filename ), 'w' ) do |file| revisions.each do |revision| YAML.dump( [revision.number, revision.changes, revision., revision.created_at ] , file ) file.puts end end end |
#upgrade_content(directory) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/soks-upgrade-0.0.2.rb', line 62 def upgrade_content( directory ) search = File.join( directory,'content', "*.textile" ) Dir[ search ].each do |filename| puts "Upgrading #{filename}" upgrade_textile( filename ) end end |
#upgrade_revisions(directory) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/soks-upgrade-0.0.2.rb', line 44 def upgrade_revisions( directory ) search = File.join( directory,'content', "*.marshal" ) Dir[ search ].each do |filename| puts "Upgrading #{filename}" save_new_revisions( filename, load_old_revisions( filename )) File.delete filename end end |
#upgrade_textile(filename) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/soks-upgrade-0.0.2.rb', line 53 def upgrade_textile( filename ) textile = IO.readlines( filename ).join textile.gsub!(/\[\[\s*(.*?)\s*(|:\s*(.*?)\s*)\]\]/) do |m| title, page = $1, $3 page ? "[[ #{title} => #{page} ]]" : "[[ #{title} ]]" end File.open( filename, 'w' ) { |f| f.puts textile } end |