Created
November 19, 2012 04:46
-
-
Save cookrn/4109027 to your computer and use it in GitHub Desktop.
Rough shot at what some Lattice Cell code might look like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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