immanence 0.0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +20 -0
- data/Gemfile +3 -0
- data/README.md +1 -0
- data/Rakefile +6 -0
- data/immanence.gemspec +30 -0
- data/lib/core_ext/hash.rb +87 -0
- data/lib/core_ext/object.rb +5 -0
- data/lib/immanence/version.rb +3 -0
- data/lib/immanence.rb +88 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2Y1MzgxZDJkZDU0MTdlNmJjYzFiYWJkMDJlNjM2NDRmMmYxNmI2YQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NTAzMGE4NWVhMmQyOTgxNDgxNjUzYmNiMmRmYjllOGU4Y2E4MDY5Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzNmYzRlODI3NjMwZTI5NGYyMzNjY2M5YmYxZDUwMGNmMjg5MDIyZGE3YjUz
|
10
|
+
NDA5NzczNjJlMDI0MzNjMjdjMDc2ODZhYzZhNGNjN2Q4NDdjMDcxM2IzN2M1
|
11
|
+
NDhjNDg3MzNjM2M2MjM0Y2I0YTM5ZjU1Y2I1YmYwYjgzOTNjZTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmFlMzViZmI3OGFjYmNhM2U3YjNjYzcwYzg2MGZjODY4MWMyNWI4YmVkNDZm
|
14
|
+
MjhlMTg2MzdjZDhlOTk4Yzc0YjAyMzYyZjI3NjI2NTkyY2Y0NjZlMjg4NWJk
|
15
|
+
NjE0MTVlNDA3YTg0YzAzNWU3MzIxYmFjZmUzNGQ5OWMyZTBiMzk=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
> [...] when I stub my toe, it is because I do not have the proper set of architectural landing sites in place. That is, my architectural body has not assembled enough clues to connect itself properly to its surroundings. Sites of reversible destiny are designed to be as complex as our most innate mechanisms of our perception. It might take an hour to go from one room to another, and I might live there in a continual state of deja vu as I experience a repetition of slightly differing perceptions. Yet, I will be involved in a constant critique of my own experience. I will see. I will live. Perhaps for the first time. —Arakawa and Gins
|
data/Rakefile
ADDED
data/immanence.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
require "immanence/version"
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = "immanence"
|
11
|
+
spec.version = Immanence::VERSION
|
12
|
+
spec.authors = ["dzucconi"]
|
13
|
+
spec.email = ["mail@damonzucconi.com"]
|
14
|
+
spec.description = "A framework"
|
15
|
+
spec.summary = "A framework"
|
16
|
+
spec.homepage = "http://github.com/dzucconi/immanence"
|
17
|
+
spec.license = "CC0"
|
18
|
+
|
19
|
+
spec.files = `git ls-files`.split($/)
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec", "~> 2.14.0"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "rack", "~> 1.5.2"
|
29
|
+
spec.add_runtime_dependency "oj", "~> 2.1.4"
|
30
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
class Hash
|
2
|
+
def reverse_merge(other_hash)
|
3
|
+
other_hash.merge(self)
|
4
|
+
end
|
5
|
+
|
6
|
+
def reverse_merge!(other_hash)
|
7
|
+
merge!(other_hash) { |key, left, right| left }
|
8
|
+
end
|
9
|
+
|
10
|
+
def transform_keys
|
11
|
+
{}.tap do |result|
|
12
|
+
each_key do |key|
|
13
|
+
result[yield(key)] = self[key]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def transform_keys!
|
19
|
+
keys.each do |key|
|
20
|
+
self[yield(key)] = delete(key)
|
21
|
+
end
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def symbolize_keys
|
27
|
+
transform_keys { |key| key.to_sym rescue key }
|
28
|
+
end
|
29
|
+
|
30
|
+
def symbolize_keys!
|
31
|
+
transform_keys! { |key| key.to_sym rescue key }
|
32
|
+
end
|
33
|
+
|
34
|
+
def assert_valid_keys(*valid_keys)
|
35
|
+
valid_keys.flatten!
|
36
|
+
|
37
|
+
each_key do |k|
|
38
|
+
raise ArgumentError.new("Unknown key: #{k}") unless valid_keys.include?(k)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def deep_transform_keys(&block)
|
43
|
+
deep_transform_keys_in_object(self, &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
def deep_transform_keys!(&block)
|
47
|
+
deep_transform_keys_in_object!(self, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def deep_symbolize_keys
|
51
|
+
deep_transform_keys { |key| key.to_sym rescue key }
|
52
|
+
end
|
53
|
+
|
54
|
+
def deep_symbolize_keys!
|
55
|
+
deep_transform_keys! { |key| key.to_sym rescue key }
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def deep_transform_keys_in_object(object, &block)
|
61
|
+
case object
|
62
|
+
when Hash
|
63
|
+
object.each_with_object({}) do |(key, value), result|
|
64
|
+
result[yield(key)] = deep_transform_keys_in_object(value, &block)
|
65
|
+
end
|
66
|
+
when Array
|
67
|
+
object.map { |e| deep_transform_keys_in_object(e, &block) }
|
68
|
+
else
|
69
|
+
object
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def deep_transform_keys_in_object!(object, &block)
|
74
|
+
case object
|
75
|
+
when Hash
|
76
|
+
object.keys.each do |key|
|
77
|
+
value = object.delete(key)
|
78
|
+
object[yield(key)] = deep_transform_keys_in_object!(value, &block)
|
79
|
+
end
|
80
|
+
object
|
81
|
+
when Array
|
82
|
+
object.map! { |e| deep_transform_keys_in_object!(e, &block) }
|
83
|
+
else
|
84
|
+
object
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/lib/immanence.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require "rack"
|
2
|
+
require "oj"
|
3
|
+
|
4
|
+
require "core_ext/hash"
|
5
|
+
require "core_ext/object"
|
6
|
+
|
7
|
+
module Immanence
|
8
|
+
class Request < Struct.new(:verb, :path, :input); end
|
9
|
+
|
10
|
+
class Control
|
11
|
+
I =-> i { Oj.load(i) }
|
12
|
+
O =-> o { Oj.dump(o, mode: :compat) }
|
13
|
+
|
14
|
+
PROBLEM = "[...] from a problem to the accidents that condition and resolve it."
|
15
|
+
|
16
|
+
LEVENSHTEIN =-> a, b {
|
17
|
+
mx = [(0..a.size).to_a]
|
18
|
+
|
19
|
+
(1..b.size).each do |j|
|
20
|
+
mx << [j] + [0] * (a.size)
|
21
|
+
end
|
22
|
+
|
23
|
+
(1..b.size).each do |i|
|
24
|
+
(1..a.size).each do |j|
|
25
|
+
if a[j-1] == b[i-1]
|
26
|
+
mx[i][j] = mx[i-1][j-1]
|
27
|
+
else
|
28
|
+
mx[i][j] = [
|
29
|
+
mx[i-1][j],
|
30
|
+
mx[i][j-1],
|
31
|
+
mx[i-1][j-1]
|
32
|
+
].min + 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
mx[-1][-1]
|
38
|
+
}
|
39
|
+
|
40
|
+
class << self
|
41
|
+
def >>(body=:ok, options={}, headers={})
|
42
|
+
body = O[body]
|
43
|
+
|
44
|
+
options.reverse_merge!({ status: 200 })
|
45
|
+
headers.reverse_merge!({
|
46
|
+
"Content-Type" => "text/json",
|
47
|
+
"Content-Length" => ("#{body.size}" rescue "0")
|
48
|
+
})
|
49
|
+
|
50
|
+
[options[:status], headers, [body]]
|
51
|
+
end
|
52
|
+
|
53
|
+
def route(verb, path, &blk)
|
54
|
+
meta_def(conjugate(verb, path)) { instance_eval &blk }
|
55
|
+
end
|
56
|
+
|
57
|
+
def conjugate(verb, path)
|
58
|
+
"immanent_#{verb}_#{path}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def ascertain(method, path)
|
62
|
+
method.to_s.gsub(/immanent_\w*_/, "").
|
63
|
+
split("/")[1..-1].
|
64
|
+
zip(path.split("/")[1..-1]).
|
65
|
+
map { |x, y|
|
66
|
+
{ x[1..-1] => y } if x[0] == ":"
|
67
|
+
}.compact.
|
68
|
+
reduce({}, :merge).
|
69
|
+
deep_symbolize_keys
|
70
|
+
end
|
71
|
+
|
72
|
+
def receiver
|
73
|
+
methods.grep(/immanent_/).map { |method|
|
74
|
+
{ method: method, score: LEVENSHTEIN[method, conjugate(@request.verb, @request.path)] }
|
75
|
+
}.min_by { |x| x[:score] }[:method]
|
76
|
+
end
|
77
|
+
|
78
|
+
def call(e)
|
79
|
+
@request = Request.new e["REQUEST_METHOD"].downcase, e["PATH_INFO"], I[e["rack.input"].read]
|
80
|
+
@params = ascertain receiver, @request.path
|
81
|
+
|
82
|
+
send receiver
|
83
|
+
rescue
|
84
|
+
self >> { error: PROBLEM }
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: immanence
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dzucconi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.5.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: oj
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.1.4
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.1.4
|
83
|
+
description: A framework
|
84
|
+
email:
|
85
|
+
- mail@damonzucconi.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- .gitignore
|
91
|
+
- Gemfile
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- immanence.gemspec
|
95
|
+
- lib/core_ext/hash.rb
|
96
|
+
- lib/core_ext/object.rb
|
97
|
+
- lib/immanence.rb
|
98
|
+
- lib/immanence/version.rb
|
99
|
+
homepage: http://github.com/dzucconi/immanence
|
100
|
+
licenses:
|
101
|
+
- CC0
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.0.6
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: A framework
|
123
|
+
test_files: []
|
124
|
+
has_rdoc:
|