ext_direct 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -21,6 +21,7 @@ Install as a gem:
21
21
  Then in "config/environment.rb" require middleware:
22
22
 
23
23
  config.middleware.use "ExtDirect::Router", "/direct"
24
+ config.middleware.use "ExtDirect::API", "/direct_api", "/direct"
24
25
 
25
26
  Great job! Now you are ready to use this library. Remember, this release is tested and runs with Rails 2.3.
26
27
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/ext_direct.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ext_direct}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcin Lewandowski"]
12
- s.date = %q{2010-06-03}
12
+ s.date = %q{2010-06-13}
13
13
  s.description = %q{The Ext Direct plugin is a simple implementation of Ext Direct router to call server-side methods on the client-side.}
14
14
  s.email = %q{marcin.martio.lewandowski@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -25,11 +25,13 @@ Gem::Specification.new do |s|
25
25
  "ext_direct.gemspec",
26
26
  "install.rb",
27
27
  "lib/ext_direct.rb",
28
+ "lib/ext_direct/api.rb",
28
29
  "lib/ext_direct/dispatcher.rb",
29
30
  "lib/ext_direct/request.rb",
30
31
  "lib/ext_direct/response.rb",
31
32
  "lib/ext_direct/router.rb",
32
33
  "lib/ext_direct/service/base.rb",
34
+ "lib/ext_direct/service/configuration.rb",
33
35
  "lib/ext_direct/service/provider.rb",
34
36
  "rails/init.rb",
35
37
  "test/ext_direct_test.rb",
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ module ExtDirect
4
+ class API
5
+ def initialize(app, api_path = "/api", route_path = "/direct", constant_name = "Ext.app.REMOTING_API")
6
+ @app, @api_path, @route_path, @constant_name = app, api_path, route_path, constant_name
7
+ end
8
+
9
+ def call(env)
10
+ if env["PATH_INFO"].match("^#{@api_path}$")
11
+ response = ExtDirect::Response.new("", 200, {"Content-Type" => "text/javascript"})
12
+ response.write("#{@constant_name} = #{ExtDirect::Service::Configuration.generate(@route_path).to_json}")
13
+ response.finish
14
+ else
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  module ExtDirect
4
4
  class Router
5
- def initialize(app, route_path)
5
+ def initialize(app, route_path = "/direct")
6
6
  @app, @route_path = app, route_path
7
7
  end
8
8
 
@@ -0,0 +1,39 @@
1
+ module ExtDirect
2
+ module Service
3
+ class Configuration
4
+ class << self
5
+ def generate(route_path)
6
+ config = {}
7
+ config['url'] = route_path
8
+ config['type'] = "remoting"
9
+ config['actions'] = {}
10
+
11
+ services = ExtDirect::Service::Provider.fetch
12
+ services.each do |action,methods|
13
+ action = normalize_action(action)
14
+ config['actions'][action] = []
15
+ methods.each do |method,params|
16
+ config['actions'][action] << {:name => normalize_method(method), :len => 1} if params[:type] == :remoting
17
+ end
18
+ end
19
+
20
+ config
21
+ end
22
+
23
+ private
24
+
25
+ def normalize_action(name)
26
+ camelize(name)
27
+ end
28
+
29
+ def normalize_method(name)
30
+ (name.to_s)[0].chr.downcase + (camelize(name.to_s))[1..-1]
31
+ end
32
+
33
+ def camelize(name)
34
+ name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -14,6 +14,10 @@ module ExtDirect
14
14
  @@store[action][method][:proc] = proc
15
15
  end
16
16
 
17
+ def fetch
18
+ @@store
19
+ end
20
+
17
21
  def exist?(action, method)
18
22
  (@@store[action.to_sym] and @@store[action.to_sym][method.to_sym])
19
23
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Marcin Lewandowski
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-03 00:00:00 +02:00
17
+ date: 2010-06-13 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -36,11 +36,13 @@ files:
36
36
  - ext_direct.gemspec
37
37
  - install.rb
38
38
  - lib/ext_direct.rb
39
+ - lib/ext_direct/api.rb
39
40
  - lib/ext_direct/dispatcher.rb
40
41
  - lib/ext_direct/request.rb
41
42
  - lib/ext_direct/response.rb
42
43
  - lib/ext_direct/router.rb
43
44
  - lib/ext_direct/service/base.rb
45
+ - lib/ext_direct/service/configuration.rb
44
46
  - lib/ext_direct/service/provider.rb
45
47
  - rails/init.rb
46
48
  - test/ext_direct_test.rb