Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
# app/models/booking.rb
class Booking < AR::Base
# ...
end
# app/models/booking/create.rb
class Booking::Create
def initialize(attributes)
module Workflow
extend ActiveSupport::Concern
included do
extend ActiveModel::Naming
include ActiveModel::Validations
end
def call
if valid?
# Thanks to http://www.paulirish.com/2009/random-hex-color-code-snippets for the idea
module ColorSupport
# yields a random color
def self.random_color
color_for((rand() * ((0xFFFFFF + 1) << 0)).to_i.to_s(16))
end
# yields a random color based on the given color
# credit: http://stackoverflow.com/a/43235
#
#
# Rails 4 concern for specifying default attribute values on models
#
# E.g. The following user has defaults defined for `active` and `manager` attributes
#
# class User < ActiveRecord::Base
# include Concerns::DefaultValues
#
# default_value :active, true
require 'active_support/concern'
module NationBuilderApi
extend ActiveSupport::Concern
def token
self.class.token
end
def nationbuilder(to, data)
module SomeLib
module Utilities
module HttpRequest
#send get request to sensor
def send_get_request(url = nil)
send_data url
end
class SshBase
attr_accessor :host, :username, :password, :timeout
class SSHException < Exception; end;
# Callbacks storage for Channel Execute Callbacks
class ChannelExecCallBacks
attr_accessor :on_success, :on_failure, :on_data, :on_extended_data, :on_close
end
module Devices
module Common
class Reports < Devices::Common::Notifiers; end
class Warnings < Devices::Common::Notifiers; end
class Errors < Devices::Common::Notifiers; end
end
end
# event.rb
class Event < ActiveRecord::Base
belongs_to :eventable, polymorphic: true
end
# migration
class CreateEvents < ActiveRecord::Migration
def change
module JasmineFixtures
extend ActiveSupport::Concern
# Saves the markup to a fixture file using the given name
def save_fixture(name)
response.should be_success
fixture_path = File.join(Rails.root, '/spec/javascripts/fixtures')
fixture_file = File.join(fixture_path, name)
fixture = case name
when /\.html$/