singularity 0.1.0 → 0.1.1

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.
@@ -1,29 +1,25 @@
1
1
  require 'rubygems'
2
2
  require 'redis'
3
3
  require 'securerandom'
4
+ require 'forwardable'
5
+ require 'singularity/configuration'
4
6
 
5
7
  module Singularity
6
- def self.cattr_accessor(attribute, default = nil)
7
- class_variable_set("@@#{attribute}", default)
8
- class_eval <<-EOS
9
- def self.#{attribute}=(value)
10
- @@#{attribute} = value
11
- end
8
+ @config = Configuration.new
12
9
 
13
- def self.#{attribute}
14
- @@#{attribute}
15
- end
16
- EOS
17
- end
10
+ class << self
11
+ extend Forwardable
18
12
 
19
- cattr_accessor :auth_path, "http://authmaster.local:9292/api"
20
- cattr_accessor :master, false
21
- cattr_accessor :session_prefix, "rack_session"
22
- cattr_accessor :profile_prefix, "profile"
23
- cattr_accessor :token_prefix, "singularity_session_token"
24
- cattr_accessor :warden_user_key, "warden.user.default.key"
13
+ def configure
14
+ if block_given?
15
+ yield @config
16
+ else
17
+ @config
18
+ end
19
+ end
25
20
 
26
- class << self
21
+ def_delegators :@config, :auth_path, :session_prefix, :profile_prefix, :token_prefix, :warden_user_key
22
+ def_delegators :@config, :auth_path=, :session_prefix=, :profile_prefix=, :token_prefix=, :warden_user_key=
27
23
 
28
24
  def generate_session_token(session_id, session, options = {})
29
25
  if session.key?("_token_expires") && session["_token_expires"].to_i > Time.now.to_i
@@ -0,0 +1,17 @@
1
+ module Singularity
2
+ class Configuration
3
+ attr_accessor :auth_path, :session_prefix, :profile_prefix, :token_prefix, :warden_user_key
4
+
5
+ def initialize
6
+ reset
7
+ end
8
+
9
+ def reset
10
+ @auth_path = 'http://localhost:9292'
11
+ @session_prefix = 'rack_session'
12
+ @profile_prefix = 'profile'
13
+ @token_prefix = 'singularity_session_token'
14
+ @warden_user_key = 'warden.user.default.key'
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,6 @@
1
1
  require 'redis/hash_key'
2
2
  require 'forwardable'
3
+ require 'securerandom'
3
4
  require 'singularity/password_hash'
4
5
 
5
6
  module Singularity
@@ -19,7 +20,7 @@ module Singularity
19
20
  def_delegators :profile, :[], :[]=
20
21
  def_delegators :profile, :all, :bulk_get, :bulk_set, :each, :empty?, :fetch
21
22
  def_delegators :profile, :has_key?, :include?, :incr, :incrby, :key, :key?
22
- def_delegators :profile, :keys, :member?, :vals, :values, :clear
23
+ def_delegators :profile, :keys, :member?, :vals, :values, :clear, :delete
23
24
 
24
25
  def password_hash
25
26
  self['password_hash']
@@ -1,3 +1,3 @@
1
1
  module Singularity
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,84 @@
1
+ require 'spec_helper'
2
+ require 'singularity'
3
+
4
+ describe Singularity do
5
+ after(:each) { Singularity.configure.reset }
6
+
7
+ context 'auth_path' do
8
+ it "defaults to localhost:9292" do
9
+ expect( subject.auth_path ).to eq 'http://localhost:9292'
10
+ end
11
+
12
+ it "is writeable" do
13
+ subject.auth_path = 'http://authmaster.local:8080'
14
+
15
+ expect( subject.auth_path ).to eq 'http://authmaster.local:8080'
16
+ end
17
+ end
18
+
19
+ context 'session_prefix' do
20
+ it "defaults to rack_session" do
21
+ expect( subject.session_prefix ).to eq 'rack_session'
22
+ end
23
+
24
+ it "is writeable" do
25
+ subject.session_prefix = 'foo'
26
+ expect( subject.session_prefix ).to eq 'foo'
27
+ end
28
+ end
29
+
30
+ context 'profile_prefix' do
31
+ it "defaults to profile" do
32
+ expect( subject.profile_prefix ).to eq 'profile'
33
+ end
34
+
35
+ it "is writeable" do
36
+ subject.profile_prefix = 'user'
37
+ expect( subject.profile_prefix ).to eq 'user'
38
+ end
39
+ end
40
+
41
+ context 'token_prefix' do
42
+ it "defaults to singularity_session_token" do
43
+ expect( subject.token_prefix ).to eq 'singularity_session_token'
44
+ end
45
+
46
+ it "is writeable" do
47
+ subject.token_prefix = 'token'
48
+ expect( subject.token_prefix ).to eq 'token'
49
+ end
50
+ end
51
+
52
+ context 'warden_user_key' do
53
+ it "defaults to warden.user.default.key" do
54
+ expect( subject.warden_user_key ).to eq 'warden.user.default.key'
55
+ end
56
+
57
+ it "is writeable" do
58
+ subject.warden_user_key = 'singularity.user'
59
+ expect( subject.warden_user_key ).to eq 'singularity.user'
60
+ end
61
+ end
62
+
63
+ context 'configure' do
64
+ it "returns config object if not given a block" do
65
+ expect( subject.configure ).to be_a Singularity::Configuration
66
+ end
67
+
68
+ it "accepts a block to set configuration" do
69
+ subject.configure do |config|
70
+ config.auth_path = 'http://foobar.local:8088'
71
+ config.session_prefix = 'foo_session'
72
+ config.profile_prefix = 'foo_user'
73
+ config.token_prefix = 'foo_token'
74
+ config.warden_user_key = 'foo.user.key'
75
+ end
76
+
77
+ expect( subject.auth_path ).to eq 'http://foobar.local:8088'
78
+ expect( subject.session_prefix ).to eq 'foo_session'
79
+ expect( subject.profile_prefix ).to eq 'foo_user'
80
+ expect( subject.token_prefix ).to eq 'foo_token'
81
+ expect( subject.warden_user_key ).to eq 'foo.user.key'
82
+ end
83
+ end
84
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singularity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-18 00:00:00.000000000 Z
13
+ date: 2016-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redis-objects
@@ -100,10 +100,12 @@ extensions: []
100
100
  extra_rdoc_files: []
101
101
  files:
102
102
  - LICENSE
103
+ - lib/singularity/configuration.rb
103
104
  - lib/singularity/password_hash.rb
104
105
  - lib/singularity/profile.rb
105
106
  - lib/singularity/version.rb
106
107
  - lib/singularity.rb
108
+ - spec/singularity/configuration_spec.rb
107
109
  - spec/singularity/profile_spec.rb
108
110
  - spec/spec_helper.rb
109
111
  homepage: https://github.com/lyconic/singularity