Skip to content

Instantly share code, notes, and snippets.

@cookrn

cookrn/example.rb

Created Nov 19, 2012
Embed
What would you like to do?
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