Skip to content

Instantly share code, notes, and snippets.

View vl3's full-sized avatar

Valentín Sanjuan vl3

  • Mendoza, Argentina
View GitHub Profile
@vl3
vl3 / domain.md
Created February 26, 2021 05:12 — forked from vsavkin/domain.md
Building Rich Domain Models in Rails

Building Rich Domain Models in Rails

Abstract

Domain model is an effective tool for software development. It can be used to express really complex business logic, and to verify and validate the understanding of the domain among stakeholders. Building rich domain models in Rails is hard. Primarily, because of Active Record, which doesn't play well with the domain model approach.

One way to deal with this problem is to use an ORM implementing the data mapper pattern. Unfortunately, there is no production ready ORM doing that for Ruby. DataMapper 2 is going to be the first one.

Another way is to use Active Record just as a persistence mechanism and build a rich domain model on top of it. That's what I'm going to talk about here.

@vl3
vl3 / git-reset-author.sh
Created June 25, 2020 03:50 — forked from bgromov/git-reset-author.sh
Git: reset author for ALL commits
#!/bin/sh
# Credits: http://stackoverflow.com/a/750191
git filter-branch -f --env-filter "
GIT_AUTHOR_NAME='Newname'
GIT_AUTHOR_EMAIL='new@email'
GIT_COMMITTER_NAME='Newname'
GIT_COMMITTER_EMAIL='new@email'
" HEAD
@vl3
vl3 / feature_toggle.py
Created August 5, 2019 00:04
Feature toggle
class FeatureToggle(object):
def __init__(self, old, new, toggle):
self.old = old
self.new = new
self.toggle = toggle
def __getattr__(self, name):
def wrapper(*args, **kwargs):
instance_to_use = self.new if self.toggle else self.old
return getattr(instance_to_use, name)(*args, **kwargs)
@vl3
vl3 / flattenize.rb
Created November 10, 2016 05:36
CitrusByte exercise
def flatten ary
flattenized_ary = []
ary.each do |element|
if element.class == Array
flattenized_ary += flatten(element)
else
flattenized_ary << element
end
end
flattenized_ary
ActiveAdmin.register Band do
permit_params :name, :description, artists_attributes: [:id]
# nested form to edit and new
form do |f|
f.inputs "Band" do
f.input :name
f.input :description
f.input :artists, :as => :select, :input_html => { :multiple => true }