devise-nobrainer 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25dcce5e3f690c8298f1ecc3604a55c135f212d9
4
+ data.tar.gz: 0a2d2a78f969af883a2712002634298afd16e5b9
5
+ SHA512:
6
+ metadata.gz: c8cb5b7b9a09e9f9cd95b6396a3302579852853dfc85df06d27b4ae8dba2fbfdb93c873b4221688395f84319956d263241d75dccd4592a16f4695d5b9e3cdfcb
7
+ data.tar.gz: 0e0a6741976551565ff72640996077db049ef6e8267362e08ef9de1f73ae94f180e4bc31ba4535ae52435fdc210c8636f2f279e4bbeea8f20b2adfeca70c52ed
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ NoBrainer Devise Adapter
2
+ ========================
3
+
4
+ nobrainer-devise is an adapter to make
5
+ [Devise](https://github.com/plataformatec/devise/) work nicely with
6
+ [NoBrainer](http://nobrainer.io).
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Include in your Gemfile:
12
+
13
+ ```ruby
14
+ gem 'nobrainer-devise'
15
+ ```
16
+
17
+ Use devise as usual.
18
+
19
+ If devise does not work, make sure that your `config/initializers/devise.rb` file
20
+ contains `require 'devise/orm/nobrainer'`.
21
+
22
+ License
23
+ -------
24
+
25
+ MIT license.
@@ -0,0 +1,3 @@
1
+ require 'orm_adapter/adapters/nobrainer'
2
+
3
+ NoBrainer::Document::ClassMethods.send :include, Devise::Models
@@ -0,0 +1,2 @@
1
+ require 'nobrainer'
2
+ require 'devise'
@@ -0,0 +1,59 @@
1
+ require 'rails/generators/named_base'
2
+ require 'generators/devise/orm_helpers'
3
+
4
+ module NoBrainer
5
+ module Generators
6
+ class DeviseGenerator < Rails::Generators::NamedBase
7
+ include Devise::Generators::OrmHelpers
8
+
9
+ def self.namespace
10
+ super.gsub(/no_brainer/,'nobrainer')
11
+ end
12
+
13
+ def generate_model
14
+ invoke "nobrainer:model", [name] unless model_exists? && behavior == :invoke
15
+ end
16
+
17
+ def inject_field_types
18
+ inject_into_file model_path, migration_data, :after => "include NoBrainer::Document\n" if model_exists?
19
+ end
20
+
21
+ def inject_devise_content
22
+ inject_into_file model_path, model_contents, :after => "include NoBrainer::Document\n" if model_exists?
23
+ end
24
+
25
+ def migration_data
26
+ <<RUBY
27
+ ## Database authenticatable
28
+ field :email, :type => String, :default => ""
29
+ field :encrypted_password, :type => String, :default => ""
30
+
31
+ ## Recoverable
32
+ field :reset_password_token, :type => String
33
+ field :reset_password_sent_at, :type => Time
34
+
35
+ ## Rememberable
36
+ field :remember_created_at, :type => Time
37
+
38
+ ## Trackable
39
+ field :sign_in_count, :type => Integer, :default => 0
40
+ field :current_sign_in_at, :type => Time
41
+ field :last_sign_in_at, :type => Time
42
+ field :current_sign_in_ip, :type => String
43
+ field :last_sign_in_ip, :type => String
44
+
45
+ ## Confirmable
46
+ # field :confirmation_token, :type => String
47
+ # field :confirmed_at, :type => Time
48
+ # field :confirmation_sent_at, :type => Time
49
+ # field :unconfirmed_email, :type => String # Only if using reconfirmable
50
+
51
+ ## Lockable
52
+ # field :failed_attempts, :type => Integer, :default => 0 # Only if lock strategy is :failed_attempts
53
+ # field :unlock_token, :type => String # Only if unlock strategy is :email or :both
54
+ # field :locked_at, :type => Time
55
+ RUBY
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,66 @@
1
+ require 'nobrainer'
2
+ require 'orm_adapter'
3
+
4
+ module NoBrainer
5
+ module Document
6
+ module ClassMethods
7
+ include OrmAdapter::ToAdapter
8
+ end
9
+
10
+ class OrmAdapter < ::OrmAdapter::Base
11
+ # get a list of column names for a given class
12
+ def column_names
13
+ klass.fields.keys
14
+ end
15
+
16
+ # @see OrmAdapter::Base#get!
17
+ def get!(id)
18
+ klass.find!(wrap_key(id))
19
+ end
20
+
21
+ # @see OrmAdapter::Base#get
22
+ def get(id)
23
+ klass.find(wrap_key(id))
24
+ end
25
+
26
+ # @see OrmAdapter::Base#find_first
27
+ def find_first(options = {})
28
+ conditions, order = extract_conditions!(options)
29
+ klass.where(conditions_to_fields(conditions)).order_by(*order_clause(order)).first
30
+ end
31
+
32
+ # @see OrmAdapter::Base#find_all
33
+ def find_all(options = {})
34
+ conditions, order, limit, offset = extract_conditions!(options)
35
+ klass.where(conditions_to_fields(conditions)).order_by(*order_clause(order)).limit(limit).offset(offset)
36
+ end
37
+
38
+ # @see OrmAdapter::Base#create!
39
+ def create!(attributes = {})
40
+ klass.create(attributes)
41
+ end
42
+
43
+ # @see OrmAdapter::Base#destroy
44
+ def destroy(object)
45
+ object.destroy if valid_object?(object)
46
+ end
47
+
48
+ protected
49
+
50
+ # converts and documents to ids
51
+ def conditions_to_fields(conditions)
52
+ conditions.inject({}) do |fields, (key, value)|
53
+ if value.is_a?(NoBrainer::Document) && column_names.include?(:"#{key}_id")
54
+ fields.merge(:"#{key}_id" => value.id)
55
+ else
56
+ fields.merge(key => value)
57
+ end
58
+ end
59
+ end
60
+
61
+ def order_clause(order)
62
+ order.map { |k,v| {k => v} }
63
+ end
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-nobrainer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Viennot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: nobrainer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.17.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.17.0
41
+ description: NoBrainer adapter for Devise
42
+ email:
43
+ - nicolas@viennot.biz
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/devise-nobrainer.rb
50
+ - lib/devise/orm/nobrainer.rb
51
+ - lib/generators/nobrainer/devise_generator.rb
52
+ - lib/orm_adapter/adapters/nobrainer.rb
53
+ homepage: http://github.com/nviennot/devise-nobrainer
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: NoBrainer adapter for Devise
77
+ test_files: []
78
+ has_rdoc: false