This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module FilterJson | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def filter_json (*attributes) | |
(@filter_attributes ||= Set.new).merge(attributes.map { |a| a.to_s }) | |
end | |
def filter_attributes | |
if superclass.respond_to?(:filter_attributes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AbstractClass | |
def self.extended (base) | |
base.instance_eval do | |
self.abstract_class = true if respond_to?(:abstract_class=) | |
@abstract_class = true unless instance_variable_defined?(:@abstract_class) | |
end | |
end | |
def new (*) | |
if @abstract_class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MessagesController < ActionController::Base | |
respond_to :html | |
def show | |
resource = Message.find(params[:id]) | |
action = resource.sent? ? :edit : :show | |
respond_with(resource, :action => action) | |
end | |
def edit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClampValidator < Grape::Validations::SingleOptionValidator | |
def validate_param!(attr_name, params) | |
params[attr_name] = clamp(params[attr_name], @option.min, @option.max) | |
end | |
def clamp (value, min, max) | |
[[value, max].min, min].max | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NilClass | |
def method_missing (*) | |
nil | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parse: (attributes) -> | |
_.reduce attributes, (object, value, key) -> | |
camelized = _str.camelize(key) | |
object[camelized] = value | |
object | |
, {} | |
format: (attributes) -> | |
_.reduce attributes, (object, value, key) -> | |
underscored = _str.underscored(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unique = (message) -> | |
message ?= 'must be unique' | |
@using (value, attribute, model) -> | |
query = model.constructor.query() | |
query.count().where(attribute, value).first() | |
.then (row) -> | |
row.count isnt '0' | |
, message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Promise = require('bluebird'), | |
User = require('./user'), | |
knex, query; | |
knex = User.prototype._builder(User.prototype.tableName); | |
query = function (q) { | |
q.distinct() | |
.innerJoin('orders', function () { | |
this.on('users.id', '=', 'orders.user_id') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!function() { | |
"use strict"; | |
var e = "undefined" != typeof window ? window : global; | |
if ("function" != typeof e.require) { | |
var t = {}, s = {}, r = function(e, t) { | |
return {}.hasOwnProperty.call(e, t) | |
}, a = function(e, t) { | |
var s, r, a = []; | |
s = /^\.\.?(\/|$)/.test(t) ? [e, t].join("/").split("/") : t.split("/"); | |
for (var n = 0, i = s.length; i > n; n++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var Promise = require('bluebird'), | |
slice = Array.prototype.slice, | |
promiseLoop; | |
promiseLoop = function (fn, thisArg) { | |
var argsArray = slice.call(arguments, 2); | |
return function () { | |
var pending = Promise.pending(), |
OlderNewer