# frozen_string_literal: true | |
namespace :db do | |
namespace :structure do | |
STRUCTURE_PATH = 'db/structure.sql' | |
def clean_structure_file | |
original = File.read(STRUCTURE_PATH) | |
cleaned = original.dup |
RedDotRubyConf 2015 links & resources
class Ticket < ActiveRecord::Base | |
belongs_to :grouper | |
belongs_to :user | |
validate :user_cant_be_blacklisted, on: :confirmation | |
validate :user_cant_double_book, on: :confirmation | |
validate :grouper_cant_be_full, on: :confirmation | |
validate :grouper_cant_have_occurred, on: :confirmation |
require 'fiddle' | |
module Python | |
def __class__= k | |
value = _wrap self | |
[k.object_id<<1].pack('Q').unpack('C8').each_with_index {|n,i|value[i+8]=n} | |
end | |
def _wrap klass; Fiddle::Pointer.new Fiddle.dlwrap klass; end | |
end |
# Packages and modules are imported to the scope using the import statement. | |
# If you wanted just a particular object from a module/package you can use | |
# the from <module> import <object> | |
import sys | |
import requests | |
# There are no constants in Python, still we can use a naming convention to | |
# imply that to the user of a library. | |
BASE_URL = "https://api.github.com" |
;; 1.1.1 Lisp atoms | |
;; If a list is preceded by single quote, we are telling lisp interpreter to take it as it is | |
'(sachin | |
rahul | |
saurav | |
laxman) | |
;; If a list is not preceded by single quote, lisp interpreter treats first atom of the list as a function, | |
;; and passes all the remaining atoms as arguments to it, and returns result of the function | |
(+ 2 2) | |
'(this list has (list inside it)) |
class Email < ActiveRecord::Base | |
scope :by_account, -> account_id { where(account_id: account_id) } | |
attr_accessible :template_name, :subject, :content, :user_id, :account_id | |
validates :subject, presence: true | |
validates :template_name, presence: true | |
validates :template_name, uniqueness: { :scope => :account_id } | |
validates :content, presence: true |
With Heroku's JRuby support you may have already seen that you can run TorqueBox Lite on Heroku. But, that only gives you the web features of TorqueBox. What about scheduled jobs, backgroundable, messaging, services, and caching?
With a small amount of extra work, you can now run the full TorqueBox (minus STOMP support and clustering) on Heroku as well! I've successfully deployed several test applications, including the example Rails application from our Getting Started Guide which has a scheduled job, a service, and uses backgroundable and messaging.
This example uses TorqueBox 3.0.2, but the instructions may work with other TorqueBox versions.
Steps Required
- Create a JRuby application on Heroku, or convert an existing application to JRuby. Make sure your application works on JRuby on Heroku before throwing TorqueBox into the mix.
- Add th
My issues with Modules
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval
.
You can find instance_eval
used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base