metabolical 0.0.1 → 0.0.2

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.
@@ -17,6 +17,13 @@ Whenever you feel like adding a column to a table ask yourself if what you reall
17
17
  user.metas['active'] = true
18
18
  user.metas['active'].data #=> true
19
19
 
20
+ User.with_meta('active') #=> all users with some metadata keyed as 'active'
21
+ User.with_meta_data('active', true) #=> all user with metadata with key 'active' and set to true
22
+ User.without_meta('asshole') #=> all users that don't have a metadata keyed as 'asshole'.
23
+
24
+ Without_meta is an expensive query.
25
+ It needs to find all the records that match and remove them from the possible list of results.
26
+
20
27
  == Notes
21
28
 
22
29
  Metabolical will need you to run the following migration
@@ -27,4 +34,6 @@ Metabolical will need you to run the following migration
27
34
  t.string :key
28
35
  t.text :data
29
36
  t.timestamps
30
- end
37
+ end
38
+
39
+ add_index :meta_data, [:metabolized_id, :metabolized_type, :key]
@@ -6,9 +6,7 @@ module Metabolical
6
6
  klass.send method, :with_metas, :includes => [:metas]
7
7
  klass.send method, :with_meta_data, lambda{|k, v| {:joins => [:metas], :conditions => {"meta_data.key" => k, "meta_data.data" => v.to_yaml}}}
8
8
  klass.send method, :without_meta, lambda{|k|
9
- {:joins => [:metas],
10
- :conditions => ["meta_data.metabolized_id not in (?)",
11
- klass.send(:with_meta, k).all(:select => 'distinct(metabolized_id)').map(&:metabolized_id)]}
9
+ {:joins => "left join meta_data md on md.metabolized_id = #{klass.table_name}.#{klass.primary_key} and md.metabolized_type = '#{klass.to_s}' and md.key = '#{k}'", :conditions => "md.metabolized_id is null"}
12
10
  }
13
11
  end
14
12
 
@@ -18,9 +16,14 @@ module Metabolical
18
16
  scope :with_meta, lambda{|k| joins([:meta]).where({"meta_data.key" => k}) }
19
17
  scope :with_metas, includes(:meta)
20
18
  scope :with_meta_data, lambda{|k, v| joins(:meta).where("meta_data.key" => k, "meta_data.data" => v.to_yaml)}
19
+ # TODO: find a better way to define this
20
+ # Arel provides a way to specify left joins by using
21
+ # join(left).on(... syntax
22
+ scope :without_meta, lambda{|k| {:joins => "left join meta_data md on md.metabolized_id = #{klass.table_name}.#{klass.primary_key} and md.metabolized_type = '#{klass.to_s}' and md.key = '#{k}'", :conditions => "md.metabolized_id is null"}
23
+ }
21
24
  end
22
25
  end
23
26
  end
24
27
 
25
28
  end
26
- end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Metabolical
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metabolical
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Diego Scataglini
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-03 00:00:00 -04:00
18
+ date: 2011-07-09 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency