deals 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/Gemfile +17 -0
  2. data/Gemfile.lock +153 -0
  3. data/LICENSE +339 -0
  4. data/README.md +60 -0
  5. data/Rakefile +40 -0
  6. data/app/assets/javascripts/deals/application.js +15 -0
  7. data/app/assets/stylesheets/deals/application.css +13 -0
  8. data/app/controllers/application_controller.rb +5 -0
  9. data/app/controllers/categories_controller.rb +8 -0
  10. data/app/controllers/deals/application_controller.rb +4 -0
  11. data/app/controllers/deals_controller.rb +30 -0
  12. data/app/controllers/home_controller.rb +8 -0
  13. data/app/controllers/places_controller.rb +8 -0
  14. data/app/helpers/deals/application_helper.rb +4 -0
  15. data/app/models/category.rb +4 -0
  16. data/app/models/deal.rb +9 -0
  17. data/app/models/place.rb +4 -0
  18. data/app/uploaders/photo_uploader.rb +55 -0
  19. data/app/views/layouts/deals/application.html.erb +14 -0
  20. data/bin/deals +12 -0
  21. data/config/routes.rb +7 -0
  22. data/db/migrate/20121212014610_create_deals.rb +20 -0
  23. data/db/migrate/20121212015114_create_categories.rb +10 -0
  24. data/db/migrate/20121212015129_create_places.rb +10 -0
  25. data/db/migrate/20121218023245_add_photo_to_deals.rb +5 -0
  26. data/lib/deals.rb +4 -0
  27. data/lib/deals/cli.rb +96 -0
  28. data/lib/deals/engine.rb +5 -0
  29. data/lib/deals/version.rb +3 -0
  30. data/lib/tasks/deals_tasks.rake +4 -0
  31. data/test/deals_test.rb +7 -0
  32. data/test/dummy/README.rdoc +261 -0
  33. data/test/dummy/Rakefile +7 -0
  34. data/test/dummy/app/assets/javascripts/application.js +15 -0
  35. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  36. data/test/dummy/app/controllers/application_controller.rb +3 -0
  37. data/test/dummy/app/helpers/application_helper.rb +2 -0
  38. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/test/dummy/config.ru +4 -0
  40. data/test/dummy/config/application.rb +59 -0
  41. data/test/dummy/config/boot.rb +10 -0
  42. data/test/dummy/config/database.yml +25 -0
  43. data/test/dummy/config/environment.rb +5 -0
  44. data/test/dummy/config/environments/development.rb +37 -0
  45. data/test/dummy/config/environments/production.rb +67 -0
  46. data/test/dummy/config/environments/test.rb +37 -0
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/test/dummy/config/initializers/inflections.rb +15 -0
  49. data/test/dummy/config/initializers/mime_types.rb +5 -0
  50. data/test/dummy/config/initializers/secret_token.rb +7 -0
  51. data/test/dummy/config/initializers/session_store.rb +8 -0
  52. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/test/dummy/config/locales/en.yml +5 -0
  54. data/test/dummy/config/routes.rb +4 -0
  55. data/test/dummy/public/404.html +26 -0
  56. data/test/dummy/public/422.html +26 -0
  57. data/test/dummy/public/500.html +25 -0
  58. data/test/dummy/public/favicon.ico +0 -0
  59. data/test/dummy/script/rails +6 -0
  60. data/test/integration/navigation_test.rb +10 -0
  61. data/test/test_helper.rb +15 -0
  62. metadata +202 -0
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ Deals Gem (Engine)
2
+ ========
3
+
4
+ Modular / mountable Deals API. Features:
5
+
6
+ * RESTful webservice for accessing deals
7
+
8
+ * Fully defined backend RailsAdmin interface for adding deals on the backend
9
+
10
+
11
+ Announcements
12
+ ========
13
+
14
+ * Review the installation process below.
15
+
16
+
17
+ Installation
18
+ ========
19
+
20
+ * First create a new rails project:
21
+ rails new sweet_app
22
+
23
+ * Config your database.yml and create the databases
24
+
25
+ * Add to Gemfile:
26
+
27
+ gem "deals"
28
+
29
+ * Next, run bundle install:
30
+
31
+ bundle install
32
+
33
+ * Next, run the deals install command:
34
+
35
+ deals install
36
+
37
+ (NOTE: If you run into an error saying that deals gem is missing, use bundle exec deals install)
38
+
39
+ * Deals is now installed and ready
40
+
41
+ * Deals API is located at /deals
42
+
43
+ * To view API end points run: rake routes
44
+
45
+ More Details
46
+ ========
47
+
48
+ Visit the project website [here][project-website].
49
+
50
+ [project-website]: http://deals.barrettgriffith.com/
51
+
52
+ TODO
53
+ ========
54
+
55
+ * Add multiple photos for each deal
56
+
57
+ Copyright
58
+ ========
59
+
60
+ Copyright (c) 2012 Barrett Griffith. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Deals'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+
4
+
5
+ end
@@ -0,0 +1,8 @@
1
+ class CategoriesController < ActionController::Base
2
+ respond_to :json
3
+
4
+ def index
5
+ @categories = Category.all.map { |c| { 'id' => c.id, :name => c.name, :slug => c.slug} }
6
+ respond_with(@categories)
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Deals
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,30 @@
1
+ class DealsController < ActionController::Base
2
+ respond_to :json
3
+
4
+ def index
5
+ place = params[:place]
6
+ category = params[:category]
7
+
8
+ if place.present?
9
+ places = Place.where(:slug => place)
10
+ place_id = places.first.id if places.any?
11
+ end
12
+
13
+ if category.present?
14
+ categories = Category.where(:slug => category)
15
+ category_id = categories.first.id if categories.any?
16
+ end
17
+
18
+ if place_id.present? && category_id.present?
19
+ @deals = Deal.where(:place_id => place_id, :category_id => category_id)
20
+ elsif place_id.present?
21
+ @deals = Deal.where(:place_id => place_id)
22
+ elsif category_id.present?
23
+ @deals = Deal.where(:category_id => category_id)
24
+ else
25
+ @deals = Deal.all
26
+ end
27
+
28
+ respond_with(@deals)
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ class HomeController < ActionController::Base
2
+
3
+ layout 'application'
4
+
5
+ def index
6
+ end
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ class PlacesController < ActionController::Base
2
+ respond_to :json
3
+
4
+ def index
5
+ @places = Place.all.map { |p| { 'id' => p.id, :name => p.name, :slug => p.slug} }
6
+ respond_with(@places)
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Deals
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ class Category < ActiveRecord::Base
2
+ has_many :deals
3
+ attr_accessible :name, :slug
4
+ end
@@ -0,0 +1,9 @@
1
+ class Deal < ActiveRecord::Base
2
+ mount_uploader :photo, PhotoUploader
3
+
4
+ belongs_to :place
5
+ belongs_to :category
6
+ attr_accessible :photo, :photo_cache, :remove_photo, :commission, :deleted_at, :place_id, :category_id, :description, :email, :first_line, :phone, :second_line, :website
7
+
8
+
9
+ end
@@ -0,0 +1,4 @@
1
+ class Place < ActiveRecord::Base
2
+ has_many :deals
3
+ attr_accessible :name, :slug
4
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ class PhotoUploader < CarrierWave::Uploader::Base
4
+
5
+ # Include RMagick or MiniMagick support:
6
+ # include CarrierWave::RMagick
7
+ # include CarrierWave::MiniMagick
8
+
9
+ # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
10
+ # include Sprockets::Helpers::RailsHelper
11
+ # include Sprockets::Helpers::IsolatedHelper
12
+
13
+ # Choose what kind of storage to use for this uploader:
14
+ storage :file
15
+ # storage :fog
16
+
17
+ # Override the directory where uploaded files will be stored.
18
+ # This is a sensible default for uploaders that are meant to be mounted:
19
+ def store_dir
20
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
21
+ end
22
+
23
+ # Provide a default URL as a default if there hasn't been a file uploaded:
24
+ # def default_url
25
+ # # For Rails 3.1+ asset pipeline compatibility:
26
+ # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
27
+ #
28
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
29
+ # end
30
+
31
+ # Process files as they are uploaded:
32
+ # process :scale => [200, 300]
33
+ #
34
+ # def scale(width, height)
35
+ # # do something
36
+ # end
37
+
38
+ # Create different versions of your uploaded files:
39
+ # version :thumb do
40
+ # process :scale => [50, 50]
41
+ # end
42
+
43
+ # Add a white list of extensions which are allowed to be uploaded.
44
+ # For images you might use something like this:
45
+ def extension_white_list
46
+ %w(jpg jpeg gif png)
47
+ end
48
+
49
+ # Override the filename of the uploaded files:
50
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
51
+ # def filename
52
+ # "something.jpg" if original_filename
53
+ # end
54
+
55
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Deals</title>
5
+ <%= stylesheet_link_tag "deals/application", :media => "all" %>
6
+ <%= javascript_include_tag "deals/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/bin/deals ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ begin
6
+ require 'deals/cli'
7
+ rescue LoadError => e
8
+ warn 'Could not load "deals/cli"'
9
+ exit -1
10
+ end
11
+
12
+ Deals::CLI.start
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Deals::Engine.routes.draw do
2
+ match '/places' => 'places#index', :defaults => { :format => 'json' }
3
+ match '/categories' => 'categories#index', :defaults => { :format => 'json' }
4
+ match '/for/:category' => 'deals#index', :defaults => { :format => 'json' }
5
+ match '/:place' => 'deals#index', :defaults => { :format => 'json' }
6
+ match '/:place/:category' => 'deals#index', :defaults => { :format => 'json' }
7
+ end
@@ -0,0 +1,20 @@
1
+ class CreateDeals < ActiveRecord::Migration
2
+ def change
3
+ create_table :deals do |t|
4
+ t.string :first_line
5
+ t.string :second_line
6
+ t.text :description
7
+ t.string :email
8
+ t.string :phone
9
+ t.string :website
10
+ t.float :commission
11
+ t.datetime :deleted_at
12
+ t.references :place
13
+ t.references :category
14
+
15
+ t.timestamps
16
+ end
17
+ add_index :deals, :place_id
18
+ add_index :deals, :category_id
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ class CreateCategories < ActiveRecord::Migration
2
+ def change
3
+ create_table :categories do |t|
4
+ t.string :name
5
+ t.string :slug
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePlaces < ActiveRecord::Migration
2
+ def change
3
+ create_table :places do |t|
4
+ t.string :name
5
+ t.string :slug
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ class AddPhotoToDeals < ActiveRecord::Migration
2
+ def change
3
+ add_column :deals, :photo, :string
4
+ end
5
+ end
data/lib/deals.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "deals/engine"
2
+
3
+ module Deals
4
+ end
data/lib/deals/cli.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'thor'
2
+
3
+ module Deals
4
+ class CLI < Thor
5
+ include Thor::Actions
6
+
7
+ desc "install", "install and configure deals"
8
+ def install
9
+ if already_installed?
10
+ update
11
+ else
12
+ inject_devise
13
+ inject_rails_admin
14
+ inject_carrierwave
15
+ run('bundle install')
16
+ run('rake deals:install:migrations')
17
+ run('rake db:migrate')
18
+ run('rails generate devise:install')
19
+ run('rails generate devise User')
20
+ run('rake db:migrate')
21
+ run('rails g rails_admin:install')
22
+ run('rake db:migrate')
23
+ mount_deals_route
24
+ welcome
25
+ end
26
+ end
27
+
28
+ desc "update", "update deals"
29
+ def update
30
+ say "Deals install detected"
31
+ say "Updating current Deals install"
32
+ run('rake deals:install:migrations')
33
+ say_upgraded
34
+ end
35
+
36
+ desc "inject_devise", "add devise"
37
+ def inject_devise
38
+ puts 'add reference to devise in GEMFILE'
39
+ insert_into_file "Gemfile", "gem 'devise'\n", :after => "source 'https://rubygems.org'\n"
40
+ end
41
+
42
+
43
+ desc "inject_rails_admin", "add rails_admin"
44
+ def inject_rails_admin
45
+ puts 'add reference to rails_admin in GEMFILE'
46
+ insert_into_file "Gemfile", "gem 'rails_admin'\n", :after => "gem 'devise'\n"
47
+ end
48
+
49
+ desc "inject_carrierwave", "add carrierwave"
50
+ def inject_carrierwave
51
+ puts 'add reference to carrierwave in GEMFILE'
52
+ insert_into_file "Gemfile", "gem 'carrierwave'\n", :after => "gem 'rails_admin'\n"
53
+ create_file "config/initializers/carrierwave.rb", "require 'carrierwave/orm/activerecord'"
54
+ end
55
+
56
+ desc "mount_deals_route", "mount deals route"
57
+ def mount_deals_route
58
+ insert_into_file "config/routes.rb", "\n mount Deals::Engine => '/deals', :as => 'deals'\n", :after => "Application.routes.draw do\n"
59
+ end
60
+
61
+ desc "create user class", "Create a user class"
62
+ def create_user_class
63
+ run('rails generate model User')
64
+ end
65
+
66
+ desc "welcome", "invite to deals"
67
+ def welcome
68
+ say ""
69
+ say ""
70
+ say ""
71
+ say "******************************************************************"
72
+ say "******************************************************************"
73
+ say "Deals Successfully Installed!"
74
+ say "******************************************************************"
75
+ end
76
+
77
+ desc "say_upgraded", "deals upgraded"
78
+ def say_upgraded
79
+ say ""
80
+ say ""
81
+ say ""
82
+ say "******************************************************************"
83
+ say "******************************************************************"
84
+ say "Deals Successfully Upgraded!"
85
+ say "******************************************************************"
86
+ end
87
+
88
+ private
89
+
90
+ def already_installed?
91
+ open('config/routes.rb') { |f| f.grep(/Deals\:\:Engine/) }.any?
92
+ end
93
+
94
+
95
+ end
96
+ end