version snippets

Ignoring columns with acts_as_versioned

Tagged acts_as_versioned, version, exclude  Languages ruby
def Model

  @@versioned_columns = [:title, :body, :rendered_body, :user_id]  
  acts_as_versioned :if_changed => @@versioned_columns

  def self.non_versioned_columns
      self.class.columns.collect(&:name) - @@versioned_columns
  end
end

Reading gem version from YAML

Tagged gem, rubygem, version, jeweler  Languages ruby

From Jekyll:

module YerGem
  def self.version
    yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
    "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
  end
end

How to get the latest version number from a list of git tags

Tagged bash, git, version, zsh  Languages bash

This will print the latest version number that a git repository has been tagged with:

$ git tag -l 'v*' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tail -n 1
v1.5.6

Note that some versions of the sort command have a —version-sort switch, and some don’t:

sort: unrecognized option `--version-sort'
Try `sort --help' for more information.

Detecting software version with Ansible

Tagged ansible, version  Languages yaml

With Ansible, detecting the version of, for example, Redis or Racket can be done like this:

- name: Detect Redis version
  # Input: Redis server v=3.2.1 sha=00000000:0 malloc=libc bits=64 build=62a67eec83b28403
  # Output: 3.2.1
  shell: redis-server -v | awk '{print $3}' | sed -e 's/v=//'
  changed_when: False
  register: redis_installed_version

- name: Detect racket versions
  # Input: Welcome to Racket v6.6.
  # Output: 6.6
  shell: "racket -v | rev | cut -d ' ' -f1 | rev | sed 's/.$//' | sed 's/^v//'"
  register: racket_installed_version

Example: Download src only if version does not match:

- get_url:
    url: http://download.redis.io/releases/redis-{{redis_version}}.tar.gz
    dest: /usr/local/src/
    sha256sum: "{{redis_sha256}}"
  register: get_redis_result
  when: redis_installed_version.stdout | version_compare(redis_version, '!=')

Which version of Ruby to use with Rails?

Tagged rails, ruby, version  Languages 

To know which version of Ruby is safe to use with Rails one option is to look at the Travis configuration, for example, Rails 5.2: https://github.com/rails/rails/blob/ee1278cc841a883835918fbedb70add96c84543b/.travis.yml#L64-L69

Note the allowed_failures configuration: https://github.com/rails/rails/blob/172bb64ca8d3f1cf88ca7daa4f6a58436e577c69/.travis.yml#L145-L148

This works for Rubygems too: https://github.com/bblimke/webmock/blob/a3c8de2550122d0998cb47292be0bbd2e3f203bf/.travis.yml#L4-L14