sync_attr 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44a69c13e6128090ae353172baf6047190bdb0ad
4
+ data.tar.gz: 29dda506593efe254aabfd28327f853c8fb54f5f
5
+ SHA512:
6
+ metadata.gz: 14bce4c1073400855394d048455b1168eb94fd53cb6e67c9069eece654f0b784cfd174a966f8943922646cf8fd865b7da2d786074e9cff045c467307fe4d6b72
7
+ data.tar.gz: 7dc91d0083331bfdbf27999ffd3584cecd4f02b4b6f2b21ae7ef1e57a28f0188711ae4c985e8a0a5958babc1c75fc63993cef4e8841a389a2f12090958a9484b
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :test do
4
+ gem "shoulda"
5
+ end
6
+
@@ -0,0 +1,26 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.12)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ bourne (1.1.2)
8
+ mocha (= 0.10.5)
9
+ i18n (0.6.4)
10
+ metaclass (0.0.1)
11
+ mocha (0.10.5)
12
+ metaclass (~> 0.0.1)
13
+ multi_json (1.6.1)
14
+ shoulda (3.3.2)
15
+ shoulda-context (~> 1.0.1)
16
+ shoulda-matchers (~> 1.4.1)
17
+ shoulda-context (1.0.2)
18
+ shoulda-matchers (1.4.2)
19
+ activesupport (>= 3.0.0)
20
+ bourne (~> 1.1.2)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ shoulda
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  sync_attr
2
2
  =========
3
3
 
4
+ Thread-safe Ruby class variables with lazy loaded default values and initializers
5
+
4
6
  * http://github.com/ClarityServices/sync_attr
5
7
 
6
8
  ### Introduction
@@ -12,7 +14,7 @@ that inconsistent data is not created.
12
14
  For example, without sync_attr if two threads attempt to write to the
13
15
  same attribute at the same time it is not deterministic what the results will be.
14
16
  This condition is made worse when two threads attempt to initialize class variables
15
- at the same time that could take a second or longer to complete.
17
+ at the same time that could take a second or longer to complete.
16
18
 
17
19
  ### Features
18
20
 
@@ -32,28 +34,57 @@ at the same time that could take a second or longer to complete.
32
34
  the Rails environment
33
35
  * Not dependent on Rails
34
36
 
35
- ### Examples
37
+ ### Synchronized Class Attribute example
36
38
 
37
39
  require 'sync_attr'
38
40
 
39
41
  # Sample class with lazy initialized Synchronized Class Attributes
40
- def Person
42
+ class Person
41
43
  include SyncAttr
42
44
 
43
45
  # Thread safe Class Attribute reader for name
44
- # Sets :name only when it is first called
46
+ # with a default value
45
47
  # Ideal for when name is loaded after startup from a database or config file
46
48
  sync_cattr_reader :name do
47
49
  "Joe Bloggs"
48
50
  end
49
51
 
50
52
  # Thread safe Class Attribute reader and writer for age
51
- # Sets :age only when it is first called
53
+ # with a default value
52
54
  sync_cattr_accessor :age do
53
55
  21
54
56
  end
55
57
  end
56
58
 
59
+ puts "The person is #{Person.name} with age #{Person.age}"
60
+
61
+ Person.age = 22
62
+ puts "The person is #{Person.name} now has age #{Person.age}"
63
+
64
+ Person.age = Proc.new {|age| age += 1 }
65
+ puts "The person is #{Person.name} now has age #{Person.age}"
66
+
67
+ ### Synchronized Instance Attribute example
68
+
69
+ require 'sync_attr'
70
+
71
+ # Sample class with lazy initialized Synchronized Class Attributes
72
+ class Person
73
+ include SyncAttr
74
+
75
+ # Thread safe Attribute reader for name
76
+ # with a default value
77
+ sync_attr_reader :name do
78
+ "Joe Bloggs"
79
+ end
80
+
81
+ # Thread safe Attribute reader and writer for age
82
+ # with a default value
83
+ sync_attr_accessor :age do
84
+ 21
85
+ end
86
+ end
87
+
57
88
  person = Person.new
58
89
  puts "The person is #{person.name} with age #{person.age}"
59
90
 
@@ -72,7 +103,6 @@ Meta
72
103
 
73
104
  * Code: `git clone git://github.com/ClarityServices/sync_attr.git`
74
105
  * Home: <https://github.com/ClarityServices/sync_attr>
75
- * Docs: <http://ClarityServices.github.com/sync_attr/>
76
106
  * Bugs: <http://github.com/reidmorrison/sync_attr/issues>
77
107
  * Gems: <http://rubygems.org/gems/sync_attr>
78
108
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  lib = File.expand_path('../lib/', __FILE__)
2
2
  $:.unshift lib unless $:.include?(lib)
3
3
 
4
+ require 'rubygems'
5
+ require 'rubygems/package'
4
6
  require 'rake/clean'
5
7
  require 'rake/testtask'
6
8
  require 'date'
@@ -18,10 +20,11 @@ task :gem do |t|
18
20
  s.date = Date.today.to_s
19
21
  s.summary = "Thread safe accessors for Ruby class and instance attributes. Supports thread safe lazy loading of attributes"
20
22
  s.description = "SyncAttr is a mixin to read, write and lazy initialize both class and instance variables in a multi-threaded environment when the attribute could be modified by two threads at the same time, written in Ruby."
21
- s.files = FileList['**/*'].exclude('*.gem', /nbproject/)
23
+ s.files = FileList["./**/*"].exclude(/\.gem$/, /\.log$/,/nbproject/).map{|f| f.sub(/^\.\//, '')}
24
+ s.license = "Apache License V2.0"
22
25
  s.has_rdoc = true
23
26
  end
24
- Gem::Builder.new(gemspec).build
27
+ Gem::Package.build gemspec
25
28
  end
26
29
 
27
30
  desc "Run Test Suite"
@@ -90,7 +90,7 @@ module SyncAttr
90
90
  # Returns the sync used by the included class to synchronize access to the
91
91
  # class attributes
92
92
  def sync_cattr_sync
93
- @sync_cattr_sync
93
+ @sync_cattr_sync ||= ::Sync.new
94
94
  end
95
95
 
96
96
  protected
@@ -1,3 +1,3 @@
1
- module SyncAttr #:nodoc
2
- VERSION = "0.1.1"
1
+ module SyncAttr
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,73 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sync_attr
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 1
9
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Reid Morrison
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2012-03-15 00:00:00 -04:00
18
- default_executable:
11
+ date: 2013-04-03 00:00:00.000000000 Z
19
12
  dependencies: []
20
-
21
- description: SyncAttr is a mixin to read, write and lazy initialize both class and instance variables in a multi-threaded environment when the attribute could be modified by two threads at the same time, written in Ruby.
22
- email:
13
+ description: SyncAttr is a mixin to read, write and lazy initialize both class and
14
+ instance variables in a multi-threaded environment when the attribute could be modified
15
+ by two threads at the same time, written in Ruby.
16
+ email:
23
17
  - reidmo@gmail.com
24
18
  executables: []
25
-
26
19
  extensions: []
27
-
28
20
  extra_rdoc_files: []
29
-
30
- files:
21
+ files:
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
31
27
  - examples/class_attribute.rb
32
28
  - examples/instance_attribute.rb
29
+ - lib/sync_attr.rb
33
30
  - lib/sync_attr/class_attributes.rb
34
31
  - lib/sync_attr/instance_attributes.rb
35
32
  - lib/sync_attr/version.rb
36
- - lib/sync_attr.rb
37
- - LICENSE.txt
38
- - Rakefile
39
- - README.md
40
33
  - test/class_attributes_test.rb
41
34
  - test/instance_attributes_test.rb
42
- has_rdoc: true
43
35
  homepage: https://github.com/ClarityServices/sync_attr
44
- licenses: []
45
-
36
+ licenses:
37
+ - Apache License V2.0
38
+ metadata: {}
46
39
  post_install_message:
47
40
  rdoc_options: []
48
-
49
- require_paths:
41
+ require_paths:
50
42
  - lib
51
- required_ruby_version: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
58
- required_rubygems_version: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- segments:
63
- - 0
64
- version: "0"
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
65
53
  requirements: []
66
-
67
54
  rubyforge_project:
68
- rubygems_version: 1.3.6
55
+ rubygems_version: 2.0.2
69
56
  signing_key:
70
- specification_version: 3
71
- summary: Thread safe accessors for Ruby class and instance attributes. Supports thread safe lazy loading of attributes
57
+ specification_version: 4
58
+ summary: Thread safe accessors for Ruby class and instance attributes. Supports thread
59
+ safe lazy loading of attributes
72
60
  test_files: []
73
-