entangled 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -5
  3. data/Rakefile +17 -1
  4. data/entangled-0.0.6.gem +0 -0
  5. data/entangled.gemspec +4 -2
  6. data/lib/entangled.rb +58 -13
  7. data/lib/entangled/controller.rb +1 -0
  8. data/lib/entangled/model.rb +0 -2
  9. data/lib/entangled/version.rb +1 -1
  10. data/spec/dummy/README.rdoc +28 -0
  11. data/spec/dummy/Rakefile +6 -0
  12. data/spec/dummy/app/assets/images/.keep +0 -0
  13. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  14. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  15. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  16. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  17. data/spec/dummy/app/controllers/foo_controller.rb +4 -0
  18. data/spec/dummy/app/controllers/messages_controller.rb +4 -0
  19. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  20. data/spec/dummy/app/mailers/.keep +0 -0
  21. data/spec/dummy/app/models/.keep +0 -0
  22. data/spec/dummy/app/models/concerns/.keep +0 -0
  23. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  24. data/spec/dummy/bin/bundle +3 -0
  25. data/spec/dummy/bin/rails +4 -0
  26. data/spec/dummy/bin/rake +4 -0
  27. data/spec/dummy/bin/setup +29 -0
  28. data/spec/dummy/config.ru +4 -0
  29. data/spec/dummy/config/application.rb +26 -0
  30. data/spec/dummy/config/boot.rb +5 -0
  31. data/spec/dummy/config/database.yml +25 -0
  32. data/spec/dummy/config/environment.rb +5 -0
  33. data/spec/dummy/config/environments/development.rb +41 -0
  34. data/spec/dummy/config/environments/production.rb +79 -0
  35. data/spec/dummy/config/environments/test.rb +42 -0
  36. data/spec/dummy/config/initializers/assets.rb +11 -0
  37. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  38. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/spec/dummy/config/initializers/inflections.rb +16 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  42. data/spec/dummy/config/initializers/session_store.rb +3 -0
  43. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/spec/dummy/config/locales/en.yml +23 -0
  45. data/spec/dummy/config/routes.rb +11 -0
  46. data/spec/dummy/config/secrets.yml +22 -0
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/lib/assets/.keep +0 -0
  49. data/spec/dummy/log/.keep +0 -0
  50. data/spec/dummy/log/test.log +1038 -0
  51. data/spec/dummy/public/404.html +67 -0
  52. data/spec/dummy/public/422.html +67 -0
  53. data/spec/dummy/public/500.html +66 -0
  54. data/spec/dummy/public/favicon.ico +0 -0
  55. data/spec/routing/foo_routing_spec.rb +68 -0
  56. data/spec/routing/messages_routing_spec.rb +53 -0
  57. data/spec/spec_helper.rb +29 -2
  58. metadata +119 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5061458f7fad47437868c5e5c445d05c1e25060a
4
- data.tar.gz: 4a5ea5580591c4d01aba2686a1392d1257bd818f
3
+ metadata.gz: b346ba92b1c5fd0eb643177f578387de48a74150
4
+ data.tar.gz: f7beb07dcc9533e1aa1d991b677cfbf3dc864517
5
5
  SHA512:
6
- metadata.gz: eb26c2be5a2e95619dfae839f8929672fdc6e403cef4025212a1a992eac53fab21d81074b04f7ec1fc40a7caee96e83f244d70675da242ee3835d602a20e899a
7
- data.tar.gz: 83a79396d556515b2a4124e15160fe513f2d12f87ef0ac0236f383a16633cdb01744b228817b4fa1d42a59b72db72d3ef3398f2eeddf1d22d81715ad03bac3c5
6
+ metadata.gz: 666d0fdf3236a271286c3cba63734af5c5d0d2edc4408fc9206b3cf1bfa0964a749e3ae1e0bbb0c9136d0a5233732556de4fe482c7566d56a469a7bf469a6e85
7
+ data.tar.gz: 6f2504708a1feb5b2efcac74d6f5c12e8300dcf23ea522a88c4c1b64fd6a8708d8689abf9e6d339c282e42feae8cf87c3e499260d85438d89aaa48db88ad01ba
data/README.md CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
  $ gem install entangled
29
29
 
30
30
  ## Usage
31
- Entangled is needed in three parts of your app. Given the example of a `MessagesController` and a `Message` model for a chat app, you will need:
31
+ Entangled is needed in three parts of your app: Routes, models, and controllers. Given the example of a `MessagesController` and a `Message` model for a chat app, you will need:
32
32
 
33
33
  ### Routes
34
34
  Add the following to your routes file:
@@ -37,8 +37,6 @@ Add the following to your routes file:
37
37
  sockets_for :messages
38
38
  ```
39
39
 
40
- Replace `messages` with your resource name.
41
-
42
40
  Under the hood, this creates the following routes:
43
41
 
44
42
  ```ruby
@@ -49,9 +47,15 @@ get '/messages/:id/destroy', to: 'messages#destroy', as: :destroy_message
49
47
  get '/messages/:id/update', to: 'messages#update', as: :update_message
50
48
  ```
51
49
 
50
+ The options `:only` and `:except` are available just like when using `resources`, so you can say something like:
51
+
52
+ ```ruby
53
+ sockets_for :messages, only: :index # or use an array
54
+ ```
55
+
52
56
  Note that Websockets don't speak HTTP, so only GET requests are available. That's why these routes deviate slightly from restful routes. Also note that there are no `edit` and `new` actions, since an Entangled controller is only concerned with rendering data, not views.
53
57
 
54
- ### Model
58
+ ### Models
55
59
  Add the following to the top inside your model (e.g., a `Message` model):
56
60
 
57
61
  ```ruby
@@ -63,7 +67,7 @@ end
63
67
 
64
68
  This will create the callbacks needed to push changes to data to all clients who are subscribed. This is essentially where the data binding is set up.
65
69
 
66
- ### Controller
70
+ ### Controllers
67
71
  Your controllers will be a little more lightweight than in a standard restful Rails app. A restful-style controller is expected and should look like this:
68
72
 
69
73
  ```ruby
data/Rakefile CHANGED
@@ -1,2 +1,18 @@
1
- require "bundler/gem_tasks"
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
2
7
 
8
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
9
+ load 'rails/tasks/engine.rake'
10
+ Bundler::GemHelper.install_tasks
11
+ Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
12
+
13
+ require 'rspec/core'
14
+ require 'rspec/core/rake_task'
15
+
16
+ desc "Run all specs in spec directory (excluding plugin specs)"
17
+ RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
18
+ task :default => :spec
Binary file
@@ -15,12 +15,14 @@ Gem::Specification.new do |spec|
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.test_files = Dir["spec/**/*"]
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency 'rspec', '~> 3.2'
23
+ spec.add_development_dependency 'rspec-rails', '~> 3.2'
24
+ spec.add_development_dependency 'sqlite3'
25
+ spec.add_development_dependency 'byebug'
24
26
  spec.add_dependency 'tubesock', '~> 0.2'
25
27
  spec.add_dependency 'rails', '~> 4.2'
26
28
  end
@@ -6,21 +6,66 @@ require 'active_support/concern'
6
6
 
7
7
  module ActionDispatch::Routing
8
8
  class Mapper
9
- def sockets_for(resource, &block)
10
- resources = resource.to_s.underscore.pluralize.to_sym
11
- resource = resource.to_s.underscore.singularize.to_sym
12
-
13
- get :"/#{resources}", to: "#{resources}#index", as: resources
14
- get :"/#{resources}/create", to: "#{resources}#create", as: :"create_#{resource}"
15
- get :"/#{resources}/:id", to: "#{resources}#show", as: resource
16
- get :"/#{resources}/:id/destroy", to: "#{resources}#destroy", as: :"destroy_#{resource}"
17
- get :"/#{resources}/:id/update", to: "#{resources}#update", as: :"update_#{resource}"
18
-
19
- if block_given?
20
- namespace resources do
21
- yield
9
+ private
10
+ def sockets_for(resource, options = {})
11
+ @resources = resource.to_s.underscore.pluralize.to_sym
12
+ @resource = resource.to_s.underscore.singularize.to_sym
13
+
14
+ if options.any?
15
+ if options[:only]
16
+ if options[:only].is_a? Symbol
17
+ send :"draw_#{options[:only]}"
18
+ elsif options[:only].is_a? Array
19
+ options[:only].each do |option|
20
+ send :"draw_#{option}"
21
+ end
22
+ end
23
+ elsif options[:except]
24
+ if options[:except].is_a? Symbol
25
+ (default_options - [options[:except]]).each do |option|
26
+ send :"draw_#{option}"
27
+ end
28
+ elsif options[:except].is_a? Array
29
+ (default_options - options[:except]).each do |option|
30
+ send :"draw_#{option}"
31
+ end
32
+ end
22
33
  end
34
+ else
35
+ draw_all
23
36
  end
24
37
  end
38
+
39
+ def default_options
40
+ [:index, :create, :show, :destroy, :update]
41
+ end
42
+
43
+ def draw_all
44
+ draw_index
45
+ draw_create
46
+ draw_show
47
+ draw_destroy
48
+ draw_update
49
+ end
50
+
51
+ def draw_index
52
+ get :"/#{@resources}", to: "#{@resources}#index", as: @resources
53
+ end
54
+
55
+ def draw_create
56
+ get :"/#{@resources}/create", to: "#{@resources}#create", as: :"create_#{@resource}"
57
+ end
58
+
59
+ def draw_show
60
+ get :"/#{@resources}/:id", to: "#{@resources}#show", as: @resource
61
+ end
62
+
63
+ def draw_destroy
64
+ get :"/#{@resources}/:id/destroy", to: "#{@resources}#destroy", as: :"destroy_#{@resource}"
65
+ end
66
+
67
+ def draw_update
68
+ get :"/#{@resources}/:id/update", to: "#{@resources}#update", as: :"update_#{@resource}"
69
+ end
25
70
  end
26
71
  end
@@ -1,4 +1,5 @@
1
1
  require 'tubesock'
2
+ require 'tubesock/hijack'
2
3
 
3
4
  module Entangled
4
5
  module Controller
@@ -3,7 +3,6 @@ module Entangled
3
3
  module ClassMethods
4
4
  # Create after_ callbacks for options
5
5
  def entangle(options = {})
6
-
7
6
  # If :only is specified, the options can either
8
7
  # be an array or a symbol
9
8
  if options[:only].present?
@@ -24,7 +23,6 @@ module Entangled
24
23
  # Instead of :only, :except can be specified; similarly,
25
24
  # the options can either be an array or a symbol
26
25
  elsif options[:except].present?
27
-
28
26
  # If it is a symbol, it has to be taken out of the default
29
27
  # options. A callback has to be defined for each of the
30
28
  # remaining options
@@ -1,3 +1,3 @@
1
1
  module Entangled
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,13 @@
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 any plugin's vendor/assets/javascripts directory 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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,4 @@
1
+ # This controller only serves to test the sockets_for
2
+ # inclusion and exclusion options
3
+ class FooController < ApplicationController
4
+ end
@@ -0,0 +1,4 @@
1
+ # This controller serves as fully restful example
2
+ # controller with all five actions
3
+ class MessagesController < ApplicationController
4
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "entangled"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+
22
+ # Do not swallow errors in after_commit/after_rollback callbacks.
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+ end
25
+ end
26
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: 5000
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: db/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: db/test.sqlite3
22
+
23
+ production:
24
+ <<: *default
25
+ database: db/production.sqlite3
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,41 @@
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
33
+
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
41
+ end