This file contains hidden or 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 Hook | |
attr_reader :payload | |
def initialize(payload) | |
@payload = payload | |
end | |
def operation_attributes | |
send(:"#{action}_operation_attributes") | |
end |
This file contains hidden or 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
require 'ostruct' | |
# ClosedStruct is similar to OpenStruct, except: | |
# | |
# * Immutable. Cannot be changed after insantiation. | |
# * Raises NoMethodError on undefined attributes instead of returning nil. | |
# | |
# Example: | |
# struct = ClosedStruct.new do |attributes| | |
# attributes.name1 = 'value1' |
This file contains hidden or 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
def hash2openstruct(attributes) | |
attributes = attributes.reduce({}) do |attributes, (name, value)| | |
if value.is_a?(Hash) | |
value = hash2openstruct(value) | |
elsif value.is_a?(Array) | |
value = value.map { |v| hash2openstruct(v) } | |
end | |
attributes[name] = value | |
attributes | |
end |
This file contains hidden or 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
require 'heroku-api' | |
require 'tmpdir' | |
branch = '' | |
git_url = '' | |
heroku_host = '' | |
heroku_key = '' | |
app_name = "t8y-#{branch.downcase.gsub('_', '-').gsub(/[^a-z0-9\-]/, '')}" | |
heroku = Heroku::API.new(api_key: heroku_key) |
This file contains hidden or 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 RetrieverForm | |
include ActiveModel::Conversion | |
include ActiveModel::Validations | |
validate :existance_of_email | |
def initialize(attributes = {}) | |
@email = attributes[:email] | |
end |
This file contains hidden or 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 RubyExample | |
CONSTANT = /^[0-9]+ regex awesomes$/ | |
attr_reader :colorscheme | |
def initialize(attributes = {}) | |
@colorscheme = attributes[:colorscheme] | |
end | |
def self.values |
This file contains hidden or 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
# Known poll types. Unknown types will raise | |
# an exception. | |
# | |
# Poll::ChoiceTypes.time # => 'Choice::Time' | |
# | |
# @return [Struct] | |
ChoiceTypes = Struct.new(:time, :place, :text).new.tap do |types| | |
types.time = 'Choice::Time' | |
types.place = 'Choice::Place' | |
types.text = 'Choice::Text' |
This file contains hidden or 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
<h1>New Plan</h1> | |
<div ng-app> | |
<%= form_for @plan do |form| %> | |
<div ng-controller="PollCtrl" ng-init="polls = <%= @plan.polls.to_json %>"> | |
<div ng-repeat="poll in polls"> | |
<%= form.fields_for :polls, Poll.new, child_index: '{{$index}}' do |poll_form| %> | |
<%= poll_form.text_field :title, id: 'plan_poll_{{$index}}', value: '{{poll.title}}' %> | |
<% end %> | |
<a href="#" ng-click="remove($index)" ng-show="isRemovable()">Remove</a> | |
</div> |
This file contains hidden or 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
Upgrade rails to 2.3.9. | |
2.3.9 fixes a bug that we had come to depend on | |
(https://github.com/rails/rails/pull/7661). It's best described with an | |
example | |
2.3.8 | |
p = Plan.new | |
p.member = Member.first |
This file contains hidden or 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 Countable | |
def self.included do | |
define_method "#{self.name}s" do | |
# ... | |
end | |
end | |
def self.name | |
self.class.to_s.sub('FeedItem', '').downcase | |
end |