View GuestObjectUsingNullObjectDesignPattern.swift
import Foundation
protocol User {
var firstName: String { get }
var lastName: String { get }
func fullName() -> String
}
class CurrentUser: User {
View OptionalUserExample.swift
import Foundation
struct User {
let firstName: String
let lastName: String
func fullName() -> String {
return "\(firstName) \(lastName)"
}
}
View ObjectAnalytics.swift
import Foundation
// this is either a third party SDK interface or your own analytics client implementation
// that actually sends JSON across the wire to deliver tracked analytics events
protocol AnalyticsClient {
func sendAnalyticsDataToTheBackend(_ eventJSON: [String: Any])
}
final class ConcreteAnalyticsClient: AnalyticsClient {
func sendAnalyticsDataToTheBackend(_ eventJSON: [String: Any]) {
View HLPlaceResourceManager.h
//
// HLPlaceResourceManager.h
// HeyLets2
//
// Created by Alex Bush on 11/18/14.
// Copyright (c) 2014 HeyLets. All rights reserved.
//
#import <Foundation/Foundation.h>
View boolean_value.rb
class BooleanValue < Value
end
View for_socpe.rb
def for_scope(scope, user = GuestUser.new)
case scope
when 'saved'
user.saved_articles.scoped
when 'my'
user.tagged_articles.scoped
else
scoped
end
end
View article.rb
class Article < ActiveRecord::Base
include Categorizable
APPROVED = 'approved'
PENDING = 'pending'
REJECTED = 'rejected'
attr_accessible :approved_at, :url, :body, :image, :rating, :state, :title, :news_source_id, :published_at
validates :url, :uniqueness => true
View articles_controller.rb
class Api::Private::ArticlesController < Api::Private::BaseController
include ArticlesSearch
before_filter :find_or_create_article, except: [:index]
PAGE_SIZE = 20
attr_accessor :total_pages
def index
@articles = Article
View article.rb
class Article < ActiveRecord::Base
include Categorizable
APPROVED = 'approved'
PENDING = 'pending'
REJECTED = 'rejected'
attr_accessible :approved_at, :url, :body, :image, :rating, :state, :title, :news_source_id, :published_at
validates :url, :uniqueness => true
View articles_controller.rb
class Api::Private::ArticlesController < Api::Private::BaseController
include ArticlesSearch
before_filter :find_or_create_article, except: [:index]
PAGE_SIZE = 20
def index
@articles = Article.scoped
total_pages = 0
page = params[:page] ? params[:page] : 1