forest_liana 1.2.6 → 1.3.0

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: 0e5aaaf20833287b7bd967b29fc446819c729c6b
4
- data.tar.gz: 42dcb1bda73a88f0c989f6abbf3432c7ea687478
3
+ metadata.gz: b6d16ef5862508a2c684e836320a1b9e2f288363
4
+ data.tar.gz: 86adb63b884cf0dcb10196a3040c85101b9a0e59
5
5
  SHA512:
6
- metadata.gz: a62ec769824286587ad781b0116c59d95e56b972af8c7bd71572e87b43f5fb108ca78ca7d9078b70a6f68464fa67f58cd85a990dfcaa45960c795be99c97a8ab
7
- data.tar.gz: 55013515cf0b5f3e12f25949cbcd382c99e2cbc92b51f39fa86e99eefdb9950a7768e9b4a0c4109d758587a17329102e7716afce1c4d42996f4baadb0be6858b
6
+ metadata.gz: d5ff620aa9503c25bdf3b43ea735be9ce9727791f1896aab03c33a188ce7983c524df48c154871876fbbb6559cbea48e068690b6bd02c61dc117d9638052f347
7
+ data.tar.gz: 6f0ee7f3879475e0fcd77ef978e8be98b861799cf4f92de4e079bb4939ee75ed7a8c94a84ab618f02320f7cc34e547a0d219247a5751f0c88357eee22a7ab7a6
@@ -13,7 +13,9 @@ module ForestLiana
13
13
  extract_relationships
14
14
  extract_paperclip
15
15
  extract_carrierwave
16
+ extract_acts_as_taggable
16
17
 
18
+ @attributes.permit! if @attributes.respond_to?(:permit!)
17
19
  @attributes
18
20
  end
19
21
 
@@ -34,7 +36,7 @@ module ForestLiana
34
36
  association = @resource.reflect_on_association(name.try(:to_sym))
35
37
 
36
38
  if [:has_one, :belongs_to].include?(association.try(:macro))
37
- if data.is_a?(Hash)
39
+ if data.is_a?(Hash) && data[:id]
38
40
  @attributes[name] = association.klass.find(data[:id])
39
41
  elsif data.blank?
40
42
  @attributes[name] = nil
@@ -60,12 +62,24 @@ module ForestLiana
60
62
  return unless @resource.respond_to?(:uploaders)
61
63
 
62
64
  @params['data']['attributes'].each do |key, value|
63
- if carrierwave_attribute?(key)
65
+ if value && carrierwave_attribute?(key)
64
66
  @attributes[key] = ForestLiana::Base64StringIO.new(value)
65
67
  end
66
68
  end
67
69
  end
68
70
 
71
+ def extract_acts_as_taggable
72
+ return unless has_acts_as_taggable?
73
+
74
+ @params['data']['attributes'].each do |key, value|
75
+ if acts_as_taggable_attribute?(key)
76
+ @attributes["#{key.singularize}_list"] = value
77
+ @attributes.delete(key)
78
+ end
79
+ end
80
+
81
+ end
82
+
69
83
  def paperclip_handler?(attr)
70
84
  begin
71
85
  Paperclip.io_adapters.handler_for(attr)
@@ -82,5 +96,14 @@ module ForestLiana
82
96
  def carrierwave_attribute?(attr)
83
97
  @resource.uploaders.include?(attr.try(:to_sym))
84
98
  end
99
+
100
+ def acts_as_taggable_attribute?(attr)
101
+ @resource.acts_as_taggable.to_a.include?(attr)
102
+ end
103
+
104
+ def has_acts_as_taggable?
105
+ @resource.respond_to?(:acts_as_taggable) &&
106
+ @resource.acts_as_taggable.try(:to_a)
107
+ end
85
108
  end
86
109
  end
@@ -4,7 +4,7 @@ class ForestLiana::Model::Action
4
4
  include ActiveModel::Serialization
5
5
  extend ActiveModel::Naming
6
6
 
7
- attr_accessor :name, :endpoint, :http_method, :fields
7
+ attr_accessor :name, :endpoint, :http_method, :fields, :redirect
8
8
 
9
9
  def initialize(attributes = {})
10
10
  attributes.each do |name, value|
@@ -7,6 +7,7 @@ class ForestLiana::ActionSerializer
7
7
  attribute :http_method
8
8
  attribute :endpoint
9
9
  attribute :fields
10
+ attribute :redirect
10
11
 
11
12
  def relationship_related_link(attribute_name)
12
13
  nil
@@ -100,7 +100,7 @@ module ForestLiana
100
100
  if relationship_records.respond_to?(:each)
101
101
  ret[:href] = "/forest/#{object.class.table_name}/#{object.id}/#{attribute_name}"
102
102
  end
103
- rescue TypeError, ActiveRecord::StatementInvalid
103
+ rescue TypeError, ActiveRecord::StatementInvalid, NoMethodError
104
104
  puts "Cannot load the association #{attribute_name} on #{object.class.name} #{object.id}."
105
105
  end
106
106
  end
@@ -141,6 +141,16 @@ module ForestLiana
141
141
  end
142
142
  end
143
143
 
144
+ # ActsAsTaggable attribute
145
+ if active_record_class.respond_to?(:acts_as_taggable) &&
146
+ active_record_class.acts_as_taggable.try(:to_a)
147
+ active_record_class.acts_as_taggable.to_a.each do |key, value|
148
+ serializer.attribute(key) do |x|
149
+ object.send(key).map(&:name)
150
+ end
151
+ end
152
+ end
153
+
144
154
  SchemaUtils.associations(active_record_class).each do |a|
145
155
  serializer.send(serializer_association(a), a.name) {
146
156
  if [:has_one, :belongs_to].include?(a.macro)
@@ -8,10 +8,10 @@ module ForestLiana
8
8
  end
9
9
 
10
10
  def perform
11
- if Rails::VERSION::MAJOR == 4
12
- @record = @resource.create!(resource_params.permit!)
11
+ if @resource.method(:create).parameters.length < 2
12
+ @record = @resource.create(resource_params)
13
13
  else
14
- @record = @resource.create!(resource_params, without_protection: true)
14
+ @record = @resource.create(resource_params, without_protection: true)
15
15
  end
16
16
 
17
17
  set_has_many_relationships
@@ -10,8 +10,8 @@ module ForestLiana
10
10
  def perform
11
11
  @record = @resource.find(@params[:id])
12
12
 
13
- if Rails::VERSION::MAJOR == 4
14
- @record.update_attributes!(resource_params.permit!)
13
+ if @resource.instance_method(:update_attributes!).arity == 1
14
+ @record.update_attributes!(resource_params)
15
15
  else
16
16
  @record.update_attributes!(resource_params, without_protection: true)
17
17
  end
@@ -5,28 +5,59 @@ module ForestLiana
5
5
  end
6
6
 
7
7
  def perform
8
- @collection = ForestLiana::Model::Collection.new({
9
- name: @model.table_name,
10
- fields: []
11
- })
12
-
13
8
  add_columns
14
9
  add_associations
15
10
 
16
- @collection
11
+ # ActsAsTaggable attribute
12
+ if @model.respond_to?(:acts_as_taggable) && @model.acts_as_taggable.try(:to_a)
13
+ @model.acts_as_taggable.to_a.each do |key, value|
14
+ field = collection.fields.find {|x| x[:field] == key.to_s}
15
+
16
+ if field
17
+ field[:type] = 'String'
18
+ field[:reference] = nil
19
+ field[:inverse_of] = nil
20
+
21
+ collection.fields.delete_if do |f|
22
+ ['taggings', 'base_tags', 'tag_taggings'].include?(f[:field])
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ collection
17
29
  end
18
30
 
19
31
  private
20
32
 
33
+ def collection
34
+ @collection ||= begin
35
+ collection = ForestLiana.apimap.find do |x|
36
+ x.name.to_s == @model.table_name
37
+ end
38
+
39
+ if collection.blank?
40
+ collection = ForestLiana::Model::Collection.new({
41
+ name: @model.table_name,
42
+ fields: []
43
+ })
44
+
45
+ ForestLiana.apimap << collection
46
+ end
47
+
48
+ collection
49
+ end
50
+ end
51
+
21
52
  def add_columns
22
53
  @model.columns.each do |column|
23
- @collection.fields << get_schema_for_column(column)
54
+ collection.fields << get_schema_for_column(column)
24
55
  end
25
56
 
26
57
  # Intercom
27
58
  if ForestLiana.integrations.try(:[], :intercom)
28
59
  .try(:[], :user_collection) == @model.name
29
- @collection.fields << {
60
+ collection.fields << {
30
61
  field: :intercom_conversations,
31
62
  type: ['String'],
32
63
  reference: 'intercom_conversations.id',
@@ -35,20 +66,7 @@ module ForestLiana
35
66
  integration: 'intercom'
36
67
  }
37
68
 
38
- @collection.fields << {
39
- field: :intercom_attributes,
40
- type: 'String',
41
- reference: 'intercom_attributes.id',
42
- column: nil,
43
- is_searchable: false,
44
- integration: 'intercom'
45
- }
46
- end
47
-
48
- # Stripe
49
- if ForestLiana.integrations.try(:[], :stripe)
50
- .try(:[], :user_collection) == @model.name
51
- @collection.fields << {
69
+ collection.fields << {
52
70
  field: :stripe_payments,
53
71
  type: ['String'],
54
72
  reference: 'stripe_payments.id',
@@ -57,7 +75,7 @@ module ForestLiana
57
75
  integration: 'stripe'
58
76
  }
59
77
 
60
- @collection.fields << {
78
+ collection.fields << {
61
79
  field: :stripe_invoices,
62
80
  type: ['String'],
63
81
  reference: 'stripe_invoices.id',
@@ -66,7 +84,7 @@ module ForestLiana
66
84
  integration: 'stripe'
67
85
  }
68
86
 
69
- @collection.fields << {
87
+ collection.fields << {
70
88
  field: :stripe_cards,
71
89
  type: ['String'],
72
90
  reference: 'stripe_cards.id',
@@ -79,14 +97,19 @@ module ForestLiana
79
97
  # Paperclip url attribute
80
98
  if @model.respond_to?(:attachment_definitions)
81
99
  @model.attachment_definitions.each do |key, value|
82
- @collection.fields << { field: key, type: 'File' }
100
+ collection.fields << { field: key, type: 'File' }
101
+ end
102
+
103
+ collection.fields.delete_if do |f|
104
+ ['picture_file_name', 'picture_file_size', 'picture_content_type',
105
+ 'picture_updated_at'].include?(f[:field])
83
106
  end
84
107
  end
85
108
 
86
109
  # CarrierWave attribute
87
110
  if @model.respond_to?(:uploaders)
88
111
  @model.uploaders.each do |key, value|
89
- field = @collection.fields.find {|x| x[:field] == key.to_s}
112
+ field = collection.fields.find {|x| x[:field] == key.to_s}
90
113
  field[:type] = 'File' if field
91
114
  end
92
115
  end
@@ -95,12 +118,12 @@ module ForestLiana
95
118
  def add_associations
96
119
  SchemaUtils.associations(@model).each do |association|
97
120
  begin
98
- if schema = column_association(@collection, association)
121
+ if schema = column_association(collection, association)
99
122
  schema[:reference] = get_ref_for(association)
100
123
  schema[:field] = deforeign_key(schema[:field])
101
124
  schema[:inverseOf] = inverse_of(association)
102
125
  else
103
- @collection.fields << get_schema_for_association(association)
126
+ collection.fields << get_schema_for_association(association)
104
127
  end
105
128
  rescue => error
106
129
  puts error.inspect
@@ -6,10 +6,10 @@ module ForestLiana
6
6
  end
7
7
 
8
8
  def perform
9
- return unless @params[:jsonapis]
9
+ return unless @params[:data][:attributes][:ids]
10
10
 
11
- @params[:jsonapis].each do |jsonapi|
12
- ch = Stripe::Charge.retrieve(jsonapi[:data][:id])
11
+ @params[:data][:attributes][:ids].each do |id|
12
+ ch = Stripe::Charge.retrieve(id)
13
13
  ch.refunds.create
14
14
  end
15
15
  end
@@ -1,5 +1,8 @@
1
1
  require 'forest_liana/engine'
2
2
 
3
+ module Forest
4
+ end
5
+
3
6
  module ForestLiana
4
7
  module UserSpace
5
8
  end
@@ -54,8 +54,6 @@ More info at: https://github.com/ForestAdmin/forest-rails/releases/tag/1.2.0"
54
54
  end
55
55
  end
56
56
 
57
- Dir["#{@app.root}/app/forest/**/*.rb"].each {|file| require file }
58
-
59
57
  setup_stripe_integration if stripe_integration?
60
58
  setup_intercom_integration if intercom_integration?
61
59
  end
@@ -0,0 +1,46 @@
1
+ module ForestLiana::Collection
2
+ extend ActiveSupport::Concern
3
+
4
+ module ClassMethods
5
+ attr_accessor :collection_name
6
+ attr_accessor :is_read_only
7
+ attr_accessor :is_searchable
8
+
9
+ def collection(name, opts = {})
10
+ self.collection_name = name.to_s
11
+ self.is_read_only = opts[:read_only] || false
12
+ self.is_searchable = opts[:is_searchable] || true
13
+ end
14
+
15
+ def action(name, opts = {})
16
+ opts[:name] = name
17
+ model.actions << ForestLiana::Model::Action.new(opts)
18
+ end
19
+
20
+ def field(name, opts)
21
+ model.fields << opts.merge({ field: name })
22
+ end
23
+
24
+ private
25
+
26
+ def model
27
+ collection = ForestLiana.apimap.find do |x|
28
+ x.name.to_s == self.collection_name.try(:to_s)
29
+ end
30
+
31
+ if collection.blank?
32
+ collection = ForestLiana::Model::Collection.new({
33
+ name: self.collection_name.to_s,
34
+ is_read_only: self.is_read_only,
35
+ is_searchable: self.is_searchable,
36
+ fields: []
37
+ })
38
+
39
+ ForestLiana.apimap << collection
40
+ end
41
+
42
+ collection
43
+ end
44
+ end
45
+ end
46
+
@@ -6,6 +6,7 @@ require 'useragent'
6
6
  require 'jwt'
7
7
  require 'bcrypt'
8
8
  require_relative 'bootstraper'
9
+ require_relative 'collection'
9
10
 
10
11
  module ForestLiana
11
12
  class Engine < ::Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "1.2.6"
2
+ VERSION = "1.3.0"
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.2.6
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -160,7 +160,6 @@ files:
160
160
  - app/serializers/forest_liana/stripe_payment_serializer.rb
161
161
  - app/services/forest_liana/activity_logger.rb
162
162
  - app/services/forest_liana/allowed_users_getter.rb
163
- - app/services/forest_liana/collection.rb
164
163
  - app/services/forest_liana/has_many_getter.rb
165
164
  - app/services/forest_liana/intercom_attributes_getter.rb
166
165
  - app/services/forest_liana/intercom_conversations_getter.rb
@@ -186,6 +185,7 @@ files:
186
185
  - lib/forest_liana.rb
187
186
  - lib/forest_liana/base64_string_io.rb
188
187
  - lib/forest_liana/bootstraper.rb
188
+ - lib/forest_liana/collection.rb
189
189
  - lib/forest_liana/engine.rb
190
190
  - lib/forest_liana/version.rb
191
191
  - lib/generators/forest_liana/install_generator.rb
@@ -1,7 +0,0 @@
1
- class ForestLiana::Collection
2
-
3
- def self.add_actions(collection_name, actions)
4
- collection = ForestLiana.apimap.find {|x| x.name == collection_name}
5
- collection.actions += actions if collection
6
- end
7
- end