- Course: https://www.codeschool.com/courses/rails-4-patterns
- Slides: http://courseware.codeschool.com.s3.amazonaws.com/rails4patterns/rails_4_patterns.pdf
- guard clause - http://www.thechrisoshow.com/2009/02/16/using-guard-clauses-in-your-ruby-code/
- scopes always return a chainable object!
- merge scopes
merge(Comment.approved)
- concerns in controllers
- serializers!
article https://robots.thoughtbot.com/tidy-views-and-beyond-with-decorators
- decorators
- draper gem
- unobstrusive ruby https://robots.thoughtbot.com/unobtrusive-ruby
- NullObject pattern https://robots.thoughtbot.com/design-patterns-in-the-wild-null-object
- Tell don’t Ask principle where you should tell an object to do something as opposed to extracting data from it and implementing behavior on the caller code
- Single Responsability Principle where every object should have only one responsability and it should be encapsulated by one class
- Open/Closed Principle where each object is open for extension but closed for modification
- prinsiples - Ruby Science book from thoughtbots
- nasty callback soup
article http://karolgalanciak.com/blog/2014/09/17/rails-useful-patterns/
- Pass form objects as data aggregates to service objects
- Create flexible service objects with listeners
- Extract context classes - SimpleDelegator
- About the form objects - I was asking myself the same question some time ago so I tried both approaches. Probably in 100% cases I regretted putting all the logic in form objects. It was tempting at the beginning to put everything there but the usecases became more complex and form object was responsible for tens of things. Now I always extract business logic to the service objects and form objects are responsible only for aggregating data, validations and writing data to the models and I'm really happy with the code.
article http://addyosmani.com/blog/essential-js-namespacing/
- http://www.jspatterns.com/
- http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752
- namespacing
- Automating nested namespacing - function to extend ns
- Dependency declaration pattern - declare deps at top of ns
- Deep object extension - put ns into ns thrugh extend
- 1.Single global variables - myApplication_
-
- Object literal notation - key:value pair
-
- Nested namespacing - nest things, use
myApp["models"] = myApp["models"] || {};
thing
- Nested namespacing - nest things, use
-
- Immediately-invoked Function Expressions (IIFE)s -
(function(){ /*...*/})();
-})(namespace);
- http://benalman.com/news/2010/11/immediately-invoked-function-expression/
- Immediately-invoked Function Expressions (IIFE)s -
-
- Namespace injection -
(function() { }).apply(myApp.utils);
apply/inject props in function to object - use likeinclude Module
- Namespace injection -
article http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html