php_session 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b17d2e471e2fc62c4c3681598183b9ce7551a277
4
- data.tar.gz: 45400c08a847f2ef18c8e0241648542fa01bc1ab
3
+ metadata.gz: f64dc34ff5c36c8bce6e5a9b402eb25f01285cbd
4
+ data.tar.gz: ac9b9f04c37483983660f4ac73a8a62eb93ac9a3
5
5
  SHA512:
6
- metadata.gz: 890cec71b4f562a2ac591099a36ea7371c190403546fb216749a72dc7dfc883ff520d72b77d87295d097a446a93ad97a625457f9067954d8ccbd4efc4ae6e869
7
- data.tar.gz: 608e598aabacdf55c0d1c834057ff1befe09ea8898e3438b9b3b4048a1a99eb76f10eb74072d401e8c4e73b301308a42bc39063443a7958a7eba3770d5f3c145
6
+ metadata.gz: 38e564743257d37ada276eca63b3648269d06e58ff9bb4805ff6085bcac48f76f44b9318144b379ba1aaf1c71aabf308de25feb2e5b63a6e77ebd9285384d4d7
7
+ data.tar.gz: 258ff69f3b9db0f348d126827a5f746a1a4f947d05ab9f342eb23773393b62f5e684278dc0e96dec9785ba170c96c4e684c6dab28879ddb34791f66e5e360401
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PHPSession
2
2
  [![Build Status](https://travis-ci.org/Shinpeim/ruby_php_session.png?branch=master)](https://travis-ci.org/Shinpeim/ruby_php_session)
3
-
3
+ [![Code Climate](https://codeclimate.com/github/Shinpeim/ruby_php_session.png)](https://codeclimate.com/github/Shinpeim/ruby_php_session)
4
4
  ## Description
5
5
  PHPSession is a php session file reader/writer. Multibyte string and exclusive control are supported.
6
6
 
@@ -23,25 +23,25 @@ Passing option to PHPSession.new, you can handle encodings.
23
23
  Options are:
24
24
 
25
25
  * :internal_encoding
26
-
26
+
27
27
  When this value is not nil, Session decoder tries to
28
28
  encode string values into this encoding.
29
-
29
+
30
30
  For a instance, if your php session file written in EUC-JP and you
31
31
  like to handle string as UTF-8 in Ruby, you should set :internal_encoding
32
32
  as "UTF-8" and :external_encoding as "EUC-JP".
33
33
 
34
34
  Default value is Encoding.default_internal.
35
-
35
+
36
36
  * :external_encoding
37
-
37
+
38
38
  This value should be same as php session file's encoding.
39
39
  Encoder tries to encode string values into this encoding.
40
-
40
+
41
41
  Default value is Encoding.default_external.
42
-
42
+
43
43
  * :encoding_option
44
-
44
+
45
45
  This value is passed to String#encode.
46
46
 
47
47
 
@@ -66,16 +66,16 @@ Or install it yourself as:
66
66
  :external_encoding => "EUC-JP", # encoding of sesion file is EUC-JP
67
67
  :encoding_option => {:undef => :replace} # passed to String#encode
68
68
  }
69
- # option's default values are
69
+ # option's default values are
70
70
  # :internal_encoding => Encoding.default_internal_encoding
71
71
  # :external_encoding => Encoding.default_external_encoding
72
72
  # :encoding_option => {}
73
- session = PHPSession.new(session_file_dir, session_id, option)
73
+ session = PHPSession.new(session_file_dir, option)
74
74
 
75
75
  begin
76
76
  # load session data from file and obtain a lock
77
- data = session.load
78
-
77
+ data = session.load(session_id)
78
+
79
79
  data.is_a? Hash # => true
80
80
 
81
81
  # save session and release the lock
data/lib/php_session.rb CHANGED
@@ -6,7 +6,7 @@ require "php_session/encoder"
6
6
 
7
7
  class PHPSession
8
8
  attr_reader :data
9
- def initialize(session_dir, session_id, option = {})
9
+ def initialize(session_dir, option = {})
10
10
  default_option = {
11
11
  :internal_encoding => Encoding.default_internal,
12
12
  :external_encoding => Encoding.default_external,
@@ -14,12 +14,12 @@ class PHPSession
14
14
  }
15
15
  @option = default_option.merge(option)
16
16
  @session_dir = File.expand_path(session_dir)
17
- set_session_id(session_id)
18
17
 
19
18
  @file = nil
20
19
  end
21
20
 
22
- def load
21
+ def load(session_id)
22
+ set_session_id(session_id)
23
23
  @file = File.open(file_path, File::CREAT|File::RDWR)
24
24
 
25
25
  unless @file.flock(File::LOCK_EX)
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  class PHPSession
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
@@ -12,9 +12,9 @@ describe PHPSession do
12
12
  :internal_encoding => nil,
13
13
  :external_encoding => "UTF-8",
14
14
  }
15
- session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id], option)
15
+ session = PHPSession.new(@session_file[:dir_name], option)
16
16
  begin
17
- data = session.load
17
+ data = session.load(@session_file[:session_id])
18
18
  expect(data).to eq({"key" => "テスト🍺"})
19
19
  ensure
20
20
  session.ensure_file_closed
@@ -25,9 +25,9 @@ describe PHPSession do
25
25
  :internal_encoding => "UTF-8",
26
26
  :external_encoding => "UTF-8",
27
27
  }
28
- session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id], option)
28
+ session = PHPSession.new(@session_file[:dir_name], option)
29
29
  begin
30
- data = session.load
30
+ data = session.load(@session_file[:session_id])
31
31
  expect(data).to eq({"key" => "テスト🍺"})
32
32
  ensure
33
33
  session.ensure_file_closed
@@ -41,9 +41,9 @@ describe PHPSession do
41
41
  :undef => :replace
42
42
  }
43
43
  }
44
- session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id], option)
44
+ session = PHPSession.new(@session_file[:dir_name], option)
45
45
  begin
46
- data = session.load
46
+ data = session.load(@session_file[:session_id])
47
47
  expect(data).to eq({"key" => "テスト🍺".encode("EUC-JP", {:undef => :replace})})
48
48
  ensure
49
49
  session.ensure_file_closed
@@ -59,9 +59,9 @@ describe PHPSession do
59
59
  end
60
60
 
61
61
  it "should return session data" do
62
- session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id])
62
+ session = PHPSession.new(@session_file[:dir_name])
63
63
  begin
64
- data = session.load
64
+ data = session.load(@session_file[:session_id])
65
65
  expect(data).to eq({"key" => "a"})
66
66
  ensure
67
67
  session.ensure_file_closed
@@ -75,9 +75,9 @@ describe PHPSession do
75
75
 
76
76
  context "when session file dosen't exist" do
77
77
  it "should return new session data" do
78
- session = PHPSession.new(Dir.tmpdir,"session_id")
78
+ session = PHPSession.new(Dir.tmpdir)
79
79
  begin
80
- data = session.load
80
+ data = session.load("session_id")
81
81
  expect(data).to eq({})
82
82
  ensure
83
83
  session.ensure_file_closed
@@ -97,8 +97,8 @@ describe PHPSession do
97
97
  :internal_encoding => "UTF-8",
98
98
  :encoding_option => {:undef => :replace}
99
99
  }
100
- session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id], option)
101
- data = session.load
100
+ session = PHPSession.new(@session_file[:dir_name], option)
101
+ data = session.load(@session_file[:session_id])
102
102
  data["key"] = "テスト🍣"
103
103
  session.commit(data)
104
104
 
@@ -116,20 +116,8 @@ describe PHPSession do
116
116
  context "when session file exists and loaded" do
117
117
  before do
118
118
  @session_file = create_dummy_session_file('key|s:1:"a";')
119
- @session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id])
120
- @session.load
121
- end
122
-
123
- it "should delete session file" do
124
- @session.destroy
125
- expect(File.exists?(@session_file[:file_path])).to eq(false)
126
- end
127
- end
128
-
129
- context "when session file exists and not loaded" do
130
- before do
131
- @session_file = create_dummy_session_file('key|s:1:"a";')
132
- @session = PHPSession.new(@session_file[:dir_name], @session_file[:session_id])
119
+ @session = PHPSession.new(@session_file[:dir_name])
120
+ @session.load(@session_file[:session_id])
133
121
  end
134
122
 
135
123
  it "should delete session file" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: php_session
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinpei Maruyama