fastapi 0.1.16 → 0.1.17
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.
- checksums.yaml +4 -4
- data/lib/fastapi.rb +131 -86
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832572badad40969dcb8f6d057c0027d1715475d
|
4
|
+
data.tar.gz: 5ee51023d5100554b269cb038ba86083abca8667
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99cb06224e1c33548b2feb9c788d30f528f66dfe3c314dcc6f0930475eff980afd7213a3d9a08b5d6813bcee6be82c8758f8e50d182569e2f28640a4c5e163ca
|
7
|
+
data.tar.gz: 7cd11d4be9b02ba8f1d261b35411e76ed129f924838f791c92af706b85b00249760bbde389a2fb7516937a6d37eccd5673c0fdb97f46bedfc83bd5faaae7175a
|
data/lib/fastapi.rb
CHANGED
@@ -536,21 +536,36 @@ class FastAPI
|
|
536
536
|
filters[:__order] = [:created_at, :DESC]
|
537
537
|
end
|
538
538
|
|
539
|
+
params = []
|
540
|
+
|
541
|
+
if filters.has_key? :__params
|
542
|
+
params = filters[:__params]
|
543
|
+
filters.delete :__params
|
544
|
+
end
|
545
|
+
|
546
|
+
if not params.is_a? Array and not params.is_a? Hash
|
547
|
+
params = [params]
|
548
|
+
end
|
539
549
|
|
540
550
|
filters.each do |key, value|
|
541
|
-
|
551
|
+
|
552
|
+
if [:__order, :__offset, :__count, :__params].include? key
|
542
553
|
next
|
543
554
|
end
|
555
|
+
|
544
556
|
found_index = key.to_s.rindex('__')
|
545
557
|
key_root = found_index.nil? ? key : key.to_s[0...found_index].to_sym
|
558
|
+
|
546
559
|
if not self_obj.column_names.include? key_root.to_s
|
547
560
|
if not model.nil? or not (
|
548
561
|
@model.reflect_on_all_associations(:has_many).map(&:name).include? key_root or
|
549
|
-
@model.reflect_on_all_associations(:belongs_to).map(&:name).include? key_root
|
562
|
+
@model.reflect_on_all_associations(:belongs_to).map(&:name).include? key_root or
|
563
|
+
@model.reflect_on_all_associations(:has_one).map(&:name).include? key_root
|
550
564
|
)
|
551
565
|
raise 'Filter "' + key.to_s + '" not supported'
|
552
566
|
end
|
553
567
|
end
|
568
|
+
|
554
569
|
end
|
555
570
|
|
556
571
|
|
@@ -562,130 +577,155 @@ class FastAPI
|
|
562
577
|
order_has_many = {}
|
563
578
|
order_belongs_to = {}
|
564
579
|
|
565
|
-
|
580
|
+
# get the order first
|
566
581
|
|
567
|
-
|
582
|
+
if filters.has_key? :__order
|
568
583
|
|
569
|
-
|
584
|
+
value = filters[:__order]
|
570
585
|
|
571
|
-
|
586
|
+
order = value.clone()
|
572
587
|
|
573
|
-
|
588
|
+
if order.is_a? String
|
589
|
+
order = order.split(',')
|
590
|
+
if order.size < 2
|
591
|
+
order << 'ASC'
|
592
|
+
end
|
593
|
+
elsif order.is_a? Array
|
594
|
+
order = order.map { |v| v.to_s }
|
595
|
+
while order.size < 2
|
596
|
+
order << ''
|
597
|
+
end
|
598
|
+
else
|
599
|
+
order = ['', '']
|
600
|
+
end
|
574
601
|
|
575
|
-
|
602
|
+
if not ['ASC', 'DESC'].include? order[1]
|
603
|
+
order[1] = 'ASC'
|
604
|
+
end
|
576
605
|
|
577
|
-
|
606
|
+
if model.nil? and @model.fastapi_custom_order.has_key? order[0].to_sym
|
578
607
|
|
579
|
-
|
580
|
-
order = order.split(',')
|
581
|
-
if order.size < 2
|
582
|
-
order << 'ASC'
|
583
|
-
end
|
584
|
-
elsif order.is_a? Array
|
585
|
-
order = order.map { |v| v.to_s }
|
586
|
-
while order.size < 2
|
587
|
-
order << ''
|
588
|
-
end
|
589
|
-
else
|
590
|
-
order = ['', '']
|
591
|
-
end
|
608
|
+
order[0] = @model.fastapi_custom_order[order[0].to_sym].gsub('self.', self_string_table + '.')
|
592
609
|
|
593
|
-
|
594
|
-
order = nil
|
595
|
-
else
|
596
|
-
order[0] = self_string_table + '.' + order[0]
|
597
|
-
if not ['ASC', 'DESC'].include? order[1]
|
598
|
-
order[1] = 'ASC'
|
599
|
-
end
|
600
|
-
order = order.join(' ')
|
601
|
-
end
|
610
|
+
if params.is_a? Array
|
602
611
|
|
603
|
-
|
612
|
+
order[0] = order[0].gsub(/\$params\[([\w\d_-]+)\]/) { ActiveRecord::Base.connection.quote(params[Regexp.last_match[1].to_i].to_s) }
|
604
613
|
|
605
614
|
else
|
606
615
|
|
607
|
-
|
616
|
+
order[0] = order[0].gsub(/\$params\[([\w\d_-]+)\]/) { ActiveRecord::Base.connection.quote(params[Regexp.last_match[1]].to_s) }
|
608
617
|
|
609
|
-
|
610
|
-
comparator = 'is'
|
611
|
-
else
|
618
|
+
end
|
612
619
|
|
613
|
-
|
614
|
-
|
620
|
+
order[0] = '(' + order[0] + ')'
|
621
|
+
order = order.join(' ')
|
615
622
|
|
616
|
-
|
617
|
-
next # skip dis bro
|
618
|
-
end
|
623
|
+
else
|
619
624
|
|
620
|
-
|
625
|
+
if not self_obj.column_names.include? order[0]
|
626
|
+
|
627
|
+
order = nil
|
628
|
+
|
629
|
+
else
|
630
|
+
|
631
|
+
order[0] = self_string_table + '.' + order[0]
|
632
|
+
order = order.join(' ')
|
621
633
|
|
622
|
-
|
634
|
+
end
|
623
635
|
|
624
|
-
|
636
|
+
end
|
625
637
|
|
626
|
-
|
627
|
-
# puts filter_result
|
628
|
-
filter_has_many[key] = filter_result[:main]
|
629
|
-
order_has_many[key] = filter_result[:main_order]
|
638
|
+
filters.delete :__order
|
630
639
|
|
631
|
-
|
640
|
+
end
|
632
641
|
|
633
|
-
|
634
|
-
# puts filter_result
|
635
|
-
filter_belongs_to[key] = filter_result[:main]
|
636
|
-
order_belongs_to[key] = filter_result[:main_order]
|
642
|
+
if filters.size > 0
|
637
643
|
|
638
|
-
|
644
|
+
filters.each do |key, value|
|
639
645
|
|
640
|
-
|
646
|
+
field = key.to_s
|
641
647
|
|
642
|
-
|
648
|
+
if field.rindex('__').nil?
|
643
649
|
|
644
|
-
|
645
|
-
't' => true,
|
646
|
-
'f' => false,
|
647
|
-
'true' => true,
|
648
|
-
'false' => false
|
649
|
-
}
|
650
|
+
comparator = 'is'
|
650
651
|
|
651
|
-
|
652
|
+
else
|
652
653
|
|
653
|
-
|
654
|
-
|
655
|
-
else
|
656
|
-
value = true
|
657
|
-
end
|
654
|
+
comparator = field[(field.rindex('__') + 2)..-1]
|
655
|
+
field = field[0...field.rindex('__')]
|
658
656
|
|
659
|
-
|
657
|
+
if not @@api_comparator_list.include? comparator
|
658
|
+
next # skip dis bro
|
659
|
+
end
|
660
|
+
|
661
|
+
end
|
662
|
+
|
663
|
+
if model.nil?
|
664
|
+
|
665
|
+
if self_obj.reflect_on_all_associations(:has_many).map(&:name).include? key
|
666
|
+
|
667
|
+
filter_result = parse_filters(value, safe, field.singularize.classify.constantize)
|
668
|
+
# puts filter_result
|
669
|
+
filter_has_many[key] = filter_result[:main]
|
670
|
+
order_has_many[key] = filter_result[:main_order]
|
671
|
+
|
672
|
+
elsif self_obj.reflect_on_all_associations(:belongs_to).map(&:name).include? key or
|
673
|
+
self_obj.reflect_on_all_associations(:has_one).map(&:name).include? key
|
674
|
+
|
675
|
+
filter_result = parse_filters(value, safe, field.singularize.classify.constantize)
|
676
|
+
# puts filter_result
|
677
|
+
filter_belongs_to[key] = filter_result[:main]
|
678
|
+
order_belongs_to[key] = filter_result[:main_order]
|
679
|
+
|
680
|
+
elsif self_obj.column_names.include? field
|
660
681
|
|
661
|
-
|
682
|
+
if self_obj.columns_hash[field].type == :boolean
|
662
683
|
|
663
|
-
|
664
|
-
filter_array << self_string_table + '.' + field + ' IS ' + value.to_s.upcase
|
665
|
-
elsif comparator == 'not'
|
666
|
-
filter_array << self_string_table + '.' + field + ' IS NOT ' + value.to_s.upcase
|
667
|
-
end
|
684
|
+
if !!value != value
|
668
685
|
|
686
|
+
bool_lookup = {
|
687
|
+
't' => true,
|
688
|
+
'f' => false,
|
689
|
+
'true' => true,
|
690
|
+
'false' => false
|
691
|
+
}
|
692
|
+
|
693
|
+
value = value.to_s.downcase
|
694
|
+
|
695
|
+
if bool_lookup.has_key? value
|
696
|
+
value = bool_lookup[value]
|
697
|
+
else
|
698
|
+
value = true
|
669
699
|
end
|
670
700
|
|
671
|
-
|
701
|
+
end
|
702
|
+
|
703
|
+
if !!value == value
|
672
704
|
|
673
705
|
if comparator == 'is'
|
674
|
-
filter_array << self_string_table + '.' + field + ' IS
|
706
|
+
filter_array << self_string_table + '.' + field + ' IS ' + value.to_s.upcase
|
675
707
|
elsif comparator == 'not'
|
676
|
-
filter_array << self_string_table + '.' + field + ' IS NOT
|
708
|
+
filter_array << self_string_table + '.' + field + ' IS NOT ' + value.to_s.upcase
|
677
709
|
end
|
678
710
|
|
679
|
-
|
711
|
+
end
|
680
712
|
|
681
|
-
|
682
|
-
filter_array << self_string_table + '.' + field + ' <= ' + ActiveRecord::Base.connection.quote(value.last.to_s)
|
713
|
+
elsif value == nil and comparator != 'is_null' and comparator != 'not_null'
|
683
714
|
|
684
|
-
|
715
|
+
if comparator == 'is'
|
716
|
+
filter_array << self_string_table + '.' + field + ' IS NULL'
|
717
|
+
elsif comparator == 'not'
|
718
|
+
filter_array << self_string_table + '.' + field + ' IS NOT NULL'
|
719
|
+
end
|
685
720
|
|
686
|
-
|
721
|
+
elsif value.is_a? Range and comparator == 'is'
|
687
722
|
|
688
|
-
|
723
|
+
filter_array << self_string_table + '.' + field + ' >= ' + ActiveRecord::Base.connection.quote(value.first.to_s)
|
724
|
+
filter_array << self_string_table + '.' + field + ' <= ' + ActiveRecord::Base.connection.quote(value.last.to_s)
|
725
|
+
|
726
|
+
else
|
727
|
+
|
728
|
+
filter_array << self_string_table + '.' + field + api_comparison(comparator, value)
|
689
729
|
|
690
730
|
end
|
691
731
|
|
@@ -720,7 +760,8 @@ class FastAPI
|
|
720
760
|
|
721
761
|
@model.fastapi_fields.each do |field|
|
722
762
|
|
723
|
-
if @model.reflect_on_all_associations(:belongs_to).map(&:name).include? field
|
763
|
+
if (@model.reflect_on_all_associations(:belongs_to).map(&:name).include? field or
|
764
|
+
@model.reflect_on_all_associations(:has_one).map(&:name).include? field)
|
724
765
|
|
725
766
|
class_name = @model.reflect_on_association(field).options[:class_name]
|
726
767
|
|
@@ -729,16 +770,20 @@ class FastAPI
|
|
729
770
|
else
|
730
771
|
model = class_name.constantize
|
731
772
|
end
|
732
|
-
|
773
|
+
|
733
774
|
model_lookup[field] = model
|
734
775
|
belongs << {model: model, alias: field}
|
735
776
|
|
736
777
|
elsif @model.reflect_on_all_associations(:has_many).map(&:name).include? field
|
778
|
+
|
737
779
|
model = field.to_s.singularize.classify.constantize
|
738
780
|
model_lookup[field] = model
|
739
781
|
has_many << model
|
782
|
+
|
740
783
|
elsif @model.column_names.include? field.to_s
|
784
|
+
|
741
785
|
fields << field
|
786
|
+
|
742
787
|
end
|
743
788
|
|
744
789
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fastapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Horwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|