dre 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dre.rb +2 -0
- data/lib/dre/engine.rb +4 -0
- data/lib/dre/rails/routes.rb +52 -0
- data/lib/dre/rails/routes/mapper.rb +28 -0
- data/lib/dre/rails/routes/mapping.rb +29 -0
- data/lib/dre/version.rb +1 -1
- metadata +6 -4
- data/config/routes.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0071fcf05aea5addf1962075b08dc2d97df64fc1
|
4
|
+
data.tar.gz: 8af0fd169ea520744358731ce7910870393aa551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd5ed250899f958080ba6086b8c3a0850ffbd6546009418122ca3d08cb958f33754414eb1fd525ffc2a9fa48c3b04baf224701c3fda064e8613a3f31388fee5e
|
7
|
+
data.tar.gz: 4f45c9376b1821619bdbcbb1551d625bcb4d5d75d8128401d2c63eff02a3ad690af837f557ca7ed339bc7b3cc2a485bbaff323f2bd6ec74a4a1e83f9f6d78008
|
data/lib/dre.rb
CHANGED
data/lib/dre/engine.rb
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'dre/rails/routes/mapping'
|
2
|
+
require 'dre/rails/routes/mapper'
|
3
|
+
|
4
|
+
module Dre
|
5
|
+
module Rails
|
6
|
+
class Routes
|
7
|
+
module Helper
|
8
|
+
def mount_dre(options = {}, &block)
|
9
|
+
Dre::Rails::Routes.new(self, &block).generate_routes!(options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.install!
|
14
|
+
ActionDispatch::Routing::Mapper.send :include, Dre::Rails::Routes::Helper
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_accessor :routes
|
18
|
+
|
19
|
+
def initialize(routes, &block)
|
20
|
+
@routes, @block = routes, block
|
21
|
+
end
|
22
|
+
|
23
|
+
def generate_routes!(options)
|
24
|
+
@mapping = Mapper.new.map(&@block)
|
25
|
+
routes.scope options[:scope] || '', as: 'dre' do
|
26
|
+
map_route(:devices, :device_routes)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def map_route(name, method)
|
33
|
+
unless @mapping.skipped?(name)
|
34
|
+
send method, @mapping[name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def device_routes(mapping)
|
39
|
+
routes.resources(
|
40
|
+
:devices,
|
41
|
+
controller: mapping[:controllers],
|
42
|
+
as: :devices,
|
43
|
+
path: 'devices',
|
44
|
+
only: [:index],
|
45
|
+
)
|
46
|
+
|
47
|
+
routes.put 'devices/:token', controller: mapping[:controllers], action: :register
|
48
|
+
routes.delete 'devices/:token', controller: mapping[:controllers], action: :deregister
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Dre
|
2
|
+
module Rails
|
3
|
+
class Routes
|
4
|
+
class Mapper
|
5
|
+
def initialize(mapping = Mapping.new)
|
6
|
+
@mapping = mapping
|
7
|
+
end
|
8
|
+
|
9
|
+
def map(&block)
|
10
|
+
self.instance_eval(&block) if block
|
11
|
+
@mapping
|
12
|
+
end
|
13
|
+
|
14
|
+
def controllers(controller_names = {})
|
15
|
+
@mapping.controllers.merge!(controller_names)
|
16
|
+
end
|
17
|
+
|
18
|
+
def skip_controllers(*controller_names)
|
19
|
+
@mapping.skips = controller_names
|
20
|
+
end
|
21
|
+
|
22
|
+
def as(alias_names = {})
|
23
|
+
@mapping.as.merge!(alias_names)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Dre
|
2
|
+
module Rails
|
3
|
+
class Routes
|
4
|
+
class Mapping
|
5
|
+
attr_accessor :controllers, :as, :skips
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@controllers = {
|
9
|
+
devices: 'dre/devices',
|
10
|
+
}
|
11
|
+
|
12
|
+
@as = {}
|
13
|
+
@skips = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](routes)
|
17
|
+
{
|
18
|
+
controllers: @controllers[routes],
|
19
|
+
as: @as[routes]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def skipped?(controller)
|
24
|
+
@skips.include?(controller)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/dre/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Ivanopoulos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -126,10 +126,12 @@ files:
|
|
126
126
|
- app/helpers/dre/application_helper.rb
|
127
127
|
- app/models/dre/device.rb
|
128
128
|
- app/views/layouts/dre/application.html.erb
|
129
|
-
- config/routes.rb
|
130
129
|
- lib/dre.rb
|
131
130
|
- lib/dre/acts_as_device_owner.rb
|
132
131
|
- lib/dre/engine.rb
|
132
|
+
- lib/dre/rails/routes.rb
|
133
|
+
- lib/dre/rails/routes/mapper.rb
|
134
|
+
- lib/dre/rails/routes/mapping.rb
|
133
135
|
- lib/dre/version.rb
|
134
136
|
- lib/generators/dre/install/install_generator.rb
|
135
137
|
- lib/generators/dre/install/templates/initializer.rb
|
@@ -155,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
157
|
version: '0'
|
156
158
|
requirements: []
|
157
159
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.4.5
|
159
161
|
signing_key:
|
160
162
|
specification_version: 4
|
161
163
|
summary: A device registration engine for Rails.
|