Skip to content

Instantly share code, notes, and snippets.

@svoboda-jan
svoboda-jan / 01_ini_files.rb
Created September 25, 2013 13:24
Rails code sample with CouchDB database, INI config files and custom email validation
# rails initializer to load *.ini into Rails.application.config
Dir.glob(File.join Rails.root, "/config/**/*.ini").each do |file_name|
config_name = File.basename(file_name, ".ini")
Rails.application.config.send "#{config_name}=", IniFile.new(file_name).to_struct.send(Rails.env)
end
@svoboda-jan
svoboda-jan / sorting.rb
Created June 3, 2013 16:34
A simple module include that allows client side model sorting in Vienna
module Vienna
module Sorting
module ClassMethods
def sorted_by(field, options = {})
@_sort_field = field
@_sort_descending = options.fetch(:order, "asc") != 'asc'
end
@svoboda-jan
svoboda-jan / blank.rb
Created May 29, 2013 15:37
ActiveSupport Object extensions (.blank? and .present?) ported to Opal
# encoding: utf-8
class Object
# An object is blank if it's false, empty, or a whitespace string.
# For example, '', ' ', +nil+, [], and {} are all blank.
#
# This simplifies:
#
# if address.nil? || address.empty?
#
@svoboda-jan
svoboda-jan / ajax.rb
Last active December 16, 2015 05:59
A simple module include that allows remote CRUD operations with ajax in Vienna::Model (Now part of Vienna: https://github.com/opal/vienna)
module Vienna
module Ajax
module ClassMethods
def url(url = nil)
url ? @_url = url : @_url
end
def from_form(form)