Skip to content
Browse files

All new app structure and load changes

  • Loading branch information...
1 parent 5b33a21 commit ab78c7e16d2f1f922a9243f14e135f5314ab8912 @avinasha avinasha committed Oct 4, 2012
View
77 .gitignore
@@ -0,0 +1,77 @@
+.sass-cache/
+.bundle
+public/javascripts/app_error_handler.js
+supportbeeapp_production.sql
+solr/data
+db/*.qlite3
+log/*.log
+tmp/**/*
+config/database.yml
+tmp/*
+public/javascripts/backbone/**/**/*.js
+public/javascripts/backbone/*.js
+public/javascripts/backbone/collections/
+public/javascripts/backbone/models/
+doc/api
+doc/app
+*.swp
+*.swo
+*.swm
+*.un~
+*˜
+.DS_Store
+schema.rb
+.tags
+emails/*
+public/uploads/*
+public/images/twitter_auth.png
+public/assets
+public/javascripts/backbone/libs/
+public/javascripts/spin.js
+public/javascripts/utility.js
+public/javascripts/admin/
+public/javascripts/backbone-rails.js
+public/javascripts/payments.js
+public/javascripts/widget/script_coffee.js
+public/javascripts/app_error_handler.js
+public/stylesheets/admin/ie.css
+public/stylesheets/admin/ie6.css
+public/stylesheets/admin/print.css
+public/stylesheets/admin/screen.css
+public/stylesheets/admin/theme.css
+public/stylesheets/app/ie.css
+public/stylesheets/app/ie6.css
+public/stylesheets/app/layout.css
+public/stylesheets/app/screen.css
+public/stylesheets/app/theme.css
+public/stylesheets/app/account.css
+public/stylesheets/app/screen_responsive.css
+public/stylesheets/embed_form.css
+public/stylesheets/formtastic_changes.css
+public/stylesheets/app/email.css
+public/stylesheets/common/marketing.css
+public/stylesheets/common/sprite.css
+public/stylesheets/common/blueprint_tabs.css
+public/stylesheets/widget/
+spec/javascripts/backbone/
+spec/javascripts/admin
+spec/javascripts/UtilitySpec.js
+spec/javascripts/BackboneRailsSpec.js
+*.swn
+uploads/
+bin/
+lib/daemons/log
+log/
+.sass-cache/
+tags
+.rvmrc
+bundler_stubs/
+config/sb_config.yml
+*.swg
+*.swh
+*.swi
+*.swj
+*.swk
+*.swl
+public/stylesheets/common/tinymce.css
+public/stylesheets/common/tinymce_ui.css
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--tty
View
3 Gemfile
@@ -4,10 +4,11 @@ source :rubygems
gem 'sinatra'
gem 'sinatra-initializers'
gem 'rake'
+gem 'activesupport', :require => false
# App Gems
gem 'tinder'
gem 'shotgun', :group => :development
gem 'rspec', :group => :test
-gem 'rack-test', :require => "rack/test", :group => :test
+gem 'rack-test', :require => "rack/test", :group => :test
View
1 Gemfile.lock
@@ -61,6 +61,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ activesupport
rack-test
rake
rspec
View
44 apps/campfire.rb
@@ -1,44 +0,0 @@
-class SupportBeeApp::Campfire < SupportBeeApp::Base
- string :subdomain, :token, :room_ids
- set_title 'Campfire'
- set_stub 'campfire'
-
- class << self
- attr_accessor :campfire_class
- end
-
- self.campfire_class = Tinder::Campfire
-
- def receive_ticket_created
- speech = "[#{payload['company']['name']}:New Ticket] #{payload['ticket']['subject']}\n https://#{payload['company']['subdomain']}.supportbee.com/tickets/#{payload['ticket']['id']}"
- speak(speech)
- end
-
- attr_writer :campfire
- attr_writer :room_ids
- def campfire
- @campfire ||= self.class.campfire_class.new(campfire_domain, :ssl => true, :token => data['token'])
- end
-
- def room_ids
- @room_ids ||= data['room_ids'].split(',').collect {|room_str| room_str.to_i }
- end
-
- def campfire_domain
- data['subdomain'].to_s.sub /\.campfirenow\.com$/i, ''
- end
-
- def speak(message)
- room_ids.each do |room_id|
- room = campfire.find_room_by_id(room_id)
- room.speak(message)
- end
- end
-
- def paste(message)
- room_ids.each do |room_id|
- room = campfire.find_room_by_id(room_id)
- room.paste(message)
- end
- end
-end
View
0 apps/dummy/config.yml
No changes.
View
23 apps/dummy/dummy.rb
@@ -0,0 +1,23 @@
+module Dummy
+ module Event
+ def ticket_created; end
+ def ticket_updated; end
+
+ def reply_created; end
+ def reply_updated; end
+ end
+end
+
+module Dummy
+ module Action
+ def action_button
+ # Handle Action here
+ end
+ end
+end
+
+module Dummy
+ class Base < SupportBeeApp::Base
+
+ end
+end
View
1 config/environments/development.rb
@@ -0,0 +1 @@
+APPS_PATH = "#{PLATFORM_ROOT}/apps"
View
1 config/environments/production.rb
@@ -0,0 +1 @@
+APPS_PATH = "#{PLATFORM_ROOT}/apps"
View
1 config/environments/test.rb
@@ -0,0 +1 @@
+APPS_PATH = "#{PLATFORM_ROOT}/apps"
View
16 config/load.rb
@@ -1,13 +1,15 @@
-sb_apps_root = File.expand_path '../../', __FILE__
-
-ENV["RACK_ENV"] ||= "development"
+PLATFORM_ENV = ENV["RACK_ENV"] ||= "development"
+PLATFORM_ROOT = File.expand_path '../../', __FILE__
require 'bundler'
Bundler.setup
-Bundler.require(:default, ENV["RACK_ENV"].to_sym)
+Bundler.require(:default, PLATFORM_ENV.to_sym)
+
+require 'active_support/core_ext/string/inflections'
-Dir["./lib/**/*.rb"].each { |f| require f }
-Dir["./apps/**/*.rb"].each { |f| require f }
+Dir["#{PLATFORM_ROOT}/lib/**/*.rb"].each { |f| require f }
+Dir["#{PLATFORM_ROOT}/apps/*/*.rb"].each { |f| require f }
-require "#{sb_apps_root}/run_app"
+require "#{PLATFORM_ROOT}/config/environments/#{PLATFORM_ENV}"
+require "#{PLATFORM_ROOT}/run_app"
View
18 lib/base.rb
@@ -2,8 +2,8 @@ module SupportBeeApp
class Base
class << self
attr_accessor :env
- attr_reader :title
- attr_reader :stub
+ attr_reader :name
+ attr_reader :slug
%w(development test production staging).each do |m|
define_method "#{m}?" do
@@ -19,6 +19,10 @@ def schema
@schema ||= []
end
+ def root
+ Pathname.new(APPS_PATH).join(self.to_s.deconstantize.underscore)
+ end
+
def add_to_schema(type, attrs)
attrs.each do |attr|
schema << [type, attr.to_sym]
@@ -37,12 +41,12 @@ def boolean(*attrs)
add_to_schema :boolean, attrs
end
- def set_title(app_title)
- @title = app_title
+ def set_name(app_name)
+ @title = app_name
end
- def set_stub(app_stub)
- @stub = app_stub
+ def set_stub(app_slug)
+ @stub = app_slug
end
def receive(event, data, payload = nil)
@@ -76,4 +80,4 @@ def initialize(event = :'ticket.created', data = {}, payload = nil)
@payload = payload || {}
end
end
-end
+end
View
8 run_app.rb
@@ -6,11 +6,11 @@ class RunApp < Sinatra::Base
register Sinatra::Initializers
def self.setup(app_class)
- get "/#{app_class.stub}" do
- app_class.title
+ get "/#{app_class.slug}" do
+ app_class.name
end
- post "/#{app_class.stub}/:event" do
+ post "/#{app_class.slug}/:event" do
event, data, payload = parse_request
if app = app_class.receive(event, data, payload)
"OK"
@@ -36,4 +36,4 @@ def parse_json_request
end
run! if app_file == $0
-end
+end
View
30 spec/lib/base_spec.rb
@@ -1,19 +1,19 @@
require 'spec_helper'
describe SupportBeeApp::Base do
- describe "ClassMethods" do
- it "should respond to env" do
- SupportBeeApp::Base.env.should == 'test'
- end
+ describe "ClassMethods" do
+ describe "Env" do
+ it "should respond to env" do
+ SupportBeeApp::Base.env.should == 'test'
+ end
- context "schema" do
- describe ".add_to_schema" do
- it "should add to schema" do
- SupportBeeApp::Base.add_to_schema(:string, [:username, :token])
- SupportBeeApp::Base.schema.should == [[:string, :username],[:string, :token]]
- end
- end
- end
-
- end
-end
+ it "should have env helper methods" do
+ SupportBeeApp::Base.should be_test
+ end
+ end
+
+ it "should figure out the root from the class name" do
+ Dummy::Base.root.to_s.should == "#{APPS_PATH}/dummy"
+ end
+ end
+end

0 comments on commit ab78c7e

Please sign in to comment.
Something went wrong with that request. Please try again.