Skip to content

Instantly share code, notes, and snippets.

View pewniak747's full-sized avatar

Tomasz Pewiński pewniak747

View GitHub Profile
class MyAppError < StandardError
attr_reader :data
def initialize(data)
super(data)
@data = data
end
end
class AuthorizationError < MyAppError
def requesting_user
class Success
attr_reader :data
def initialize(data)
@data = data
end
def success?
true
end
end
app/
services/
create_invoice.rb
correct_invoice.rb
pay_invoice.rb
register_user.rb
register_user_with_google.rb
change_password.rb
TxOJ8Xw5dBR5jvJT9yh7yL6dFiWd9ZC76O6Sz5VilJ75mvKUoTv2XMpv2EJX
CcH0YRG0Xbq7OoOytqf200wW801onZP_y1ZiIIuw2pZiIloNJrsBTyI3udJF
WebUMbI5Udd9nrtW2OH6z6rPQJMzQOHUO0uU-YMecYoGDhZ3p77UY_Bu_GjF
yMFB8zn3XZiJt0K6oo73Gt9B20_aUTSkgzFJ5DrCyGa-fQBvYxTuFPq0G8LP
6v3bD7oNUdOWx3OPn6IfzY9Pltv-5eiGYwT_IUid1WHv5kt2LcsA0jSD_YvO
fq7H3OHPgH_yVwHQvwBKD_w6_m0S_0eR8XhcQm4f0KpmuxP7D2fuQMeEPAJC
wBWYl3X-4c33On10Eqif8h4wdDfr_lJ5FTE4mzi5q2GIroEWgb-cu27BF6b7
xxmaoSG6zM2EICNAStB3HXvuUvEIps4hmeAyKqHUyoqyr0ZiGJ3uBL498kWQ
ii-QOr1Iq6R249ZtqUi7uAAkC9UrPq8MOSfBj_ew3mb-ZArKcHPTIVwT9dV1
EarjH6Wt8lHeyPejqEIb2cxWSiZ6B5iujVAlBYJ1ZFXWSDkcaA4psFVZgKy0
# defined in component 1
@listenTo Application.vent, "someevent", (argument)->
# do something with argument
# defined in component 2
@listenTo Application.vent, "someevent", (argument)->
# do something else with argument
Application.commands.setHandler 'logout', ->
Application.currentUser = null
Application.mainRegion.show(new HomepageView)
Application.execute('navigate' '/')
Application.commands.setHandler 'navigate', (path) ->
Backbone.history.navigate(path)
Application.execute('logout')
# define responses
Application.reqres.setHandler "post:new", ->
new Post
Application.reqres.setHandler "post:get", (id) ->
post = new Post(id: id)
post.fetch()
post
Application.module 'Posts', (Posts, Application, Backbone, Marionete, $, _) ->
Posts.Router = Marionette.AppRouter.extend
appRoutes:
'post/:id': 'show'
class Posts.Controller
show: (id)->
post = new Post(id: id)
view = new Posts.Views.Post(model: post)
Application.mainRegion.show(view)
Application = new Marionette.Application
# this will replace your mainLayout
Application.addRegions
mainRegion: 'body'
Application.on 'initialize:after', ->
Backbone.history.start()
# OtherView definition
class MainLayout extends Marionette.Layout
template: -> "<div id='main-region'></div>"
regions:
mainRegion: '#main-region'
# application startup
App.mainLayout = new MainLayout
$("body").html(@mainLayout.render().$el)
# somewhere in a router