Switching an existing Phoenix app from Brunch to Webpack

Phoenix version 1.4 onwards will be using webpack as a module bundler for javascript. This blog post is about the steps which I followed to switch from brunch to webpack in an existing Phoenix project. Clone Phoenix Since Phoenix 1.4 is unreleased as of when this blog is published, we will generate a new project using Phoenix source installer. Clone Phoenix and run - cd phoenix/installer mix phx.new dev_app --dev Run npm install in dev_app/assets folder.

Ruby 2.6 KeyError#initialize accepts message, receiver, and key as arguments

Ruby 2.6.0-preview2 was recently released. Ruby 2.5.0 introduced public instance methods KeyError#key and KeyError#receiver. You can read my earlier blog about KeyError#key & KeyError#receiver here. Ruby csv library raises a KeyError on CSV::Row#fetch method when the field is not found. def fetch(header, *varargs) # ... raise KeyError, "key not found: #{header}" # ... end Instead of raising a KeyError shown above, how about if this is possible? - raise KeyError.

Ruby 2.5 adds KeyError#receiver and KeyError#key

Ruby 2.5.0 was recently released. Earlier to Ruby 1.9 Hash#fetch method would raise IndexError for an invalid key. An IndexError is raised when the given index value is invalid. irb(main):001:0> hash = { 'foo' => 'bar' } irb(main):002:0> hash.fetch('foo') IndexError: key not found from (irb):2:in `fetch' from (irb):2 from :0 KeyError class was introduced in Ruby 1.9 and it inherits from IndexError class. It is raised when the specified key is not found.

Ruby 2.6 added options to Exception#full_message

Ruby 2.6.0-preview2 was recently released. Ruby 2.5.0 The Exception#full_message method returns a formatted string of the exception. >> e = StandardError.new('foo') => #<StandardError: foo> >> e.full_message => "\e[1mTraceback\e[m (most recent call last):\n(irb):14:in `full_message': \e[1mfoo (\e[1;4mStandardError\e[m\e[1m)\e[m\n" The string contains escape sequences too. It was proposed that escape sequences should be excluded from the error message. Nobuyoshi Nakada said that since Exception#full_message is expected to return the message printed to stderr, escape sequences are intentional.

Ruby 2.6 adds Matrix#antisymmetric?

Ruby 2.6.0-preview2 was recently released. A matrix according to Wikipedia is a rectangular array of numbers. Matrix class in ruby represents a mathematical matrix. >> x = Matrix[[1, 2], [3, 4]] => Matrix[[1, 2], [3, 4]] Ruby 2.5.0 Let’s say we want to find out if a matrix is a skew-symmetric (or antisymmetric) matrix. >> matrix1 = Matrix[[0, 1], [-1, 0]] => Matrix[[0, 1], [-1, 0]] >> matrix1 == -matrix1.

Kernel#system now accepts exception flag as an argument

Ruby 2.6.0-preview1 was recently released. Using Kernel#system we can execute terminal commands. It executes commands in a subshell. >> Kernel.system('echo atul') atul => true The method Kernel#system returns false for non zero exit status. Ruby 2.5 puts "system method returns: #{system('bundle install')}" ➜ hello git:(master) ✗ ruby test.rb Fetching source index from https://rubygems.org/ Could not fetch specs from https://rubygems.org/ system method returns: false To raise an error if the command returns false we would –

Using Ruby 2.5's IO#close

Ruby 2.5 was recently released. IO class is the basis for all input and output. You can use the public methods of IO class to open, write, read and close the IO stream. The close method makes the IO stream unavailable for any further data operations. Ruby’s IO#close which would earlier raise an error with message “stream closed”, but it is refined to “stream closed in another thread”. The new message is more clear for the user.