Skip to content

Instantly share code, notes, and snippets.

@cookrn
Created November 19, 2012 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cookrn/4109027 to your computer and use it in GitHub Desktop.
Save cookrn/4109027 to your computer and use it in GitHub Desktop.
Rough shot at what some Lattice Cell code might look like
require 'lattice'
class ApplicationCell
include Lattice::Cell
# Other custom stuff
end
class Person < Struct.new( :name , :birthday )
end
class Address < Struct.new( :month , :day , :year )
end
# Or maybe more like this for immutable magic
#
# class Person < Lattice::ValueObject
# property :name
# property :birthday
# end
class PersonCell < ApplicationCell
def update_address( person , address )
# performs data transformation
end
end
require 'lattice'
class Person < Struct.new( :name , :birthday )
end
class PersonCell
include Lattice::Cell
# ONLY here for example
# Probably defined in `Lattice::Cell`
def call( *args , &block )
desired_method = args.shift
# Other things could happen here like turning params into value objects
send(
:future,
desired_method,
*args,
&block
).value
end
def update_address( person , address )
# performs data transformation
end
end
class PersonResource < WebMachine::Resource
include Lattice::Cell
def process_post
PersonCell.new( params ).call :update_address
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment