Trailblazer Introduction by Nick Sutterer
-
Upload
pivorak-meetup -
Category
Software
-
view
477 -
download
3
Transcript of Trailblazer Introduction by Nick Sutterer
class CommentsController < AppController def create Comment::Create.(params) endend
class Comment < ActiveRecord::Base belongs_to :authorend
.comment .text = body .author = avatar
FUNCTIONS
”Create comment”
”View profile”
”Follow user”
POST /comments/
”Create comment”
”View profile”
”Follow user”GET /profiles/1
POST /users/1/follow
POST /comments/
”Create comment”
POST /comments/
”Create comment”
POST /comments/
”Create comment”
“Most Rails developers do not write object-oriented Ruby code.
They write MVC-oriented Ruby code by putting models and controllers in the expected locations.
It takes 2-3 years before developers realize: “Rails is just Ruby.”
-- Mike Perham
POST /comments { id : 1 body: “Great!”, author: { “id”: 1 }}
app concepts comment cell index.rb show.rb contract create.rb update.rb operation create.rb update.rb view index.haml show.haml
app concepts comment cell index.rb show.rb contract create.rb update.rb operation create.rb update.rb view index.haml show.haml
POST /comments { body: “Great!”, author: { “id”: 1 }}
POST /comments
class CommentsController < AppController def create Comment::Create.(params) endend
POST /comments
Comment::Create.(params)
POST /comments
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params) validate do end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params) validate do end end endend
app concepts comment cell index.rb show.rb contract create.rb update.rb operation create.rb update.rb view index.haml show.haml
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params)
end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params)
end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params) Comment.create(params)
end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract do
end
def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract do property :body validates :body, presence: true end
def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract Contract::Create
def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base module Contract class Create < Reform::Form
end endend
class Comment < ActiveRecord::Base module Contract class Create < Reform::Form
end endend
app concepts comment cell index.rb show.rb contract create.rb update.rb operation create.rb update.rb view index.haml show.haml
class Comment < ActiveRecord::Base module Contract class Create < Reform::Form
end endend
class Comment < ActiveRecord::Base module Contract class Create < Reform::Form property :body validates :body, presence: true
end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract Contract::Create
def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract Contract::Create
def process(params) model = Comment.new validate(params, model) do |f| f.save end end endend
class Comment < ActiveRecord::Base belongs_to :authorend
class CommentsController < AppController def create Comment::Create.(params) endend
describe Comment::Create do it do Comment::Create.(params)
endend
describe Comment::Create do it do Comment::Create.(params). model.persisted? must_equal true endend
describe Comment::Update do let(:comment) { Comment::Create.(..) } end
describe Comment::Create do it do Comment::Create.(params). model.persisted? must_equal true endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract Contract::Create
def process(params) model = Comment.new validate(params, model) do |f| f.save
end end endend
class Comment < ActiveRecord::Base class Create < Trailblazer::Operation contract Contract::Create
def process(params) model = Comment.new validate(params, model) do |f| f.save after_save! end end endend
= cell("comment/cell/show", comment)
class Comment::Cell::Show < Cell::ViewModel
end
class Comment::Cell::Show < Cell::ViewModel
end
app concepts comment cell index.rb show.rb contract create.rb update.rb operation create.rb update.rb view index.haml show.haml
class Comment::Cell::Show < Cell::ViewModel property :body def show render end
private def avatar image_tag model.image.url endend
.comment .text = body .author = avatar
class Comment::Cell::Show < Cell::ViewModel property :body def show render end
private def avatar image_tag model.image.url endend
.comment .text = body .author = avatar
app concepts comment cell index.rb show.rb contract create.rb update.rb operation create.rb update.rb view index.haml show.haml
http://leanpub.com/trailblazer
POST_RAILS_BOOK_BUNDLE_159
trailblazer.to
@apotonick