lib/generators/trestle/auth/otp/install/install_generator.rb in trestle-auth-otp-0.2.1 vs lib/generators/trestle/auth/otp/install/install_generator.rb in trestle-auth-otp-0.2.2
- old
+ new
@@ -33,13 +33,17 @@
def generate_admin
generate "trestle:auth:otp:admin", model, ("--devise" if devise?)
end
def generate_migration
+ filename = 'migration.rb'
+ path = File.expand_path(find_in_source_paths(filename.to_s))
+ text = File.read(path)
+ content = text.gsub('[]', "[#{ActiveRecord::Migration.current_version}]")
+ File.open(path, "w") { |file| file << content }
- migration_template("migration.rb", "db/migrate/add_otp_fields.rb")
-
+ migration_template(filename, "db/migrate/add_otp_fields.rb")
end
def devise?
options[:devise]
end
@@ -56,16 +60,24 @@
def template_content(path, options={})
path = File.expand_path(find_in_source_paths(path.to_s))
context = options.delete(:context) || instance_eval("binding")
- capturable_erb = CapturableERB.new(::File.binread(path), trim_mode: "-", eoutvar: "@output_buffer")
-
- content = capturable_erb.tap do |erb|
+ content = capturable_erb(path).tap do |erb|
erb.filename = path
end.result(context)
end
+
+ def capturable_erb(path)
+ match = ERB.version.match(/(\d+\.\d+\.\d+)/)
+
+ if match && match[1] >= "2.2.0" # Ruby 2.6+
+ CapturableERB.new(::File.binread(path), trim_mode: "-", eoutvar: "@output_buffer")
+ else
+ CapturableERB.new(::File.binread(path), nil, "-", "@output_buffer")
+ end
+ end
end
end
end
end
-end
+end
\ No newline at end of file