simple_record 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_record.rb +18 -95
- metadata +2 -2
data/lib/simple_record.rb
CHANGED
@@ -29,7 +29,7 @@ require 'local_cache'
|
|
29
29
|
|
30
30
|
module SimpleRecord
|
31
31
|
|
32
|
-
VERSION = '1.0.
|
32
|
+
VERSION = '1.0.2'
|
33
33
|
|
34
34
|
class Base < RightAws::ActiveSdb::Base
|
35
35
|
|
@@ -625,104 +625,13 @@ This is done on getters now
|
|
625
625
|
select=false
|
626
626
|
select_attributes=[]
|
627
627
|
|
628
|
-
|
629
|
-
# Pad and Offset number attributes
|
628
|
+
# Pad and Offset number attributes
|
630
629
|
options = params[1]
|
631
630
|
# puts 'options=' + options.inspect
|
632
|
-
|
633
|
-
|
634
|
-
if !conditions.nil? && conditions.size > 1
|
635
|
-
# all after first are values
|
636
|
-
conditions[1...conditions.size] = conditions[1...conditions.size].collect { |x|
|
637
|
-
self.pad_and_offset(x)
|
638
|
-
}
|
639
|
-
end
|
640
|
-
end
|
631
|
+
convert_condition_params(options)
|
632
|
+
|
641
633
|
# puts 'after collect=' + params.inspect
|
642
|
-
=begin
|
643
|
-
|
644
|
-
|
645
|
-
params.each_with_index do |param, index|
|
646
|
-
#this is the easiest way to determine if it will be necessary to reload several rows or just one
|
647
|
-
#note that :all (or :first) is always params[0], and everything else is in a Hash in params[1]
|
648
|
-
if param==:all
|
649
|
-
all=true
|
650
|
-
end
|
651
|
-
|
652
|
-
if param.class==Hash
|
653
|
-
param.each do |key, value|
|
654
|
-
case key
|
655
|
-
when :reload;
|
656
|
-
reload=value #new option I'm adding so you can prevent reloading when it isn't necessary
|
657
|
-
when :conditions #conditions have to be reformatted to work with ActiveSDB
|
658
|
-
if value #value will sometimes be nil
|
659
|
-
query=sanitize_sql(value)#sanitize the conditions into an SQL query
|
660
|
-
query=query.gsub(/\w+\./, '') #this removes tables from the query, just a temporary measure, we need to inspect the table and alter query
|
661
|
-
#query=quote_regexp(query,/[a-z0-9._-]+/)#ActiveSDB.find needs quotes around the attributes and values
|
662
|
-
query=quote_regexp(query, /[^\s=']+/)
|
663
|
-
#next we put brackets around the entire query, and turn it into an array
|
664
|
-
#note, that these are 2 seperate things, and are both necessary for the function to work with ActiveSDB find
|
665
|
-
params[index][:conditions]= ["[#{query}]"]
|
666
|
-
end
|
667
|
-
#params[index][:conditions][0]= "[#{params[index][:conditions][0]}]"
|
668
|
-
#we then find any attributes in the query and put single quotes around them
|
669
|
-
#@@attributes.each do |attribute|
|
670
|
-
# params[index][:conditions][0]=params[index][:conditions][0].gsub(attribute.to_s,"'#{attribute.to_s}'")
|
671
|
-
#end
|
672
|
-
|
673
|
-
when :select #next we implement select functionality
|
674
|
-
if value #value will sometimes be nil
|
675
|
-
select=true
|
676
|
-
#if the selected attributes are in array for, we can assume we are good to go
|
677
|
-
if value.class==Array
|
678
|
-
select_attributes=value
|
679
|
-
else
|
680
|
-
#however if they are passed as comma seperated values in a string, we have to split it into an array.
|
681
|
-
#we remove all whitespace from the selected string, then split on comma
|
682
|
-
select_attributes=value.gsub(' ', '').split(',')
|
683
|
-
end
|
684
|
-
end
|
685
|
-
end
|
686
|
-
end
|
687
|
-
end
|
688
|
-
end
|
689
|
-
|
690
|
-
results = "scooby"
|
691
|
-
begin
|
692
|
-
results=super(*params)
|
693
|
-
if results
|
694
|
-
if reload
|
695
|
-
if select
|
696
|
-
if all
|
697
|
-
results.each do |row|
|
698
|
-
row.reload_attributes(select_attributes)
|
699
|
-
end
|
700
|
-
else
|
701
|
-
results.reload_attributes(select_attributes)
|
702
|
-
end
|
703
|
-
else
|
704
|
-
if all
|
705
|
-
results.each do |row|
|
706
|
-
row.reload
|
707
|
-
end
|
708
|
-
else
|
709
|
-
results.reload
|
710
|
-
end
|
711
|
-
end
|
712
|
-
end
|
713
|
-
end
|
714
|
-
rescue RightAws::AwsError
|
715
|
-
puts "RESCUED: " + $!
|
716
|
-
if ($!.is_a?(Hash))
|
717
|
-
puts "it's a hash..."
|
718
|
-
end
|
719
|
-
if ($!.message().index("NoSuchDomain") == nil)
|
720
|
-
raise $!
|
721
|
-
end
|
722
|
-
end
|
723
|
-
return results
|
724
634
|
|
725
|
-
=end
|
726
635
|
results = []
|
727
636
|
begin
|
728
637
|
results=super(*params)
|
@@ -737,6 +646,8 @@ This is done on getters now
|
|
737
646
|
end
|
738
647
|
|
739
648
|
def select(*params)
|
649
|
+
options = params[1]
|
650
|
+
convert_condition_params(options)
|
740
651
|
results = []
|
741
652
|
begin
|
742
653
|
results=super(*params)
|
@@ -750,6 +661,18 @@ This is done on getters now
|
|
750
661
|
return results
|
751
662
|
|
752
663
|
end
|
664
|
+
|
665
|
+
def self.convert_condition_params(options)
|
666
|
+
if !options.nil? && options.size > 0
|
667
|
+
conditions = options[:conditions]
|
668
|
+
if !conditions.nil? && conditions.size > 1
|
669
|
+
# all after first are values
|
670
|
+
conditions[1...conditions.size] = conditions[1...conditions.size].collect { |x|
|
671
|
+
self.pad_and_offset(x)
|
672
|
+
}
|
673
|
+
end
|
674
|
+
end
|
675
|
+
end
|
753
676
|
|
754
677
|
def self.cache_results(results)
|
755
678
|
if !@@cache_store.nil? && !results.nil?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Reeder
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-04-
|
12
|
+
date: 2009-04-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|