doeskeyvalue 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.
data/README.rdoc CHANGED
@@ -12,68 +12,74 @@ Do the usual, of course:
12
12
 
13
13
  And add a gem dependency to your Gemfile:
14
14
 
15
- gem "doeskeyvalue", ">=0.0.1"
16
-
17
-
18
- == Example (TODO: Update this with new API)
19
-
20
- To add document_fields to your ActiveRecord object, first add a text column to your class' backing table that will hold your document content. By default, do_document_fields will expect this column to be named "document", but you can override that easily.
21
-
22
- Once you've migrated that change into your model, here's a sample of hold to add document-style blob fields to your object:
23
-
24
- class ObjectWithBlob < ActiveRecord::Base
25
-
26
- # Declare that we are using document blobs in a particular column of this object:
27
- do_document_fields
28
-
29
- # Declare the columns we are adding to our document:
30
- document_field :name, String
31
- document_field :phone, String
32
- document_field :age, Integer
33
-
34
- # Declare the document fields you'd like to track with indexes:
35
- document_index :name
36
-
37
-
38
- # If we wanted to change the name of the column in which we store the document, we'd do this:
39
- # do_document_fields :something_other_than_document. Like so:
40
-
41
- do_document_fields :settings
42
-
43
- # Changing the name of the column gives you a specifically-formatted field-definition method:
44
-
45
- settings_field :age
46
- settings_field :sex
47
- settings_field :location
48
-
49
- # This also provides a customized way to index:
50
-
51
- settings_index :location
52
-
53
- end
54
-
55
-
56
- Now, you can add and remove new fields to this object within the document as simply as adding or removing declarations of "document_field".
57
-
58
-
59
- Once you've added any indices to your model's fields, you'll want to be sure to build your supporting index tables. We use separate tables with database-level indexing to support indexed lookups of data in your document_field attributes. Build these tables by running this rake task:
60
-
61
- rake db:migrate:document_indexes
62
-
63
-
64
- Now, you can use strictly-provided finders to find your objects by their document field attributes. Considering the model we described above, you can lookup by any *indexed* field like so:
65
-
66
- obj = ObjectWithBlob.find_by_name("Charlie")
67
- => [#<ObjectWithBlob id: 412, document: {:name=>"Charlie", :phone=>"212-555-1234", :age=>34}, created_at: "2010-03-22 20:49:03", updated_at: "2010-03-22 20:49:03">]
68
-
69
- Finders are only added to document fields that are indexed. Finders also are all "find_all" lookups on equality.
70
-
71
- If you'd like to use special sub-searching within any of your document-formatted fields, you can use the hash-based search conditions. Given the "settings" document declared in the example above, we can now also do this:
72
-
73
- obj = ObjectWithBlob.find_with_settings(:location=>"San Francisco, CA")
74
- => [#<ObjectWithBlob id: 412, settings: {:age=>32, :sex=>"Female", :location=>"San Francisco, CA"}, created_at: "2010-03-22 20:49:03", updated_at: "2010-03-22 20:49:03">]
75
-
76
- It's simple.
15
+ gem "doeskeyvalue", ">=0.1.0"
16
+
17
+
18
+ == Example
19
+
20
+ Quick and simple. First, add the declaration to your ActiveRecord model:
21
+
22
+ doeskeyvalue :settings
23
+
24
+ In this invocation, "settings" is the name of TEXT or BLOB field on your model's database table. Think
25
+ of it as something you'd typically serialize, but would prefer solid accessor and finding behavior on.
26
+
27
+ To add keys to your document, using the name of the field you provided, before (in this case
28
+ "settings"), add keys individually like so:
29
+
30
+ settings_key :uid
31
+ settings_key :email
32
+ settings_key :name
33
+
34
+ This adds a uid, email, and name field to your record. You can use these fields just like regular
35
+ columns on your ActiveRecord object, but they're happily stored within your TEXT/BLOB column at the
36
+ database level. Check it out:
37
+
38
+ mod = Model.new
39
+
40
+ mod.uid = "mccolin"
41
+ => "mccolin"
42
+
43
+ mod.uid
44
+ => "mccolin"
45
+
46
+ You can see the serialized key-value structure at any time, as well. Just access your old filed:
47
+
48
+ mod.settings
49
+ => {:uid=>"mccolin"}
50
+
51
+ At this point, we have a fancy serialized Hash on our hands. What we really want to be able to do is
52
+ search for objects of type Model that have certain values. That's possible, too. First, generate the
53
+ necessary migration:
54
+
55
+ rails g doeskeyvalue
56
+
57
+ This creates db/migrate/XXX_create_key_value_index.rb for you. Migrate your database:
58
+
59
+ rake db:migrate
60
+
61
+ Now, you can declare keys that you'd like to be searchable within Model like so:
62
+
63
+ settings_index :uid
64
+ settings_index :email
65
+
66
+ Now, you've added powerful finders to your objects. As your objects are created, accessed, and updated,
67
+ metadata in your index table will be updated that allows you to search against those objects similarly
68
+ to how you'd perform lookups with a regular finder. Like so:
69
+
70
+ Model.find_all_by_uid(123)
71
+ => [#<Model:0x000001016b51a0 @settings=>{:uid=>123}>, #<Model:0x000001016b51a0 @settings=>{:uid=>123}>, ...]
72
+
73
+ Model.find_all_with_settings(:email=>"foo@bar.com")
74
+ => [#<Model:0x000001016b51a0 @settings=>{:email=>"foo@bar"}>, ...]
75
+
76
+ You can only run finds on keys for which you've added an index, but you can add and remove indexes as
77
+ necessary simply by removing the index declaration from your model.
78
+
79
+ Likewise, you can remove keys from any model by removing the key declaration. This allows you to add
80
+ and remove keys from every ActiveRecord object at will, without having to build any migrations, but you
81
+ can still reap the benefits of whatever SQL-backed relational database you've chosen for the bulk of
82
+ your application's heavy lifting.
77
83
 
78
84
 
79
85
  == Prior Versions
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/doeskeyvalue.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{doeskeyvalue}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Awexome Labs"]
@@ -8,7 +8,6 @@ module DoesKeyValue
8
8
  module Indexes
9
9
 
10
10
  def declare_index(key_value_column, key_name, opts={})
11
- puts "DOES_KEY_VALUE: Index declared: #{key_value_column}, #{key_name}, #{opts.inspect}"
12
11
  raise DoesKeyValue::NoColumnNameSpecified unless key_value_column
13
12
  raise DoesKeyValue::NoKeyNameSpecified unless key_name
14
13
  raise DoesKeyValue::KeyAndIndexOptionsMustBeHash unless opts.is_a?(Hash)
@@ -7,7 +7,6 @@ module DoesKeyValue
7
7
  module Keys
8
8
 
9
9
  def declare_key(key_value_column, key_name, opts={})
10
- puts "DOES_KEY_VALUE: Key declared: #{key_value_column}, #{key_name}, #{opts.inspect}"
11
10
  raise DoesKeyValue::NoColumnNameSpecified unless key_value_column
12
11
  raise DoesKeyValue::NoKeyNameSpecified unless key_name
13
12
  raise DoesKeyValue::KeyAndIndexOptionsMustBeHash unless opts.is_a?(Hash)
@@ -15,18 +14,14 @@ module DoesKeyValue
15
14
  # Define accessors for the key column in the AR class:
16
15
  class_eval <<-EOS
17
16
  def #{key_name}
18
- puts "DOES_KEY_VALUE: Accessor for `#{key_name}` invoked"
19
17
  return (self.send(:#{key_value_column}) || Hash.new)[:#{key_name}]
20
18
  end
21
- puts "DOES_KEY_VALUE: Key accessor `#{key_name}` declared"
22
19
 
23
20
  def #{key_name}=(value)
24
- puts "DOES_KEY_VALUE: Setter for `#{key_name}` invoked"
25
21
  key_set = self.send(:#{key_value_column}) || Hash.new
26
22
  key_set[:#{key_name}] = value
27
23
  self.send("#{key_value_column}=", key_set)
28
24
  end
29
- puts "DOES_KEY_VALUE: Key manipulator `#{key_name}=` declared"
30
25
  EOS
31
26
 
32
27
  # Check for opts[:index=>true] and if present, call declare_index
data/lib/doeskeyvalue.rb CHANGED
@@ -47,7 +47,6 @@ module ActiveRecord
47
47
  # Call this method within your class to establish key-value behavior and prep
48
48
  # the internal structure that will hold the blob
49
49
  def self.doeskeyvalue(column, opts={})
50
- puts "DOES_KEY_VALUE: Turned on for AR Column:#{column}"
51
50
  self.instance_eval do
52
51
  extend DoesKeyValue::Keys
53
52
  extend DoesKeyValue::Indexes
@@ -64,18 +63,15 @@ module ActiveRecord
64
63
 
65
64
  instance_eval <<-EOS
66
65
  def #{@@key_value_column}_key(key_name, opts={})
67
- puts "DOES_KEY_VALUE: Inside defined method #{@@key_value_column}_key"
68
66
  key_name = key_name.to_sym
69
67
  declare_key(@@key_value_column, key_name, opts)
70
68
  end
71
69
 
72
70
  def #{@@key_value_column}_index(key_name, opts={})
73
- puts "DOES_KEY_VALUE: Inside defined method #{@@key_value_column}_index"
74
71
  key_name = key_name.to_sym
75
72
  declare_index(@@key_value_column, key_name, opts)
76
73
  end
77
74
  EOS
78
- puts "DOES_KEY_VALUE: key and index methods declared"
79
75
  end
80
76
 
81
77
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: doeskeyvalue
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Awexome Labs
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- hash: -2545379118669446342
76
+ hash: 136860461958198637
77
77
  segments:
78
78
  - 0
79
79
  version: "0"