excursion 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/excursion/datastores/active_record.rb +47 -0
- data/lib/excursion/datastores/active_record_with_memcache.rb +40 -0
- data/lib/excursion/datastores/file.rb +3 -3
- data/lib/excursion/exceptions/active_record.rb +4 -0
- data/lib/excursion/helpers/url_helper.rb +18 -10
- data/lib/excursion/pool.rb +7 -0
- data/lib/excursion/railtie.rb +1 -1
- data/lib/excursion/route_pool.rb +5 -0
- data/lib/excursion/version.rb +1 -1
- data/lib/excursion.rb +1 -0
- data/lib/generators/excursion/active_record_generator.rb +19 -0
- data/lib/generators/excursion/templates/migration.rb +14 -0
- data/spec/dummy/config/environments/development.rb +1 -3
- data/spec/dummy/config/environments/test.rb +1 -3
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20130618222840_create_excursion_route_pool.rb +14 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +70166 -0
- data/spec/excursion/datastores/active_record_spec.rb +106 -0
- data/spec/excursion/datastores/active_record_with_memcache_spec.rb +158 -0
- data/spec/excursion/datastores/file_spec.rb +1 -0
- data/spec/excursion/datastores/memcache_spec.rb +1 -0
- data/spec/excursion/route_pool_spec.rb +4 -0
- data/spec/spec_helper.rb +4 -2
- metadata +22 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 970c66c03bce9f7cc650641b90518f7b81d0c716
|
4
|
+
data.tar.gz: d63f0475015ad67d34e5ef75a84d12f1f723cc81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4922ab494d86409741c2229dc85a5cfd5ffa5696bfdb44545c08f74c646608ab40e9ba35b012c3329fd8c7d7c178cabd5253819ab34c48d50c81217fa32f11dd
|
7
|
+
data.tar.gz: e219ee026b5d0d6615869a72efb30a18a911c5de42e6a214fa42c1a630f17e1926858b1566e953b6bc339754b05939d9208912cb1fc2654f33007f9fda8add16
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'excursion/datastores/datastore'
|
2
|
+
require 'excursion/exceptions/active_record'
|
3
|
+
|
4
|
+
module Excursion
|
5
|
+
module Datastores
|
6
|
+
class ActiveRecord < Datastore
|
7
|
+
|
8
|
+
def model_find(key)
|
9
|
+
return @model.find_by(key: key) if Excursion.rails4?
|
10
|
+
return @model.find_by_key(key) if Excursion.rails3?
|
11
|
+
end
|
12
|
+
|
13
|
+
def read(key)
|
14
|
+
model_find(key).value
|
15
|
+
rescue
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
alias_method :get, :read
|
19
|
+
|
20
|
+
def write(key, value)
|
21
|
+
written = model_find(key)
|
22
|
+
if written.nil?
|
23
|
+
written = @model.create key: key, value: value
|
24
|
+
else
|
25
|
+
written.update value: value
|
26
|
+
end
|
27
|
+
written.value
|
28
|
+
end
|
29
|
+
alias_method :set, :write
|
30
|
+
|
31
|
+
def delete(key)
|
32
|
+
deleted = model_find(key)
|
33
|
+
return nil if deleted.nil?
|
34
|
+
deleted.destroy
|
35
|
+
deleted.value
|
36
|
+
end
|
37
|
+
alias_method :unset, :delete
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def initialize
|
42
|
+
@model = Excursion::RoutePool
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'excursion/datastores/active_record'
|
2
|
+
require 'excursion/datastores/memcache'
|
3
|
+
|
4
|
+
module Excursion
|
5
|
+
module Datastores
|
6
|
+
class ActiveRecordWithMemcache < Datastore
|
7
|
+
|
8
|
+
def read(key)
|
9
|
+
value = @cache.read(key)
|
10
|
+
return value unless value.nil?
|
11
|
+
|
12
|
+
value = @model.read(key)
|
13
|
+
@cache.write(key, value) unless value.nil?
|
14
|
+
|
15
|
+
value
|
16
|
+
end
|
17
|
+
alias_method :get, :read
|
18
|
+
|
19
|
+
def write(key, value)
|
20
|
+
@model.write(key, value)
|
21
|
+
@cache.write(key, value)
|
22
|
+
end
|
23
|
+
alias_method :set, :write
|
24
|
+
|
25
|
+
def delete(key)
|
26
|
+
@model.delete(key)
|
27
|
+
@cache.delete(key)
|
28
|
+
end
|
29
|
+
alias_method :unset, :delete
|
30
|
+
|
31
|
+
protected
|
32
|
+
|
33
|
+
def initialize(server)
|
34
|
+
@model = Excursion::Datastores::ActiveRecord.new
|
35
|
+
@cache = Excursion::Datastores::Memcache.new(server)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -36,11 +36,11 @@ module Excursion
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def exists?
|
39
|
-
::File.exists(@path)
|
39
|
+
::File.exists?(@path)
|
40
40
|
end
|
41
41
|
|
42
42
|
def read_file
|
43
|
-
YAML.load_file(@path)
|
43
|
+
exists? ? YAML.load_file(@path) : {}
|
44
44
|
rescue
|
45
45
|
{}
|
46
46
|
end
|
@@ -48,7 +48,7 @@ module Excursion
|
|
48
48
|
def write_file(results)
|
49
49
|
FileUtils.mkpath(::File.dirname(@path))
|
50
50
|
::File.open(@path, 'w') { |f| f.write(results.to_yaml)}
|
51
|
-
rescue
|
51
|
+
rescue StandardError => e
|
52
52
|
raise DatastoreConfigurationError, "Could not write to the excursion route pool file: #{@path}"
|
53
53
|
end
|
54
54
|
end
|
@@ -9,9 +9,14 @@ module Excursion
|
|
9
9
|
|
10
10
|
def method_missing(meth, *args)
|
11
11
|
if meth.to_s.match(/\A(#{routes.collect { |name,route| name }.join("|")})_(url|path)\Z/)
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
if Excursion.rails4?
|
13
|
+
ActionDispatch::Routing::RouteSet::NamedRouteCollection::UrlHelper.create(routes.get($1.to_sym), @application.default_url_options).call(Rails.application.routes, args)
|
14
|
+
elsif Excursion.rails3?
|
15
|
+
# Playing with getting Rails3 working
|
16
|
+
#mapping = ActionDispatch::Routing::Mapper::Mapping.new(routes, {}, routes.get($1.to_sym).path.spec.to_s.dup, {:controller => 'dummy', :action => 'dummy'})
|
17
|
+
#puts mapping.send(:instance_variable_get, :@path)
|
18
|
+
ActionDispatch::Http::URL.url_for(@application.default_url_options.merge({path: replaced_path(routes.get($1.to_sym), args)}))
|
19
|
+
end
|
15
20
|
else
|
16
21
|
super
|
17
22
|
end
|
@@ -24,13 +29,16 @@ module Excursion
|
|
24
29
|
end
|
25
30
|
|
26
31
|
# Playing with getting Rails3 working
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
def replaced_path(route, args)
|
33
|
+
path = route.path.spec.to_s.dup # ActionDispatch::Routing::Mapper.normalize_path(route.path.spec.to_s.dup)
|
34
|
+
|
35
|
+
route.required_parts.zip(args) do |part, arg|
|
36
|
+
path.gsub!(/(\*|:)#{part}/, Journey::Router::Utils.escape_fragment(arg.to_param))
|
37
|
+
end
|
38
|
+
|
39
|
+
path.gsub!(/\(\.:format\)/, '') # This is really gross, and :format should actually be supported
|
40
|
+
path
|
41
|
+
end
|
34
42
|
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/excursion/pool.rb
CHANGED
@@ -42,6 +42,13 @@ module Excursion
|
|
42
42
|
when :memcache
|
43
43
|
raise MemcacheConfigurationError, "You must configure the :memcache datastore with a memcache_server" if Excursion.configuration.memcache_server.nil?
|
44
44
|
@@datastore ||= Excursion::Datastores::Memcache.new(Excursion.configuration.memcache_server)
|
45
|
+
when :active_record
|
46
|
+
raise TableDoesNotExist, "To use the :active_record datastore you must first run `rails generate excursion:active_record` followed by `rake db:migrate` to create the storage table" unless Excursion::RoutePool.table_exists?
|
47
|
+
@@datastore ||= Excursion::Datastores::ActiveRecord.new
|
48
|
+
when :active_record_with_memcache
|
49
|
+
raise MemcacheConfigurationError, "You must configure the :active_record_with_memcache datastore with a memcache_server" if Excursion.configuration.memcache_server.nil?
|
50
|
+
raise TableDoesNotExist, "To use the :active_record_with_memcache datastore you must first run `rails generate excursion:active_record` followed by `rake db:migrate` to create the storage table" unless Excursion::RoutePool.table_exists?
|
51
|
+
@@datastore ||= Excursion::Datastores::ActiveRecord.new(Excursion.configuration.memcache_server)
|
45
52
|
end
|
46
53
|
end
|
47
54
|
end
|
data/lib/excursion/railtie.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Excursion
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
config.after_initialize do |app|
|
4
|
-
|
4
|
+
if Excursion.configuration.register_app == true && !Excursion.configuration.datastore.nil? && !defined?(Rails::Generators::Base) # HACK is there a better way to attempt to check if we're running a generator?
|
5
5
|
app.reload_routes!
|
6
6
|
Excursion::Pool.register_application(app)
|
7
7
|
end
|
data/lib/excursion/version.rb
CHANGED
data/lib/excursion.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
require 'rails/generators/active_record'
|
4
|
+
|
5
|
+
module Excursion
|
6
|
+
class ActiveRecordGenerator < ::Rails::Generators::Base
|
7
|
+
include ::Rails::Generators::Migration
|
8
|
+
|
9
|
+
self.source_paths << File.join(File.dirname(__FILE__), 'templates')
|
10
|
+
|
11
|
+
def create_migration_file
|
12
|
+
migration_template 'migration.rb', 'db/migrate/create_excursion_route_pool.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.next_migration_number(dirname)
|
16
|
+
::ActiveRecord::Generators::Base.next_migration_number dirname
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateExcursionRoutePool < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :excursion_route_pool, :force => true do |table|
|
4
|
+
table.string :key, :null => false
|
5
|
+
table.text :value, :null => false
|
6
|
+
end
|
7
|
+
|
8
|
+
add_index :excursion_route_pool, :key, :name => 'excursion_route_pool_key', :unique => true
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :excursion_route_pool
|
13
|
+
end
|
14
|
+
end
|
@@ -5,9 +5,7 @@ Dummy::Application.configure do
|
|
5
5
|
# every request. This slows down response time but is perfect for development
|
6
6
|
# since you don't have to restart the web server when you make code changes.
|
7
7
|
config.cache_classes = false
|
8
|
-
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
8
|
+
config.eager_load = false
|
11
9
|
|
12
10
|
# Show full error reports and disable caching
|
13
11
|
config.consider_all_requests_local = true
|
@@ -6,14 +6,12 @@ Dummy::Application.configure do
|
|
6
6
|
# your test database is "scratch space" for the test suite and is wiped
|
7
7
|
# and recreated between test runs. Don't rely on the data there!
|
8
8
|
config.cache_classes = true
|
9
|
+
config.eager_load = false
|
9
10
|
|
10
11
|
# Configure static asset server for tests with Cache-Control for performance
|
11
12
|
config.serve_static_assets = true
|
12
13
|
config.static_cache_control = "public, max-age=3600"
|
13
14
|
|
14
|
-
# Log error messages when you accidentally call methods on nil
|
15
|
-
config.whiny_nils = true
|
16
|
-
|
17
15
|
# Show full error reports and disable caching
|
18
16
|
config.consider_all_requests_local = true
|
19
17
|
config.action_controller.perform_caching = false
|
Binary file
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateExcursionRoutePool < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :excursion_route_pool, :force => true do |table|
|
4
|
+
table.string :key, :null => false
|
5
|
+
table.text :value, :null => false
|
6
|
+
end
|
7
|
+
|
8
|
+
add_index :excursion_route_pool, :key, :name => 'excursion_route_pool_key', :unique => true
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
drop_table :excursion_route_pool
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20130618222840) do
|
15
|
+
|
16
|
+
create_table "excursion_route_pool", force: true do |t|
|
17
|
+
t.string "key", null: false
|
18
|
+
t.text "value", null: false
|
19
|
+
end
|
20
|
+
|
21
|
+
add_index "excursion_route_pool", ["key"], name: "excursion_route_pool_key", unique: true
|
22
|
+
|
23
|
+
end
|
File without changes
|