risky 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,24 +1,31 @@
1
1
  Risky
2
2
  =====
3
3
 
4
+ (Hey guys, I'll be porting over tests from our internal suite in the next few evenings. --Kyle)
5
+
4
6
  A simple, lightweight object layer for Riak.
5
7
 
8
+ $ gem install risky
9
+
6
10
  class User < Risky
7
11
  bucket :users
8
12
  end
9
13
 
10
14
  User.new('clu', 'fights' => 'for the users').save
11
-
12
15
  User['clu']['fights'] #=> 'for the users'
13
16
 
14
17
  Built on top of seancribb's excellent riak-client, Risky provides basic
15
18
  infrastructure for designing models with attributes (including defaults and
16
- casting to/from JSON), validation, lifecycle callbacks, link-walking,
17
- mapreduce, and more. Modules are available for timestamps, chronologically ordered lists, and basic secondary indexes.
19
+ casting to/from JSON), conflict resolution, validation, lifecycle callbacks,
20
+ link-walking, mapreduce, and more. Modules are available for timestamps,
21
+ chronologically ordered lists, and basic secondary indexes.
18
22
 
19
- Risky does not provide the rich API of Ripple, but it also does not require activesupport. It strives to be understandable, minimal, and modular. Magic is avoided in favor of module composition and a compact API.
23
+ Risky does not provide the rich API of Ripple, but it also does not require
24
+ activesupport. It strives to be understandable, minimal, and modular. Magic is
25
+ avoided in favor of module composition and a compact API.
20
26
 
21
- Risky stores every instance of a model in a given bucket, indexed by key. Objects are stored as JSON hashes.
27
+ Risky stores every instance of a model in a given bucket, indexed by key.
28
+ Objects are stored as JSON hashes.
22
29
 
23
30
  Show me the code!
24
31
  -----------------
@@ -38,8 +45,8 @@ Show me the code!
38
45
  value :created_at, :class => Time
39
46
 
40
47
  # Provides User.by_name. Changing the name stores an object in the
41
- # users_by_name bucket, with key user.name, linking back to us. A validate
42
- # function is used to ensure uniqueness before saving.
48
+ # users_by_name bucket, with key user.name, linking back to us. A
49
+ # validate function is used to ensure uniqueness before saving.
43
50
  index :name, :unique => true
44
51
 
45
52
  # Here, a custom proc returns the key used for the index.
data/lib/risky.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  class Risky
2
+ require 'set'
2
3
  require 'riak'
3
4
 
4
5
  $LOAD_PATH << File.expand_path(File.dirname(__FILE__))
@@ -6,13 +7,16 @@ class Risky
6
7
  # Exceptions
7
8
  require 'risky/invalid'
8
9
  require 'risky/not_found'
10
+
11
+ # Fix threading autoload bugs
12
+ require 'risky/threadsafe'
9
13
 
10
14
  # Plugins
11
15
  require 'risky/cron_list'
12
16
  require 'risky/indexes'
13
17
  require 'risky/timestamps'
14
18
 
15
- include Enumerable
19
+ extend Enumerable
16
20
 
17
21
  # Get a model by key. Returns nil if not found. You can also pass opts to
18
22
  # #reload (e.g. :r, :merge => false).
@@ -228,9 +232,21 @@ class Risky
228
232
 
229
233
  # The Riak::Client backing this model class.
230
234
  def self.riak
231
- @riak ||= superclass.riak
235
+ if c = Thread.current["#{self}.riak"]
236
+ c
237
+ elsif @riak and @riak.respond_to? :call
238
+ Thread.current["#{self}.riak"] = @riak.call(self)
239
+ elsif @riak
240
+ Thread.current["#{self}.riak"] = @riak
241
+ else
242
+ superclass.riak
243
+ end
232
244
  end
233
245
 
246
+ # Sets the Riak Client backing this model class. If client is a lambda (or
247
+ # anything responding to #call), it will be invoked to generate a new client
248
+ # every time Risky feels it is appropriate. Clients are stored in
249
+ # thread-local storage, under "Classname.riak".
234
250
  def self.riak=(client)
235
251
  @riak = client
236
252
  end
@@ -282,7 +298,7 @@ class Risky
282
298
  key = key.to_s unless key.nil?
283
299
 
284
300
  @riak_object ||= Riak::RObject.new(self.class.bucket, key)
285
- @riak_object.content_type = 'application/javascript'
301
+ @riak_object.content_type = 'application/json'
286
302
 
287
303
  @new = true
288
304
  @merged = false
@@ -457,6 +473,7 @@ class Risky
457
473
  end
458
474
 
459
475
  @riak_object.raw_data = @values.to_json
476
+ @riak_object.content_type = "application/json"
460
477
 
461
478
  store_opts = {}
462
479
  store_opts[:w] = opts[:w] if opts[:w]
@@ -20,8 +20,13 @@ module Risky::CronList
20
20
  end
21
21
 
22
22
  def merge(versions)
23
+ # Order versions chronologically
23
24
  p = super(versions)
24
- items = sort_items(versions.map(&:items).flatten!.uniq)
25
+ items = sort_items(
26
+ versions.inject([]) do |list, version|
27
+ list |= version.items.reverse
28
+ end.reverse
29
+ )
25
30
 
26
31
  if limit = self.limit
27
32
  p.items = items[0...limit]
data/lib/risky/indexes.rb CHANGED
@@ -70,7 +70,7 @@ module Risky::Indexes
70
70
  index = Riak::RObject.new(self.class.riak[opts[:bucket]], current)
71
71
  index.content_type = 'text/plain'
72
72
  index.data = ''
73
- index.links = Set.new([@riak_robject.to_link('value')])
73
+ index.links = Set.new([@riak_object.to_link('value')])
74
74
  index.store
75
75
  end
76
76
  end
@@ -0,0 +1,42 @@
1
+ # Autoload is broken with threading.
2
+ Riak::Bucket
3
+ Riak::Client
4
+ Riak::Link
5
+ Riak::WalkSpec
6
+ Riak::RObject
7
+
8
+ Riak::FailedRequest
9
+ Riak::MapReduceError
10
+
11
+ Riak::Util::Escape
12
+ Riak::Util::Headers
13
+ Riak::Util::Multipart
14
+ Riak::Util::Translation
15
+
16
+ Riak::Client::HTTPBackend
17
+ Riak::Client::HTTPBackend::RequestHeaders
18
+ Riak::Client::HTTPBackend::TransportMethods
19
+ Riak::Client::HTTPBackend::ObjectMethods
20
+ Riak::Client::HTTPBackend::Configuration
21
+
22
+ Riak::Client::NetHTTPBackend
23
+
24
+ Riak::MapReduce
25
+ Riak::MapReduce::Phase
26
+
27
+ I18n::ArgumentError
28
+ I18n::Backend
29
+ I18n::Backend::Base
30
+ I18n::Backend::Simple
31
+ I18n::Config
32
+ I18n::ExceptionHandler
33
+ I18n::Gettext
34
+ I18n::InvalidLocale
35
+ I18n::InvalidLocaleData
36
+ I18n::InvalidPluralizationData
37
+ I18n::Locale
38
+ I18n::MissingInterpolationArgument
39
+ I18n::MissingTranslationData
40
+ I18n::ReservedInterpolationKey
41
+ I18n::Tests
42
+ I18n::UnknownFileType
data/lib/risky/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Risky
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: risky
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 31
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 0
9
- version: 0.1.0
9
+ - 2
10
+ version: 0.1.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Kyle Kingsbury
@@ -14,21 +15,23 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-04-07 00:00:00 -07:00
18
+ date: 2011-04-22 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: riak-client
22
23
  prerelease: false
23
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
24
26
  requirements:
25
27
  - - ~>
26
28
  - !ruby/object:Gem::Version
29
+ hash: 23
27
30
  segments:
31
+ - 1
32
+ - 0
28
33
  - 0
29
- - 8
30
- - 2
31
- version: 0.8.2
34
+ version: 1.0.0
32
35
  type: :runtime
33
36
  version_requirements: *id001
34
37
  description:
@@ -40,13 +43,14 @@ extensions: []
40
43
  extra_rdoc_files: []
41
44
 
42
45
  files:
43
- - lib/risky/invalid.rb
44
- - lib/risky/not_found.rb
46
+ - lib/risky.rb
45
47
  - lib/risky/version.rb
46
- - lib/risky/timestamps.rb
48
+ - lib/risky/not_found.rb
47
49
  - lib/risky/indexes.rb
50
+ - lib/risky/invalid.rb
51
+ - lib/risky/timestamps.rb
52
+ - lib/risky/threadsafe.rb
48
53
  - lib/risky/cron_list.rb
49
- - lib/risky.rb
50
54
  - LICENSE
51
55
  - README.markdown
52
56
  has_rdoc: true
@@ -59,25 +63,29 @@ rdoc_options: []
59
63
  require_paths:
60
64
  - lib
61
65
  required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
62
67
  requirements:
63
68
  - - ">="
64
69
  - !ruby/object:Gem::Version
70
+ hash: 59
65
71
  segments:
66
72
  - 1
67
73
  - 8
68
74
  - 6
69
75
  version: 1.8.6
70
76
  required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
71
78
  requirements:
72
79
  - - ">="
73
80
  - !ruby/object:Gem::Version
81
+ hash: 3
74
82
  segments:
75
83
  - 0
76
84
  version: "0"
77
85
  requirements: []
78
86
 
79
87
  rubyforge_project: risky
80
- rubygems_version: 1.3.6
88
+ rubygems_version: 1.3.7
81
89
  signing_key:
82
90
  specification_version: 3
83
91
  summary: A Ruby ORM for the Riak distributed database.