dre 0.0.3
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +20 -0
- data/app/assets/javascripts/dre/application.js +13 -0
- data/app/assets/stylesheets/dre/application.css +15 -0
- data/app/controllers/dre/application_controller.rb +4 -0
- data/app/controllers/dre/devices_controller.rb +50 -0
- data/app/helpers/dre/application_helper.rb +4 -0
- data/app/models/dre/device.rb +27 -0
- data/app/views/layouts/dre/application.html.erb +14 -0
- data/config/routes.rb +5 -0
- data/lib/dre/acts_as_device_owner.rb +14 -0
- data/lib/dre/engine.rb +12 -0
- data/lib/dre/version.rb +3 -0
- data/lib/dre.rb +29 -0
- data/lib/generators/dre/install/install_generator.rb +25 -0
- data/lib/generators/dre/install/templates/initializer.rb +7 -0
- data/lib/generators/dre/install/templates/migration.rb +14 -0
- data/lib/tasks/dre_tasks.rake +4 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aaaa75fdb152a349ffb05e012ecd12bd238d40f2
|
4
|
+
data.tar.gz: aaced50bfebd0298d4e4e34d3c74401d15d4573c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33c22329664de9788920136bc5bf27ac17e1260e43101828dcce5744fb3d396143ae3f8cb9ceb4ebda3224a64c8e90116b1a4b8d8fb30ef9275fc88646711588
|
7
|
+
data.tar.gz: c6146b863eea07f5c3c84527ebbf9209bb8e8d7731f69be1d36c87d38fe06cfdf87c91e289670aa4d16485dfccbc2b3b1d20110cff5cd9147957fed840fcbd40
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Anton Ivanopoulos
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
|
8
|
+
load 'rails/tasks/engine.rake'
|
9
|
+
|
10
|
+
Bundler::GemHelper.install_tasks
|
11
|
+
|
12
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each { |f| load f }
|
13
|
+
|
14
|
+
require 'rspec/core'
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
|
17
|
+
desc 'Run all specs in spec directory (excluding plugin specs)'
|
18
|
+
RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
|
19
|
+
|
20
|
+
task default: :spec
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_dependency 'dre/application_controller'
|
2
|
+
|
3
|
+
module Dre
|
4
|
+
class DevicesController < ApplicationController
|
5
|
+
before_filter :authenticate!
|
6
|
+
|
7
|
+
respond_to :json
|
8
|
+
|
9
|
+
def index
|
10
|
+
render json: { devices: collection }
|
11
|
+
end
|
12
|
+
|
13
|
+
def register
|
14
|
+
@device = collection.find_by(token: params[:token]) || Device.new(owner: user, token: params[:token])
|
15
|
+
response = @device.persisted? ? 200 : 201
|
16
|
+
|
17
|
+
if @device.save
|
18
|
+
render json: { device: @device }, status: response
|
19
|
+
else
|
20
|
+
render json: { errors: @device.errors }, status: :unprocessable_entity
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def deregister
|
25
|
+
@device = collection.find_by(token: params[:token])
|
26
|
+
|
27
|
+
if @device.nil?
|
28
|
+
render nothing: true, status: :not_found
|
29
|
+
elsif @device.destroy
|
30
|
+
render nothing: true, status: :ok
|
31
|
+
else
|
32
|
+
render json: { errors: @device.errors }, status: :unprocessable_entity
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def authenticate!
|
39
|
+
method(Dre.authentication_method).call
|
40
|
+
end
|
41
|
+
|
42
|
+
def user
|
43
|
+
@user ||= method(Dre.current_user_method).call
|
44
|
+
end
|
45
|
+
|
46
|
+
def collection
|
47
|
+
@devices ||= Device.for_owner(user).limit(30)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Dre
|
2
|
+
class Device < ActiveRecord::Base
|
3
|
+
# Associations:
|
4
|
+
belongs_to :owner, polymorphic: true
|
5
|
+
|
6
|
+
# Validations:
|
7
|
+
validates :owner_id, presence: true
|
8
|
+
validates :owner_type, presence: true
|
9
|
+
validates :token, presence: true
|
10
|
+
validates :token, uniqueness: { scope: [:owner_id, :owner_type] }
|
11
|
+
|
12
|
+
# Hooks:
|
13
|
+
after_create :invalidate_used_token
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def invalidate_used_token
|
18
|
+
Device.where(token: token).where.not(id: id).delete_all
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
def for_owner(owner)
|
23
|
+
where(owner_id: owner.id, owner_type: owner.class.base_class)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/config/routes.rb
ADDED
data/lib/dre/engine.rb
ADDED
data/lib/dre/version.rb
ADDED
data/lib/dre.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'dre/engine'
|
2
|
+
require 'responders'
|
3
|
+
|
4
|
+
module Dre
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :ActsAsDeviceOwner, 'dre/acts_as_device_owner'
|
8
|
+
|
9
|
+
# Method to authenticate a user:
|
10
|
+
mattr_accessor :authentication_method
|
11
|
+
@@authentication_method = nil
|
12
|
+
|
13
|
+
# Method to retrieve the current authenticated user:
|
14
|
+
mattr_accessor :current_user_method
|
15
|
+
@@current_user_method = nil
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Default way to setup Dre:
|
20
|
+
def self.setup
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module ActiveRecord
|
26
|
+
class Base
|
27
|
+
include Dre::ActsAsDeviceOwner
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
class Dre::InstallGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template 'initializer.rb', 'config/initializers/dre.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_arcade_migration
|
13
|
+
migration_template 'migration.rb', 'db/migrate/dre_create_devices.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
# Implement the required interface for Rails::Generators::Migration.
|
17
|
+
def self.next_migration_number(dirname)
|
18
|
+
next_migration_number = current_migration_number(dirname) + 1
|
19
|
+
if ActiveRecord::Base.timestamped_migrations
|
20
|
+
[Time.now.utc.strftime('%Y%m%d%H%M%S'), '%.14d' % next_migration_number].max
|
21
|
+
else
|
22
|
+
'%.3d' % next_migration_number
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Dre.setup do |config|
|
2
|
+
# Dre will call this within DevicesController to ensure the user is authenticated.
|
3
|
+
config.authentication_method = :authenticate_user!
|
4
|
+
|
5
|
+
# Dre will call this within DevicesController to return the current logged in user.
|
6
|
+
config.current_user_method = :current_user
|
7
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class DreCreateDevices < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :dre_devices do |t|
|
4
|
+
t.string :token
|
5
|
+
t.integer :owner_id
|
6
|
+
t.string :owner_type
|
7
|
+
|
8
|
+
t.timestamps null: false
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :dre_devices, [:owner_id, :owner_type]
|
12
|
+
add_index :dre_devices, :token
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dre
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Ivanopoulos
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: responders
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
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: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: factory_girl_rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: An engine to easily add in a Device model and registration / deregistration
|
98
|
+
system by supplying a token provided mobile applications. Provides easy associations
|
99
|
+
to device owner models.
|
100
|
+
email:
|
101
|
+
- a.ivanopoulos@gmail.com
|
102
|
+
executables: []
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- MIT-LICENSE
|
107
|
+
- Rakefile
|
108
|
+
- app/assets/javascripts/dre/application.js
|
109
|
+
- app/assets/stylesheets/dre/application.css
|
110
|
+
- app/controllers/dre/application_controller.rb
|
111
|
+
- app/controllers/dre/devices_controller.rb
|
112
|
+
- app/helpers/dre/application_helper.rb
|
113
|
+
- app/models/dre/device.rb
|
114
|
+
- app/views/layouts/dre/application.html.erb
|
115
|
+
- config/routes.rb
|
116
|
+
- lib/dre.rb
|
117
|
+
- lib/dre/acts_as_device_owner.rb
|
118
|
+
- lib/dre/engine.rb
|
119
|
+
- lib/dre/version.rb
|
120
|
+
- lib/generators/dre/install/install_generator.rb
|
121
|
+
- lib/generators/dre/install/templates/initializer.rb
|
122
|
+
- lib/generators/dre/install/templates/migration.rb
|
123
|
+
- lib/tasks/dre_tasks.rake
|
124
|
+
homepage: http://www.papercloud.com.au
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.2.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: A device registration engine for Rails.
|
148
|
+
test_files: []
|