kyototycoon-objects 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c497690f08d94ed0c5506ed230cc9d189625fba
4
+ data.tar.gz: fbef2e8a68cbbaeb9bb8e2c97edcc91324db07bb
5
+ SHA512:
6
+ metadata.gz: ac2c1870c9d04335f45632dee7a219cadc0e7b20d7dd0553686adb9e61feabafc862715f5d15f52b4bac156b6810f99bcf16cf06eabf9a6242cac17ffaeb46f0
7
+ data.tar.gz: 50286b6b3cee9ecc6817633271b933c0ca4630459dd5c0f3302825019b8d057380c8c85d4844d2fb2d5beeb92249475319bedd89e7c41e9be9f508fcd6c02edf
@@ -0,0 +1 @@
1
+ require 'kyototycoon/objects'
@@ -0,0 +1,33 @@
1
+ require 'active_support/core_ext/string/inflections'
2
+ require 'active_support/core_ext/object/try'
3
+
4
+ class KyotoTycoon
5
+ module Objects
6
+ def self.included base
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def kyototycoon_connection
12
+ @kyototycoon_connection ||= (KyotoTycoon.configures.values.last || KyotoTycoon.new).call
13
+ end
14
+
15
+ def kyototycoon_counter(name, options={})
16
+ options[:start] ||= 0
17
+ define_method(name) do
18
+ instance_variable_get("@#{name}") || instance_variable_set("@#{name}", self.class.kyototycoon_connection[kyototycoon_counter_key(name)].try(:to_i) || options[:start])
19
+ end
20
+
21
+ define_method("#{name}=") do |value|
22
+ instance_variable_set("@#{name}", value)
23
+ self.class.kyototycoon_connection[kyototycoon_counter_key(name)] = value
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+ def kyototycoon_counter_key attr
30
+ "#{self.class.name.underscore.pluralize}:#{self.id}:#{attr}"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ require 'kyototycoon/objects'
2
+ require 'kyototycoon'
3
+
4
+ describe KyotoTycoon::Objects do
5
+ class KTTest
6
+ include KyotoTycoon::Objects
7
+ kyototycoon_counter :views, start: 3
8
+ def initialize attributes = {}
9
+ @id ||= attributes[:id] || 0
10
+ end
11
+ def id; @id; end
12
+ end
13
+ before (:all) {KyotoTycoon.configure(:test, "0.0.0.0", 1978) { }}
14
+ describe "#kyototycoon_counter" do
15
+ after {KyotoTycoon.new.clear}
16
+ context "class method kyototycoon_counter" do
17
+ it {KTTest.should respond_to(:kyototycoon_counter)}
18
+ end
19
+ context "instance counter getter" do
20
+ it {KTTest.new.views.should == 3}
21
+ end
22
+ context "instance counter setter" do
23
+ before do
24
+ @kt_test = KTTest.new
25
+ @kt_test.views += 1
26
+ end
27
+ it {@kt_test.views.should == 4}
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kyototycoon-objects
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ChiKim
8
+ - TungD
9
+ - DaiNghiaVoTinh
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-07-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: kyototycoon
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: activesupport
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ description: Using KyotoTycoon as Ruby objects
44
+ email: huy.nguyendang@hotmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/kyototycoon-objects.rb
50
+ - lib/kyototycoon/objects.rb
51
+ - spec/kyototycoon_objects_spec.rb
52
+ homepage: http://github.com/chikim/kyototycoon-objects
53
+ licenses: []
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.5
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: KyotoTycoon Objects
75
+ test_files: []
76
+ has_rdoc: