chromembed_rails 0.1.2 → 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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{chromembed_rails}
8
- s.version = "0.1.2"
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 = [%q{Victor Costan}]
12
- s.date = %q{2011-07-01}
12
+ s.date = %q{2011-07-06}
13
13
  s.description = %q{Ruby on Rails engine for Web applications that are strongly coupled with Chrome extensions}
14
14
  s.email = %q{costan@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -55,7 +55,7 @@ Gem::Specification.new do |s|
55
55
  s.homepage = %q{http://github.com/pwnall/chromembed_rails}
56
56
  s.licenses = [%q{MIT}]
57
57
  s.require_paths = [%q{lib}]
58
- s.rubygems_version = %q{1.8.4}
58
+ s.rubygems_version = %q{1.8.5}
59
59
  s.summary = %q{Serves a Chrome extension embedded in a Rails application}
60
60
 
61
61
  if s.respond_to? :specification_version then
@@ -4,29 +4,11 @@ require 'crxmake'
4
4
  # :nodoc: namespace
5
5
  module ChromembedRails
6
6
 
7
- # :nodoc: namespace
8
- module Session
9
-
10
- # Mixed into ActiveController::Base
11
- module ControllerMixin
12
- def self.included(base)
13
- base.send :extend, ControllerClassMethods
14
- end
15
- end
16
-
17
- # Methods here become ActiveController::Base class methods.
18
- module ControllerClassMethods
19
- # Turns the current controller into the Chrome extension serving controller.
20
- #
21
- # Right now, this should be called from ChromeExtensionController. The
22
- # controller name is hardwired in other parts of the implementation.
23
- def chrome_extension_controller
24
- include ControllerInstanceMethods
25
- end
26
- end
27
-
28
- # Included in controllers that call config_vars_controller.
29
- module ControllerInstanceMethods
7
+ # Included in the Chrome extension serving controller.
8
+ #
9
+ # Some parts of the codebase assume that the controller's name is
10
+ # ChromeExtension.
11
+ module Controller
30
12
  # GET /chrome_extension.crx
31
13
  def show
32
14
  extension_data =
@@ -48,16 +30,12 @@ module ControllerInstanceMethods
48
30
  <?xml version='1.0' encoding='UTF-8'?>
49
31
  <gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
50
32
  <app appid='#{extension_data.appid}'>
51
- <updatecheck codebase='#{chrome_extension_url}' version='#{extension_data.version}' />
33
+ <updatecheck codebase='#{url_for(:action => :show)}' version='#{extension_data.version}' />
52
34
  </app>
53
35
  </gupdate>
54
36
  END_XML
55
37
  end
56
38
  private :update_xml
57
- end # module ChromembedRails::Session::ControllerInstanceMethods
58
-
59
- ActionController::Base.send :include, ControllerMixin
60
-
61
- end # namespace ChromembedRails::Session
39
+ end # module ChromembedRails::Controller
62
40
 
63
41
  end # namespace ChromembedRails
@@ -1,6 +1,6 @@
1
1
  # Caches information about serving the Chrome extension.
2
2
  class ChromeExtensionCache < ActiveRecord::Base
3
- chrome_extension_cache_model
3
+ include ChromembedRails::Model
4
4
 
5
5
  # Add your extensions to the ChromeExtensionCache model here.
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # Serves the embedded Chrome extension.
2
2
  class ChromeExtensionController < ApplicationController
3
- chrome_extension_controller
3
+ include ChromembedRails::Controller
4
4
 
5
5
  # Add your extension to the controller here.
6
6
  end
@@ -1,26 +1,15 @@
1
1
  require 'English'
2
2
 
3
- require 'active_record'
3
+ require 'active_support'
4
4
 
5
5
  # :nodoc: namespace
6
6
  module ChromembedRails
7
7
 
8
- # :nodoc: namespace
8
+ # Included by the model caching data for serving an embedded Chrome extension.
9
9
  module Model
10
+ extend ActiveSupport::Concern
10
11
 
11
-
12
- # Mixed into ActiveRecord::Base
13
- module ModelMixin
14
- def self.included(base)
15
- base.send :extend, ModelClassMethods
16
- end
17
- end
18
-
19
-
20
- # Methods here become ActiveRecord::Base class methods.
21
- module ModelClassMethods
22
- # Extends the model to cache data for serving an embedded Chrome extension.
23
- def chrome_extension_cache_model
12
+ included do
24
13
  # The extension's appid.
25
14
  validates :appid, :uniqueness => true, :length => 1..128, :presence => true
26
15
 
@@ -30,66 +19,59 @@ module ModelClassMethods
30
19
  # The CRX file contents.
31
20
  validates :crx_bits,
32
21
  :length => { :in => 0..(64.megabytes), :allow_nil => false }
33
-
34
- extend ModelMetaclassMethods
35
- include ModelInstanceMethods
36
22
  end
37
- end # module ChromembedRails::Model::ModelClassMethods
38
-
39
-
40
- # Included in the metaclass of models that call chrome_extension_cache_model.
41
- module ModelMetaclassMethods
42
- # ChromeExtensionCache entry for the latest extension bits.
43
- def extension_data(chrome_extension_update_url)
44
- self.new.update_with_current_bits(
45
- 'update_url' => chrome_extension_update_url)
46
- end
47
- end # module ChromembedRails::Model::ModelMetaclassMethods
48
-
49
-
50
- # Included in models that call chrome_extension_cache_model.
51
- module ModelInstanceMethods
52
- # Updates this cache entry to reflect the current extension code.
53
- #
54
- # Args:
55
- # manifest_changes:: hash to be merged into the extension's manifest JSON;
56
- # 'update_url' and 'version' might be good keys to change
57
- def update_with_current_bits(manifest_changes)
58
- extension_path = ChromembedRails.extension_path
59
- manifest_path = File.join extension_path, 'manifest.json'
60
- manifest_json = ActiveSupport::JSON.decode File.read(manifest_path)
61
- manifest_json.merge! manifest_changes
62
- self.version = manifest_json['version']
63
-
64
- key_path = ChromembedRails.key_path
65
- key = OpenSSL::PKey::RSA.new File.read(key_path)
66
- # Source: http://supercollider.dk/2010/01/calculating-chrome-extension-id-from-your-private-key-233
67
- alg = ["30819F300D06092A864886F70D010101050003818D00"].pack('H*')
68
- hash = Digest::SHA256.hexdigest(alg + key.public_key.to_der)[0...32]
69
- self.appid = hash.unpack('C*').map{ |c| c < 97 ? c + 49 : c + 10 }.
70
- pack('C*')
71
-
72
- tmp_path = Rails.root.join 'tmp', "chrome_ext_#{Time.now.to_f}_#{$PID}"
73
- ext_path = File.join tmp_path, 'chrome_extension'
74
- FileUtils.mkdir_p ext_path
75
- FileUtils.cp_r File.join(extension_path, '.'), ext_path
76
- man_path = File.join ext_path, 'manifest.json'
77
- File.open(man_path, 'wb') do |f|
78
- f.write ActiveSupport::JSON.encode manifest_json
23
+
24
+ # Class methods for models that include ChromembedRails::Model.
25
+ module ClassMethods
26
+ # ChromeExtensionCache entry for the latest extension bits.
27
+ def extension_data(chrome_extension_update_url)
28
+ self.new.update_with_current_bits(
29
+ 'update_url' => chrome_extension_update_url)
79
30
  end
80
-
81
- crx_path = File.join tmp_path, 'chrome_extension.crx'
82
- CrxMake.make :ex_dir => ext_path, :pkey => key_path,
83
- :crx_output => crx_path, :verbose => false
84
- self.crx_bits = File.read crx_path
85
- FileUtils.rm_r tmp_path
86
-
87
- self
88
- end
89
- end # module ChromembedRails::Model::ModelInstanceMethods
90
-
91
- ActiveRecord::Base.send :include, ModelMixin
31
+ end # module ChromembedRails::Model::ClassMethods
32
+
33
+
34
+ # Included in models that include ChromembedRails::Model.
35
+ module InstanceMethods
36
+ # Updates this cache entry to reflect the current extension code.
37
+ #
38
+ # Args:
39
+ # manifest_changes:: hash to be merged into the extension's manifest JSON;
40
+ # 'update_url' and 'version' might be good keys to change
41
+ def update_with_current_bits(manifest_changes)
42
+ extension_path = ChromembedRails.extension_path
43
+ manifest_path = File.join extension_path, 'manifest.json'
44
+ manifest_json = ActiveSupport::JSON.decode File.read(manifest_path)
45
+ manifest_json.merge! manifest_changes
46
+ self.version = manifest_json['version']
47
+
48
+ key_path = ChromembedRails.key_path
49
+ key = OpenSSL::PKey::RSA.new File.read(key_path)
50
+ # Source: http://supercollider.dk/2010/01/calculating-chrome-extension-id-from-your-private-key-233
51
+ alg = ["30819F300D06092A864886F70D010101050003818D00"].pack('H*')
52
+ hash = Digest::SHA256.hexdigest(alg + key.public_key.to_der)[0...32]
53
+ self.appid = hash.unpack('C*').map{ |c| c < 97 ? c + 49 : c + 10 }.
54
+ pack('C*')
55
+
56
+ tmp_path = Rails.root.join 'tmp', "chrome_ext_#{Time.now.to_f}_#{$PID}"
57
+ ext_path = File.join tmp_path, 'chrome_extension'
58
+ FileUtils.mkdir_p ext_path
59
+ FileUtils.cp_r File.join(extension_path, '.'), ext_path
60
+ man_path = File.join ext_path, 'manifest.json'
61
+ File.open(man_path, 'wb') do |f|
62
+ f.write ActiveSupport::JSON.encode manifest_json
63
+ end
64
+
65
+ crx_path = File.join tmp_path, 'chrome_extension.crx'
66
+ CrxMake.make :ex_dir => ext_path, :pkey => key_path,
67
+ :crx_output => crx_path, :verbose => false
68
+ self.crx_bits = File.read crx_path
69
+ FileUtils.rm_r tmp_path
70
+
71
+ self
72
+ end
73
+ end # module ChromembedRails::Model::InstanceMethods
92
74
 
93
- end # namespace ChromembedRails::Model
75
+ end # module ChromembedRails::Model
94
76
 
95
77
  end # namespace ChromembedRails
@@ -1,13 +1,8 @@
1
1
  require 'action_pack'
2
2
 
3
- # :nodoc: namespace
4
- module ChromembedRails
5
-
6
- # :nodoc: namespace
7
- module Routes
8
-
9
- # :nodoc: mixed into ActionPack's route mapper.
10
- module MapperMixin
3
+ # :nodoc: adding the chrome_extension method to the route mapper.
4
+ class ActionDispatch::Routing::Mapper
5
+ # Installs the routes for serving an extension
11
6
  def chrome_extension
12
7
  get 'chrome_extension.crx' => 'chrome_extension#show',
13
8
  :as => :chrome_extension
@@ -15,9 +10,3 @@ module MapperMixin
15
10
  :as => :chrome_extension_update
16
11
  end
17
12
  end
18
-
19
- ActionDispatch::Routing::Mapper.send :include, MapperMixin
20
-
21
- end # namespace ChromembedRails::Routes
22
-
23
- end # namespace ChromembedRails
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chromembed_rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Victor Costan
@@ -15,11 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-01 00:00:00 Z
18
+ date: 2011-07-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- type: :runtime
22
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
22
  none: false
24
23
  requirements:
25
24
  - - ">="
@@ -30,12 +29,12 @@ dependencies:
30
29
  - 0
31
30
  - 3
32
31
  version: 2.0.3
32
+ type: :runtime
33
+ requirement: *id001
33
34
  prerelease: false
34
- version_requirements: *id001
35
35
  name: crxmake
36
36
  - !ruby/object:Gem::Dependency
37
- type: :runtime
38
- requirement: &id002 !ruby/object:Gem::Requirement
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
40
39
  requirements:
41
40
  - - ">="
@@ -48,12 +47,12 @@ dependencies:
48
47
  - rc
49
48
  - 4
50
49
  version: 3.1.0.rc4
50
+ type: :runtime
51
+ requirement: *id002
51
52
  prerelease: false
52
- version_requirements: *id002
53
53
  name: rails
54
54
  - !ruby/object:Gem::Dependency
55
- type: :development
56
- requirement: &id003 !ruby/object:Gem::Requirement
55
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
57
  requirements:
59
58
  - - ~>
@@ -64,12 +63,12 @@ dependencies:
64
63
  - 0
65
64
  - 0
66
65
  version: 1.0.0
66
+ type: :development
67
+ requirement: *id003
67
68
  prerelease: false
68
- version_requirements: *id003
69
69
  name: bundler
70
70
  - !ruby/object:Gem::Dependency
71
- type: :development
72
- requirement: &id004 !ruby/object:Gem::Requirement
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ~>
@@ -80,12 +79,12 @@ dependencies:
80
79
  - 6
81
80
  - 0
82
81
  version: 1.6.0
82
+ type: :development
83
+ requirement: *id004
83
84
  prerelease: false
84
- version_requirements: *id004
85
85
  name: jeweler
86
86
  - !ruby/object:Gem::Dependency
87
- type: :development
88
- requirement: &id005 !ruby/object:Gem::Requirement
87
+ version_requirements: &id005 !ruby/object:Gem::Requirement
89
88
  none: false
90
89
  requirements:
91
90
  - - ">="
@@ -96,12 +95,12 @@ dependencies:
96
95
  - 9
97
96
  - 12
98
97
  version: 0.9.12
98
+ type: :development
99
+ requirement: *id005
99
100
  prerelease: false
100
- version_requirements: *id005
101
101
  name: mocha
102
102
  - !ruby/object:Gem::Dependency
103
- type: :development
104
- requirement: &id006 !ruby/object:Gem::Requirement
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
105
104
  none: false
106
105
  requirements:
107
106
  - - ">="
@@ -110,12 +109,12 @@ dependencies:
110
109
  segments:
111
110
  - 0
112
111
  version: "0"
112
+ type: :development
113
+ requirement: *id006
113
114
  prerelease: false
114
- version_requirements: *id006
115
115
  name: rcov
116
116
  - !ruby/object:Gem::Dependency
117
- type: :development
118
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ version_requirements: &id007 !ruby/object:Gem::Requirement
119
118
  none: false
120
119
  requirements:
121
120
  - - ">="
@@ -126,8 +125,9 @@ dependencies:
126
125
  - 3
127
126
  - 3
128
127
  version: 1.3.3
128
+ type: :development
129
+ requirement: *id007
129
130
  prerelease: false
130
- version_requirements: *id007
131
131
  name: sqlite3
132
132
  description: Ruby on Rails engine for Web applications that are strongly coupled with Chrome extensions
133
133
  email: costan@gmail.com
@@ -202,7 +202,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  requirements: []
203
203
 
204
204
  rubyforge_project:
205
- rubygems_version: 1.8.4
205
+ rubygems_version: 1.8.5
206
206
  signing_key:
207
207
  specification_version: 3
208
208
  summary: Serves a Chrome extension embedded in a Rails application