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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 417bd06fed3bd4350d940fb704b06528f9718dc9
4
- data.tar.gz: 67ba09cce7e7368dfa801a54da35fcf06b0c8e3e
3
+ metadata.gz: 0071fcf05aea5addf1962075b08dc2d97df64fc1
4
+ data.tar.gz: 8af0fd169ea520744358731ce7910870393aa551
5
5
  SHA512:
6
- metadata.gz: 141f451feb94f305b8c77c43d3f703810a3c8dbace980d0f78da1a0d218e62097c4c15a117fb4a2fe37832fc7a802bda3f6b2f5761b1c81c913c5947dc5728fa
7
- data.tar.gz: 5b9ae0cefdf6a16c8b95ce318c794160c895315a00e3a982f8f207ed025b4c443a4b57f70e017f9a924c75ffc521c38faea2eb0b2752e888934c448c6f18eafd
6
+ metadata.gz: fd5ed250899f958080ba6086b8c3a0850ffbd6546009418122ca3d08cb958f33754414eb1fd525ffc2a9fa48c3b04baf224701c3fda064e8613a3f31388fee5e
7
+ data.tar.gz: 4f45c9376b1821619bdbcbb1551d625bcb4d5d75d8128401d2c63eff02a3ad690af837f557ca7ed339bc7b3cc2a485bbaff323f2bd6ec74a4a1e83f9f6d78008
data/lib/dre.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'dre/engine'
2
+ require 'dre/rails/routes'
3
+
2
4
  require 'responders'
3
5
 
4
6
  module Dre
@@ -2,6 +2,10 @@ module Dre
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace Dre
4
4
 
5
+ initializer "dre.routes" do
6
+ Dre::Rails::Routes.install!
7
+ end
8
+
5
9
  config.generators do |g|
6
10
  g.test_framework :rspec
7
11
  g.fixture_replacement :factory_girl, dir: 'spec/factories'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Dre
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
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
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-26 00:00:00.000000000 Z
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.2.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.
@@ -1,5 +0,0 @@
1
- Dre::Engine.routes.draw do
2
- get 'devices/', to: 'devices#index'
3
- put 'devices/:token', to: 'devices#register'
4
- delete 'devices/:token', to: 'devices#deregister'
5
- end