Skip to content

Instantly share code, notes, and snippets.

@the-undefined
the-undefined / presenter.rb
Last active January 20, 2016 15:27
What to use for the `view_context` in a presenter spec
class Presenter
def user_select_options
view_context.options_from_collection_for_select(
User.all,
:id,
:full_name
)
end
private
@the-undefined
the-undefined / index.rb
Last active January 15, 2016 07:01
Sorting, filtering, and searching using the command pattern to apply a list queries to the collection when they meet criteria for usage.
module Index
module_function
def call(parent_filter:, search_term:, sort:, direction:)
queries = [
filter_query(parent_filter),
search_query(search_term),
sort_query(sort, direction)
]
@the-undefined
the-undefined / index.rb
Created January 15, 2016 06:57
command pattern to build queries based on conditions
module Index
module_function
def call(parent:, search_term:, sort:, direction:)
queries = [
parent_query(parent),
search_query(search_term),
sort_query(sort, direction)
]
@the-undefined
the-undefined / failing_template_for_rails_bug_20738.rb
Last active September 13, 2015 05:45
Failing bug template for rails issue #20738
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile do
source 'https://rubygems.org'
gem 'rails', path: '.'
@the-undefined
the-undefined / rails_bug_20738.rb
Created September 12, 2015 04:03
Bug templates for Rails Engine Issue #20738 - assertions last passed on Rails Version 4.1.9
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '4.1.9'

Keybase proof

I hereby claim:

  • I am the-undefined on github.
  • I am undef_find (https://keybase.io/undef_find) on keybase.
  • I have a public key whose fingerprint is EB04 6762 4B5F 420E CEDA 609D DB45 DF15 B731 7152

To claim this, I am signing this object:

@the-undefined
the-undefined / repository_pattern.rb
Last active August 29, 2015 14:02
Implement the repository pattern with a strategy object (to swap out with an AR model)
class InMemoryStore
attr_accessor :result_set
def initialize
@result_set = []
end
def store(row)
!!(result_set << row)
end
@the-undefined
the-undefined / time_travel_by_delorean.rb
Last active August 29, 2015 13:57
Time travelling in style - got any garbage?
class Delorean
# set_coodinates
# ==============
#
# ## REQUIRES:
#
# - abbr_time => "07:30"
#
# ## RETURNS:
# An instance of Delorean.
@the-undefined
the-undefined / last_tracks.rb
Created February 20, 2014 11:56
Thinking on a further refactoring on a nice blog post regarding flog, using a Session Model came to mind to assist with the responsibilities. POST: http://cored.github.io/blog/2014/02/19/my-gpa-at-code-climate-is-3-dot-59-a-refactoring-story
class LastTracks
attr_accessor :session, :list
def initialize(session)
@session = session
@list = []
yield(self)
end
def blacklist(url)
@the-undefined
the-undefined / invite.rb
Last active January 1, 2016 00:39
Creating a DSL inspired by the rspec assertions but with a conversion method thrown in for added semantic measure.
module Invite
module_function
def Invite(people)
Invitees.new(people)
end
class Invitees
attr_reader :recipients
def initialize people