web-connect 0.1.7 → 0.1.8
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/netfira/web_connect/events.rb +5 -0
- data/lib/netfira/web_connect/model/record/events.rb +1 -0
- data/lib/netfira/web_connect/model/record.rb +3 -0
- data/lib/netfira/web_connect/model/relation.rb +3 -0
- data/lib/netfira/web_connect/rack_app/actions/version_8/commit/records.rb +37 -10
- data/lib/netfira/web_connect/rack_app/actions/version_8/records.rb +39 -0
- data/lib/netfira/web_connect/schema/table.rb +5 -0
- data/lib/netfira/web_connect/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bff09894e31923c611c0c8cb82f423cef9dd2b3
|
4
|
+
data.tar.gz: ce9cc08844cefd19669865fff7c19b7941278e9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14373030230ccba50232126e8a26e4c82f9e2a68e90d47e7864607bb11d187696c7f7a8bc9afab925746993e77c48e69f1bfd25afc5e88ab676f00d5a199185b
|
7
|
+
data.tar.gz: 2cf04972fcdfcd7526b90eee50528e9e5f6f9f55198ebd533e3e0cd5c6e3d25832076bab0f13b661aefc32facb87a2709d795f0cfdf60d3442ae96527ec702ee
|
@@ -8,15 +8,24 @@ module Netfira::WebConnect
|
|
8
8
|
records.each do |class_name, attribute_sets|
|
9
9
|
klass = class_for_record_type(class_name)
|
10
10
|
attribute_sets.each do |attributes|
|
11
|
-
|
11
|
+
modify_record klass, attributes
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def modify_record(klass, attributes)
|
17
|
+
record = find_record(klass, attributes)
|
18
|
+
if attributes['@delete']
|
19
|
+
delete_record record
|
20
|
+
else
|
21
|
+
update_record record, attributes
|
22
|
+
end
|
23
|
+
complete_record record
|
24
|
+
end
|
25
|
+
|
26
|
+
def update_record(record, attributes)
|
27
|
+
klass = record.class
|
28
|
+
origin_key = klass.origin_key.to_s
|
20
29
|
attributes.each do |key, value|
|
21
30
|
key = key.underscore
|
22
31
|
next if key == origin_key
|
@@ -24,12 +33,13 @@ module Netfira::WebConnect
|
|
24
33
|
request_file klass, attributes['fileName'] if record.checksum != value
|
25
34
|
next
|
26
35
|
end
|
27
|
-
record.write_with_type_casting(key.to_sym, value) or
|
36
|
+
record.write_with_type_casting(key.to_sym, value) or unknown_attribute! klass, key
|
28
37
|
end
|
29
|
-
record.save or
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
record.save or could_not_save! record
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_record(record)
|
42
|
+
record.destroy! if record.persisted?
|
33
43
|
end
|
34
44
|
|
35
45
|
def complete_record(record)
|
@@ -42,6 +52,23 @@ module Netfira::WebConnect
|
|
42
52
|
list << file_name unless list.include? file_name
|
43
53
|
end
|
44
54
|
|
55
|
+
def find_record(klass, attributes)
|
56
|
+
origin_key = klass.origin_key.to_s.camelize :lower
|
57
|
+
origin_id = attributes[origin_key]
|
58
|
+
raise BadRequest, "#{klass.name.demodulize} sent with no #{klass.origin_key}" unless origin_id
|
59
|
+
klass.find_or_initialize_by_origin_id(shop, origin_id.to_s)
|
60
|
+
end
|
61
|
+
|
62
|
+
def could_not_save!(record)
|
63
|
+
message = "#{record.class.name.demodulize} record could not be saved"
|
64
|
+
errors = record.errors.messages.map { |k, v| [k.to_s.camelize(:lower), v] }.to_h
|
65
|
+
raise BadRequest.new message, errors: errors
|
66
|
+
end
|
67
|
+
|
68
|
+
def unknown_attribute!(klass, key)
|
69
|
+
raise BadRequest, "#{klass.name.demodulize.pluralize} don't have #{key} fields"
|
70
|
+
end
|
71
|
+
|
45
72
|
end
|
46
73
|
end
|
47
74
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Netfira::WebConnect
|
2
|
+
class RackApp
|
3
|
+
module Action::Version8
|
4
|
+
class Records < Action
|
5
|
+
|
6
|
+
def call
|
7
|
+
case verb
|
8
|
+
when :delete then purge!
|
9
|
+
else raise MethodNotAllowed
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def purge!
|
16
|
+
raise NotFound unless path.count == 1 && Models.const_defined?(path.first)
|
17
|
+
klass = Models.const_get(path.first)
|
18
|
+
raise NotFound unless Class === klass && klass < Model::Record
|
19
|
+
scope = klass.where shop_id: shop.id
|
20
|
+
method = delete_handler_exists? ? :destroy_all : :delete_all
|
21
|
+
scope.__send__ method
|
22
|
+
{}
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete_handler_name
|
26
|
+
@destroy_handler_name ||= :"delete_#{path.first.underscore}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete_handler_exists?
|
30
|
+
Netfira::WebConnect.handles_event? delete_handler_name
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
require_relative 'commit/records'
|
39
|
+
require_relative 'commit/relations'
|
@@ -24,6 +24,10 @@ module Netfira::WebConnect
|
|
24
24
|
@localize ||= l10n_columns.keys.map(&:to_sym)
|
25
25
|
end
|
26
26
|
|
27
|
+
def relations
|
28
|
+
@relations = klass.related_classes
|
29
|
+
end
|
30
|
+
|
27
31
|
IGNORE_COLUMNS = %w[id shop_id created_at updated_at digest]
|
28
32
|
|
29
33
|
def columns
|
@@ -33,6 +37,7 @@ module Netfira::WebConnect
|
|
33
37
|
def as_json(options)
|
34
38
|
@json ||= {
|
35
39
|
columns: columns.map { |name, type| [name.to_s.camelize(:lower), type] }.to_h,
|
40
|
+
relations: relations.map{ |klass| klass.name.demodulize.pluralize },
|
36
41
|
singular: singular,
|
37
42
|
primaryKey: [primary_key.to_s.camelize(:lower)],
|
38
43
|
localize: l10n_columns.keys.map{ |k| k.camelize :lower }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: web-connect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil E. Pearson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/netfira/web_connect/rack_app/actions/version_8/commit/records.rb
|
213
213
|
- lib/netfira/web_connect/rack_app/actions/version_8/commit/relations.rb
|
214
214
|
- lib/netfira/web_connect/rack_app/actions/version_8/files.rb
|
215
|
+
- lib/netfira/web_connect/rack_app/actions/version_8/records.rb
|
215
216
|
- lib/netfira/web_connect/rack_app/actions/version_8/settings.rb
|
216
217
|
- lib/netfira/web_connect/rack_app/exceptions.rb
|
217
218
|
- lib/netfira/web_connect/rack_app/exceptions/http_exception.rb
|