yaml_conditions 0.0.0.3 → 0.0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,6 +39,8 @@ Just to give you a little background, I build this gem/plugin just to filter my
39
39
 
40
40
  So, I added some custom magic for filtering Delayed::Job objects, like this:
41
41
 
42
+ Delayed::Job.find(:first, :yaml_conditions => { :class => Delayed::PerformableMethod, :args => [ QuoteRequest.find(435), Supplier.find(57) ] })
43
+
42
44
  Delayed::Job.first(:yaml_conditions => { :handler => { :class => Delayed::PerformableMethod, :method => :new_registration, :args => [ User.find(1), '*', '*' ] } })
43
45
 
44
46
  Delayed::Job.first(:yaml_conditions => { :handler => { :args => [ { :user => { :last_name => 'Marcelo', :address => { :city => 'Rio Negro' } } } ] } })
@@ -47,8 +49,8 @@ As you probably realize, '*' is interpreted as a wildcard.
47
49
 
48
50
  If :handler is not provided as top level key of the hash, then the hash will be wrapped inside a handler key. For example, the following queries return the same results:
49
51
 
50
- Delayed::Job.last(:yaml_conditions => { :handler => { :class => SimpleJob, :method => :new_registration }})
51
- Delayed::Job.last(:yaml_conditions => { :class => SimpleJob, :method => :new_registration })
52
+ Delayed::Job.last(:yaml_conditions => { :handler => { :class => SimpleJob, :name => 'job_name', :kind => 'some_kind' }})
53
+ Delayed::Job.last(:yaml_conditions => { :class => SimpleJob , :name => 'job_name', :kind => 'some_kind' })
52
54
 
53
55
  This wrapping magic it's only available for Delayed::Job for now.
54
56
 
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'echoe'
3
3
 
4
4
  # PACKAGING ============================================================
5
5
 
6
- Echoe.new('yaml_conditions', '0.0.0.3') do |p|
6
+ Echoe.new('yaml_conditions', '0.0.0.4') do |p|
7
7
  p.description = ''
8
8
  p.url = 'http://github.com/marklazz/yaml_conditions'
9
9
  p.author = 'Marcelo Giorgi'
@@ -1,9 +1,8 @@
1
1
  module Yaml
2
2
  module Conditions
3
3
  extend self
4
- ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/
5
4
 
6
- VERSION = '0.0.0.3'
5
+ VERSION = '0.0.0.4'
7
6
  end
8
7
 
9
8
  class NotSerializedField
@@ -1,6 +1,8 @@
1
1
  module Yaml
2
2
  module QueryBuilder
3
3
 
4
+ ParseObjectFromYaml = /\!ruby\/\w+\:([^\s]+)/
5
+
4
6
  def __include_db_adapter_if_necessary__
5
7
  adapter_name = self.connection.adapter_name
6
8
  adapter_capitalized = adapter_name.upcase[0].chr + adapter_name.downcase[1..-1]
@@ -56,7 +58,16 @@ module Yaml
56
58
  end
57
59
 
58
60
  def __check_yaml_nested_hierarchy_on_list__(value, yaml_conditions)
59
- return false if !value.is_a?(Array) || value.length != yaml_conditions.length
61
+ return false if !value.is_a?(Array)
62
+ yaml_conditions = if value.length != yaml_conditions.length
63
+ if value.length > yaml_conditions.length
64
+ yaml_conditions + (['*'] * (value.length - yaml_conditions.length))
65
+ else
66
+ yaml_conditions[0..-1+(value.length-yaml_conditions.length)]
67
+ end
68
+ else
69
+ yaml_conditions
70
+ end
60
71
  yaml_conditions.zip(value).inject(true) do |result, (cond, nested_value)|
61
72
  result &= __check_yaml_nested_hierarchy__(nested_value, cond)
62
73
  end
@@ -99,14 +110,32 @@ module Yaml
99
110
  end
100
111
 
101
112
  def __yaml_load_object_recursively__(object)
113
+ return nil if object.nil?
114
+ return object.map { |v| __yaml_load_object_recursively__(v) } if object.is_a?(Array)
115
+ if object.is_a?(Hash)
116
+ return object.keys.inject({}) do |result, k|
117
+ result[__yaml_load_object_recursively__(k).to_sym] = __yaml_load_object_recursively__(object[k])
118
+ result
119
+ end
120
+ elsif object.is_a?(Symbol)
121
+ return object
122
+ end
102
123
  yaml_object = __yaml_deserialize__(object)
103
- if yaml_object.respond_to?(:value) && yaml_object.respond_to?(:type_id) && yaml_object.type_id == 'struct'
104
- yaml_object = yaml_object.value
105
- yaml_object = yaml_object.keys.inject(yaml_object) do |yobject, key|
106
- yobject[key] = yobject[key].is_a?(String) ? __yaml_load_object_recursively__(yobject[key]) : yobject[key]
124
+ if yaml_object.is_a?(Struct) || (yaml_object.respond_to?(:value) && yaml_object.respond_to?(:type_id) && yaml_object.type_id == 'struct')
125
+ yaml_object = yaml_object.respond_to?(:value) ? yaml_object.value : yaml_object
126
+ keys = yaml_object.respond_to?(:members) ? yaml_object.members : yaml_object.keys
127
+ yaml_object = keys.inject(yaml_object) do |yobject, key|
128
+ value = yobject.respond_to?(key.to_sym) ? yobject.send(key.to_sym) : yobject[key]
129
+ yobject[key] = begin
130
+ if value.is_a?(Array) || value.is_a?(String)
131
+ __yaml_load_object_recursively__(value)
132
+ else
133
+ value
134
+ end
135
+ end
107
136
  yobject
108
137
  end
109
- yaml_object[:class] = yaml_object.class.to_s
138
+ yaml_object[:class]=(yaml_object.class.to_s) unless yaml_object.is_a?(Struct)
110
139
  yaml_object
111
140
  else
112
141
  yaml_object
@@ -10,7 +10,6 @@ rescue LoadError
10
10
  # not installed
11
11
  end
12
12
 
13
-
14
13
  describe ::Orms::ActiveRecordVersion2 do
15
14
 
16
15
  before do
@@ -28,6 +27,16 @@ describe ::Orms::ActiveRecordVersion2 do
28
27
 
29
28
  subject { Delayed::Job.first(:yaml_conditions => @yaml_conditions) }
30
29
 
30
+ context 'test filter by class' do
31
+
32
+ before do
33
+ @yaml_conditions = { :class => Delayed::PerformableMethod }
34
+ end
35
+
36
+ it { should == @job }
37
+ end
38
+
39
+
31
40
  context 'test filter by args' do
32
41
 
33
42
  before do
@@ -61,7 +61,7 @@ for adapter in %w( mysql postgresql )
61
61
  end
62
62
 
63
63
  namespace adapter do
64
- task "spec_#{adapter}" => [ "rebuild_#{adapter}_databases" ]
64
+ #task "spec_#{adapter}" => [ "rebuild_#{adapter}_databases" ]
65
65
  task :spec => "spec_#{adapter}"
66
66
  end
67
67
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{yaml_conditions}
5
- s.version = "0.0.0.3"
5
+ s.version = "0.0.0.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marcelo Giorgi"]
9
- s.date = %q{2010-11-27}
9
+ s.date = %q{2010-11-28}
10
10
  s.default_executable = %q{console.sh}
11
11
  s.description = %q{}
12
12
  s.email = %q{marklazz.uy@gmail.com}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_conditions
3
3
  version: !ruby/object:Gem::Version
4
- hash: 73
4
+ hash: 71
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
9
  - 0
10
- - 3
11
- version: 0.0.0.3
10
+ - 4
11
+ version: 0.0.0.4
12
12
  platform: ruby
13
13
  authors:
14
14
  - Marcelo Giorgi
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-27 00:00:00 -02:00
19
+ date: 2010-11-28 00:00:00 -02:00
20
20
  default_executable: console.sh
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency