Skip to content

Instantly share code, notes, and snippets.

View indrekj's full-sized avatar

Indrek Juhkam indrekj

View GitHub Profile
class Post
class Mapper
include SomeMapper
def self.find(id)
post = super
if post.published_at
PublishedPost.new(post)
else
Draft.new(post)
@indrekj
indrekj / gist:3164215
Created July 23, 2012 15:23
Separating domain logic: emails?
# I'm trying to follow advice from "Keynote: Architecture the Lost Years by Robert Martin"
# ( https://www.youtube.com/watch?v=WpkDN78P884 )
#
# I created a separate gem for my domain logic. It has entities and interactors.
#
# An example of a rails controller:
class CommentsController < ApplicationController
include MyApp::Interactors
def create
@indrekj
indrekj / gist:3829339
Created October 3, 2012 19:41
UseCase
module Trip
module Controls
class AttendsTripOffer
def initialize(request)
Validator.validate!(request)
@user = FacebookUserFetcher.get(request.access_token)
@trip_offer = Repositories::TripOffer.find_by_id(request.trip_offer_id)
end
@indrekj
indrekj / gist:4054976
Created November 11, 2012 14:03
Counts how many times have files changed
#!/bin/bash
START=bff040e58fa3f00a5c8caada4d1c00718d2810f2
function filesChanged() {
prev=$START
revs=`git rev-list $START..HEAD --no-merges`
for rev in $revs; do
changed=`git diff --name-only $prev $rev --diff-filter=M`

Interactor

module Trip
  module Controls
    class AttendsTripOffer
      def initialize(request)
        Validator.validate!(request)

        @user = FacebookUserFetcher.get(request.access_token)
        @trip_offer = Repositories::TripOffer.find_by_id(request.trip_offer_id)
require "dm-mapper"
require "data_mapper/engine/arel"
DM = DataMapper::Environment.new
DM.engines[:arel] = DataMapper::Engine::Arel::Engine.new("sqlite3:/db/development.sqlite3")
require "virtus"
class Variant
include DataMapper::Model
module Admin
class CategoriesController < BaseController
def new
@form = CategoryForm.new
end
def create
@form = CategoryForm.new(params[:category])
if @form.valid?
require "virtus"
module Bitbot
module Live
class Depth
include Virtus
attribute :price, Price
end
end
class MakesBookingPayment
def initialize(booking, payment_details)
@booking = booking
@payment_details = payment_details
end
def pay!
response = process_payment
Transaction.record_purchase(@booking, response)
:!mutant -r ./spec/spec_helper.rb --rspec-dm2 ::Inflecto\.underscore
Spec file(s): "spec/unit//class_methods/underscore_spec.rb" not found for Inflecto.underscore:/Users/indrek/inflecto/lib/inflecto.rb:43:9f2af
...
...
Took: (0.05s)
subjects: 1
mutations: 52
noop_fails: 0