yaml_conditions 0.0.0.4 → 0.0.0.5

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/Manifest CHANGED
@@ -14,7 +14,6 @@ lib/yaml/query_builder.rb
14
14
  lib/yaml/query_builder/sql/mysql.rb
15
15
  lib/yaml/query_builder/sql/postgresql.rb
16
16
  lib/yaml_conditions.rb
17
- out.txt
18
17
  spec/ar_spec_helper.rb
19
18
  spec/cases/orms/active_record/version_2_delayed_job_spec.rb
20
19
  spec/cases/orms/active_record/version_2_spec.rb
@@ -33,6 +33,10 @@ On this last sample, the city attribute will be used to filter the objects on me
33
33
  BTW: All methods ActiveRecord::Base#{last, first, all} rely on ActiveRecord::Base#find, so we can use yaml_conditions with these methods too. As an example:
34
34
  Company.all(:yaml_conditions => { :data => { :address => { :street => '5551 LEAOPARD ST' } } }) behaves the same way as the first sample explained below.
35
35
 
36
+ Company.find(:last, :yaml_conditions => { :data => { :last_name => 'Marcelo' }, :flat_check => true}))
37
+
38
+ Also when you don't want to check the hierarchy (for best performance), you can use the option :flat_check => true. Using this, you will receive the records that have the proper key/value for the leafs of the Hash structure (and it's all handled by the database by a mix of SQL's LIKE statements).
39
+
36
40
  == delayed_job
37
41
 
38
42
  Just to give you a little background, I build this gem/plugin just to filter my YAML objects created via delayed_job plugin ;)
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'echoe'
3
3
 
4
4
  # PACKAGING ============================================================
5
5
 
6
- Echoe.new('yaml_conditions', '0.0.0.4') do |p|
6
+ Echoe.new('yaml_conditions', '0.0.0.5') do |p|
7
7
  p.description = ''
8
8
  p.url = 'http://github.com/marklazz/yaml_conditions'
9
9
  p.author = 'Marcelo Giorgi'
@@ -12,16 +12,22 @@ module Orms
12
12
  def find_with_yaml_conditions(*args)
13
13
  options = args.last.is_a?(::Hash) ? args.last : {}
14
14
  yaml_conditions = options[:yaml_conditions]
15
+ flat_check = yaml_conditions.delete(:flat_check) unless yaml_conditions.nil?
15
16
  return find_without_yaml_conditions(*args) if yaml_conditions.blank?
16
17
  __include_db_adapter_if_necessary__ if @db_adapter_included.nil?
17
18
  __include_delayedjob_adapter_if_necessary__ if defined?(Delayed::Job) && self == Delayed::Job && @delayed_adapter_included.nil?
18
19
  options = args.extract_options!
19
20
  adapted_args = args << refactor_options(options)
20
21
  selector = adapted_args.shift
21
- result = find_without_yaml_conditions(:all, *adapted_args).select do |o|
22
+ result = find_without_yaml_conditions(flat_check ? selector : :all, *adapted_args)
23
+ if flat_check.present?
24
+ result
25
+ else
26
+ result = result.select do |o|
22
27
  __check_yaml_nested_hierarchy__(o, __prepare_yaml_conditions__(yaml_conditions))
28
+ end
29
+ selector == :all ? result : result.send(selector.to_sym)
23
30
  end
24
- selector == :all ? result : result.send(selector.to_sym)
25
31
  end
26
32
 
27
33
  def refactor_options(options)
@@ -2,7 +2,7 @@ module Yaml
2
2
  module Conditions
3
3
  extend self
4
4
 
5
- VERSION = '0.0.0.4'
5
+ VERSION = '0.0.0.5'
6
6
  end
7
7
 
8
8
  class NotSerializedField
@@ -167,7 +167,7 @@ module Yaml
167
167
  end
168
168
 
169
169
  def __filter_yaml_attributes_to_check_on__(yaml_conditions)
170
- yaml_conditions.reject { |k,v| k.to_s == 'class' }
170
+ yaml_conditions.reject { |k,v| k.to_s == 'class' || k.to_s == 'flat_check' }
171
171
  end
172
172
 
173
173
  def __join_yaml_conditions__(current_conditions, conditions)
@@ -305,5 +305,68 @@ describe ::Orms::ActiveRecordVersion2 do
305
305
 
306
306
  it { should be_nil }
307
307
  end
308
+
309
+ context "More on using wildcards and nested structures" do
310
+
311
+ before do
312
+ user = User.create(:name => 'marcelo')
313
+ @some_nested_job = Delayed::Job.enqueue Delayed::PerformableMethod.new(NotificationMailer, :deliver_admin_login, [ User.find_by_name('marcelo'), { :some => { :nested => 'structure' }} ] )
314
+ end
315
+
316
+ subject { Delayed::Job.first(:yaml_conditions => @yaml_conditions) }
317
+
318
+ context 'test nested structure with proper conditions' do
319
+
320
+ before do
321
+ @yaml_conditions = { :class => Delayed::PerformableMethod, :args => [ '*', '*', { :some => { :nested => 'structure' } }] }
322
+ end
323
+
324
+ it { should == @some_nested_job }
325
+ end
326
+
327
+ context 'test nested structure with wrong method' do
328
+
329
+ before do
330
+ @yaml_conditions = { :class => Delayed::PerformableMethod, :args => [ '*', :deliver_admin_login, { :some => { :nested => 'structure' } }] }
331
+ end
332
+
333
+ it { should be_nil }
334
+ end
335
+
336
+ context 'test nested structure with wrong args' do
337
+ context 'bad string' do
338
+ before do
339
+ @yaml_conditions = { :class => Delayed::PerformableMethod, :args => [ '*', :deliver_admin_login, { :some => { :nested => 'bad_structure' } }] }
340
+ end
341
+
342
+ it { should be_nil }
343
+ end
344
+
345
+ context 'bad key' do
346
+ before do
347
+ @yaml_conditions = { :class => Delayed::PerformableMethod, :args => [ '*', :bad_symbol, { :some => { :bad_nested => 'structure' } }] }
348
+ end
349
+
350
+ it { should be_nil }
351
+ end
352
+
353
+ context 'wrong hierarchy' do
354
+ before do
355
+ @yaml_conditions = { :class => Delayed::PerformableMethod, :args => [ '*', :deliver_admin_login, { :nested => 'structure' } ] }
356
+ end
357
+
358
+ it { should be_nil }
359
+ end
360
+
361
+ context 'wrong hierarchy but with :flat_check set to true' do
362
+ before do
363
+ @yaml_conditions = { :class => Delayed::PerformableMethod, :args => [ '*', :deliver_admin_login, { :nested => 'structure' } ], :flat_check => true }
364
+ end
365
+
366
+ it { should == @some_nested_job }
367
+ end
368
+ end
369
+ end
370
+
308
371
  end
309
372
  end if defined?(Delayed::Job)
@@ -262,6 +262,14 @@ describe Orms::ActiveRecordVersion2 do
262
262
  it { should be_nil }
263
263
  end
264
264
 
265
+ context "yaml_conditions that match key/value, WRONG hierarchy BUT flat_check => true" do
266
+ before do
267
+ @yaml_conditions = { :data => { :class => 'Struct', :struct => { :handler => { :another_nested_object => { :class => 'User', :name => 'marcelo' } } } }, :flat_check => true }
268
+ end
269
+
270
+ it { should == @job }
271
+ end
272
+
265
273
  context "correct yaml_conditions but WRONG class name" do
266
274
  before do
267
275
  @yaml_conditions = { :data => { :class => 'WrongModel', :struct => { :handler => { :class => 'User', :name => 'marcelo' } } } }
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{yaml_conditions}
5
- s.version = "0.0.0.4"
5
+ s.version = "0.0.0.5"
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"]
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.email = %q{marklazz.uy@gmail.com}
13
13
  s.executables = ["console.sh"]
14
14
  s.extra_rdoc_files = ["README.rdoc", "bin/console.sh", "lib/orms/active_record.rb", "lib/orms/active_record/version2/delayed_job.rb", "lib/orms/active_record/version_2.rb", "lib/orms/active_record/version_3.rb", "lib/orms/datamapper.rb", "lib/yaml/conditions.rb", "lib/yaml/query_builder.rb", "lib/yaml/query_builder/sql/mysql.rb", "lib/yaml/query_builder/sql/postgresql.rb", "lib/yaml_conditions.rb", "tasks/yaml_conditions.rake"]
15
- s.files = ["Manifest", "README.rdoc", "Rakefile", "TESTS.rdoc", "bin/console.sh", "init.rb", "lib/orms/active_record.rb", "lib/orms/active_record/version2/delayed_job.rb", "lib/orms/active_record/version_2.rb", "lib/orms/active_record/version_3.rb", "lib/orms/datamapper.rb", "lib/yaml/conditions.rb", "lib/yaml/query_builder.rb", "lib/yaml/query_builder/sql/mysql.rb", "lib/yaml/query_builder/sql/postgresql.rb", "lib/yaml_conditions.rb", "out.txt", "spec/ar_spec_helper.rb", "spec/cases/orms/active_record/version_2_delayed_job_spec.rb", "spec/cases/orms/active_record/version_2_spec.rb", "spec/connections/mysql/connection.rb", "spec/connections/postgresql/connection.rb", "spec/datamapper_spec_helper.rb", "spec/models/job.rb", "spec/models/period.rb", "spec/models/priority.rb", "spec/models/support_classes.rb", "spec/models/user.rb", "spec/models/user_data.rb", "spec/schema.rb", "spec/spec_helper.rb", "tasks/yaml_conditions.rake", "yaml_conditions.gemspec"]
15
+ s.files = ["Manifest", "README.rdoc", "Rakefile", "TESTS.rdoc", "bin/console.sh", "init.rb", "lib/orms/active_record.rb", "lib/orms/active_record/version2/delayed_job.rb", "lib/orms/active_record/version_2.rb", "lib/orms/active_record/version_3.rb", "lib/orms/datamapper.rb", "lib/yaml/conditions.rb", "lib/yaml/query_builder.rb", "lib/yaml/query_builder/sql/mysql.rb", "lib/yaml/query_builder/sql/postgresql.rb", "lib/yaml_conditions.rb", "spec/ar_spec_helper.rb", "spec/cases/orms/active_record/version_2_delayed_job_spec.rb", "spec/cases/orms/active_record/version_2_spec.rb", "spec/connections/mysql/connection.rb", "spec/connections/postgresql/connection.rb", "spec/datamapper_spec_helper.rb", "spec/models/job.rb", "spec/models/period.rb", "spec/models/priority.rb", "spec/models/support_classes.rb", "spec/models/user.rb", "spec/models/user_data.rb", "spec/schema.rb", "spec/spec_helper.rb", "tasks/yaml_conditions.rake", "yaml_conditions.gemspec"]
16
16
  s.homepage = %q{http://github.com/marklazz/yaml_conditions}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Yaml_conditions", "--main", "README.rdoc"]
18
18
  s.require_paths = ["lib"]
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: 71
4
+ hash: 69
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
9
  - 0
10
- - 4
11
- version: 0.0.0.4
10
+ - 5
11
+ version: 0.0.0.5
12
12
  platform: ruby
13
13
  authors:
14
14
  - Marcelo Giorgi
@@ -70,7 +70,6 @@ files:
70
70
  - lib/yaml/query_builder/sql/mysql.rb
71
71
  - lib/yaml/query_builder/sql/postgresql.rb
72
72
  - lib/yaml_conditions.rb
73
- - out.txt
74
73
  - spec/ar_spec_helper.rb
75
74
  - spec/cases/orms/active_record/version_2_delayed_job_spec.rb
76
75
  - spec/cases/orms/active_record/version_2_spec.rb
data/out.txt DELETED
File without changes