forest_liana 1.1.13 → 1.1.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a779e509b0b4b9a4e38c73e759bc4935bb40a0f6
4
- data.tar.gz: 830cfdca779bf2e564633a313aed465c9e71f8ea
3
+ metadata.gz: 9ed1df190068b491195f4ce6d96e3369a0597514
4
+ data.tar.gz: 40ed3f6fade056c021539de67edc5bbd62b48f2d
5
5
  SHA512:
6
- metadata.gz: 34d03fc25f33fcf640742a00ea89693daa29885a8bf1b37e977c4c56944bedaaabb2ebfe03050d125e390d1d12ad23a2dfd467bb2b1d1df5cc3cfa60ffa65011
7
- data.tar.gz: c8fefe895c61ec8cf80cc1117878661f96ceb1d46625e19b868cceb9dac8028fd586112524edd3704fd9e04b83195649d15629791fae9fc11b4637f3d7149744
6
+ metadata.gz: 1d2c8bd8bb71665e3db8ecbe48864d5ab0a41bc3702abd1537c8cf0c6a02bae651624f320a68ca73eca0525a38fdbbd323936d82e5b216217cba4305871efb15
7
+ data.tar.gz: f1d443cba25f22ad12d18f6430b78ad0266b720c6a4867eaf3cfbcc76cd1117bee2e65fd3f2fe5ea7949461e2b738cbe91360a53f1413eb2f8ae1612a5e7176c
@@ -28,7 +28,9 @@ module ForestLiana
28
28
  @association = @resource.reflect_on_association(
29
29
  params[:association_name])
30
30
 
31
- if @association.nil?
31
+ # Only accept "many" associations
32
+ if @association.nil? ||
33
+ [:belongs_to, :has_one].include?(@association.macro)
32
34
  render json: {status: 404}, status: :not_found
33
35
  end
34
36
  end
@@ -1,5 +1,9 @@
1
1
  module ForestLiana
2
2
  class ResourcesController < ForestLiana::ApplicationController
3
+ begin
4
+ prepend ResourcesExtensions
5
+ rescue NameError
6
+ end
3
7
 
4
8
  before_filter :find_resource
5
9
 
@@ -60,8 +64,8 @@ module ForestLiana
60
64
  @resource
61
65
  .reflect_on_all_associations
62
66
  .select do |a|
63
- [:belongs_to, :has_and_belongs_to_many].include?(a.macro) &&
64
- !a.options[:polymorphic]
67
+ [:belongs_to, :has_and_belongs_to_many, :has_one]
68
+ .include?(a.macro) && !a.options[:polymorphic]
65
69
  end
66
70
  .map {|a| a.name.to_s }
67
71
  end
@@ -10,6 +10,7 @@ module ForestLiana
10
10
  @records = search_param
11
11
  @records = filter_param
12
12
  @records = has_many_filter
13
+ @records = belongs_to_filter
13
14
 
14
15
  @records
15
16
  end
@@ -58,7 +59,7 @@ module ForestLiana
58
59
  field = field.split(':').first if field.include?(':')
59
60
  association = @resource.reflect_on_association(field.to_sym)
60
61
 
61
- association.try(:macro) === :has_many
62
+ [:has_many, :has_and_belongs_to_many].include?(association.try(:macro))
62
63
  end
63
64
 
64
65
  def has_many_filter
@@ -110,5 +111,36 @@ module ForestLiana
110
111
  .group("#{@resource.table_name}.id, #{association.table_name}.#{subfield}")
111
112
  .having("#{association.table_name}.#{subfield} #{operator} '#{value}'")
112
113
  end
114
+
115
+ def belongs_to_association?(field)
116
+ field = field.split(':').first if field.include?(':')
117
+ association = @resource.reflect_on_association(field.to_sym)
118
+ [:belongs_to, :has_one].include?(association.try(:macro))
119
+ end
120
+
121
+ def belongs_to_subfield_filter(field, value)
122
+ field, subfield = field.split(':')
123
+
124
+ association = @resource.reflect_on_association(field.to_sym)
125
+ return if association.blank?
126
+
127
+ operator, value = OperatorValueParser.parse(value)
128
+
129
+ @records = @records
130
+ .joins(field.to_sym)
131
+ .where("#{association.table_name}.#{subfield} #{operator} '#{value}'")
132
+ end
133
+
134
+ def belongs_to_filter
135
+ if @params[:filter]
136
+ @params[:filter].each do |field, value|
137
+ next unless belongs_to_association?(field)
138
+ @records = belongs_to_subfield_filter(field, value)
139
+ end
140
+ end
141
+
142
+ @records
143
+ end
144
+
113
145
  end
114
146
  end
@@ -11,7 +11,8 @@ module ForestLiana
11
11
 
12
12
  config.middleware.insert_before 0, 'Rack::Cors' do
13
13
  allow do
14
- origins '*'
14
+ origins 'http://localhost:4200', 'https://www.forestadmin.com',
15
+ 'http://www.forestadmin.com'
15
16
  resource '*', headers: :any, methods: :any
16
17
  end
17
18
  end
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.1.13"
2
+ VERSION = "1.1.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.13
4
+ version: 1.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-04 00:00:00.000000000 Z
11
+ date: 2015-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails