fastapi 0.1.14 → 0.1.15

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fastapi.rb +66 -37
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5e54711b6986d78e68f91500ea931e04bd497027
4
- data.tar.gz: 5e321a89fc6fc363d2389e799a8249a418ca254f
3
+ metadata.gz: 0a6ce23d8deee325849253771c6e3d086fc39198
4
+ data.tar.gz: 5f19315c1ae01f124a089c67878a31106e821b57
5
5
  SHA512:
6
- metadata.gz: 09af462c7bb56a4298afbd50f65d59dc07ad92f5fc3030f05bcd62dcb5015df5f0f81ca8dc475ca965590f0ef6fd56106170b4196ae927bc330490d5368fdd67
7
- data.tar.gz: 6b5c624fb605fd6dc1916a8ea0c8a8c436bb0e4f286779a21346429f52e3ed5b20bf6bddbd146a705346a61cb3b9ebfc6158b72800c12b0da15c6d63dd1599bc
6
+ metadata.gz: 76b3a8277e2973aacd8bcb43c025cdd5feb386b86f4c0b259fcc827d24111d8ae70d49f50ebd1c672f66e844c353e69679e4df69951072d57c4ceb566f03154b
7
+ data.tar.gz: b3374e4f49364f4d5878e9cc605be36d2510a7bd5f6f8c97b3b32a9bea232baf7de099b74623f8d822d0080d9c98b5b3b9e8b87bec0a97003c6cf9e97d330242
@@ -543,7 +543,7 @@ class FastAPI
543
543
  self_obj = model.nil? ? @model : model
544
544
  self_string_table = model.nil? ? @model.to_s.tableize : '__' + model.to_s.tableize
545
545
 
546
- filters = filters.clone()
546
+ filters = filters.clone().symbolize_keys
547
547
  # if we're at the top level...
548
548
  if model.nil?
549
549
 
@@ -579,9 +579,9 @@ class FastAPI
579
579
  found_index = key.to_s.rindex('__')
580
580
  key_root = found_index.nil? ? key : key.to_s[0...found_index].to_sym
581
581
  if not self_obj.column_names.include? key_root.to_s
582
- if not model.nil? or (
583
- not @model.reflect_on_all_associations(:has_many).map(&:name).include? key_root and
584
- not @model.reflect_on_all_associations(:belongs_to).map(&:name).include? key_root
582
+ if not model.nil? or not (
583
+ @model.reflect_on_all_associations(:has_many).map(&:name).include? key_root or
584
+ @model.reflect_on_all_associations(:belongs_to).map(&:name).include? key_root
585
585
  )
586
586
  raise 'Filter "' + key.to_s + '" not supported'
587
587
  end
@@ -591,9 +591,11 @@ class FastAPI
591
591
 
592
592
  filter_array = []
593
593
  filter_has_many = {}
594
+ filter_belongs_to = {}
594
595
 
595
596
  order = nil
596
597
  order_has_many = {}
598
+ order_belongs_to = {}
597
599
 
598
600
  if filters.size > 0
599
601
 
@@ -652,52 +654,77 @@ class FastAPI
652
654
 
653
655
  end
654
656
 
655
- if model.nil? and self_obj.reflect_on_all_associations(:has_many).map(&:name).include? key
657
+ if model.nil?
656
658
 
657
- filter_result = parse_filters(value, safe, field.singularize.classify.constantize)
658
- # puts filter_result
659
- filter_has_many[key] = filter_result[:main]
660
- order_has_many[key] = filter_result[:main_order]
659
+ puts 'What the Fuck'
660
+ puts key
661
+ puts self_obj
661
662
 
662
- elsif self_obj.column_names.include? field
663
+ if self_obj.reflect_on_all_associations(:has_many).map(&:name).include? key
663
664
 
664
- if self_obj.columns_hash[field].type == :boolean
665
+ filter_result = parse_filters(value, safe, field.singularize.classify.constantize)
666
+ # puts filter_result
667
+ filter_has_many[key] = filter_result[:main]
668
+ order_has_many[key] = filter_result[:main_order]
665
669
 
666
- if !!value != value
667
- value = ({
668
- 't' => true,
669
- 'f' => false,
670
- 'true' => true,
671
- 'false' => false
672
- }[value] or true)
673
- end
670
+ elsif self_obj.reflect_on_all_associations(:belongs_to).map(&:name).include? key
674
671
 
675
- if !!value == value
672
+ filter_result = parse_filters(value, safe, field.singularize.classify.constantize)
673
+ # puts filter_result
674
+ filter_belongs_to[key] = filter_result[:main]
675
+ order_belongs_to[key] = filter_result[:main_order]
676
+
677
+ elsif self_obj.column_names.include? field
678
+
679
+ if self_obj.columns_hash[field].type == :boolean
680
+
681
+ if !!value != value
682
+
683
+ bool_lookup = {
684
+ 't' => true,
685
+ 'f' => false,
686
+ 'true' => true,
687
+ 'false' => false
688
+ }
689
+
690
+ value = value.to_s.downcase
691
+
692
+ if bool_lookup.has_key? value
693
+ value = bool_lookup[value]
694
+ else
695
+ value = true
696
+ end
676
697
 
677
- if comparator == 'is'
678
- filter_array << self_string_table + '.' + field + ' IS ' + value.to_s.upcase
679
- elsif comparator == 'not'
680
- filter_array << self_string_table + '.' + field + ' IS NOT ' + value.to_s.upcase
681
698
  end
682
699
 
683
- end
700
+ if !!value == value
684
701
 
685
- elsif value == nil and comparator != 'is_null' and comparator != 'not_null'
702
+ if comparator == 'is'
703
+ filter_array << self_string_table + '.' + field + ' IS ' + value.to_s.upcase
704
+ elsif comparator == 'not'
705
+ filter_array << self_string_table + '.' + field + ' IS NOT ' + value.to_s.upcase
706
+ end
686
707
 
687
- if comparator == 'is'
688
- filter_array << self_string_table + '.' + field + ' IS NULL'
689
- elsif comparator == 'not'
690
- filter_array << self_string_table + '.' + field + ' IS NOT NULL'
691
- end
708
+ end
709
+
710
+ elsif value == nil and comparator != 'is_null' and comparator != 'not_null'
711
+
712
+ if comparator == 'is'
713
+ filter_array << self_string_table + '.' + field + ' IS NULL'
714
+ elsif comparator == 'not'
715
+ filter_array << self_string_table + '.' + field + ' IS NOT NULL'
716
+ end
692
717
 
693
- elsif value.is_a? Range and comparator == 'is'
718
+ elsif value.is_a? Range and comparator == 'is'
694
719
 
695
- filter_array << self_string_table + '.' + field + ' >= ' + ActiveRecord::Base.connection.quote(value.first.to_s)
696
- filter_array << self_string_table + '.' + field + ' <= ' + ActiveRecord::Base.connection.quote(value.last.to_s)
720
+ filter_array << self_string_table + '.' + field + ' >= ' + ActiveRecord::Base.connection.quote(value.first.to_s)
721
+ filter_array << self_string_table + '.' + field + ' <= ' + ActiveRecord::Base.connection.quote(value.last.to_s)
697
722
 
698
- else
723
+ else
699
724
 
700
- filter_array << self_string_table + '.' + field + api_comparison(comparator, value)
725
+ filter_array << self_string_table + '.' + field + api_comparison(comparator, value)
726
+
727
+ end
701
728
 
702
729
  end
703
730
 
@@ -713,7 +740,9 @@ class FastAPI
713
740
  main: filter_array,
714
741
  main_order: order,
715
742
  has_many: filter_has_many,
716
- has_many_order: order_has_many
743
+ has_many_order: order_has_many,
744
+ belongs_to: filter_belongs_to,
745
+ belongs_to_order: order_belongs_to
717
746
  }
718
747
 
719
748
  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.14
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Horwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj