@@ -53,32 +53,35 @@ def get_action(collection, action_name)
53
53
collection . actions . find { |action | action . name == action_name }
54
54
end
55
55
56
+ def generate_action_hooks ( )
57
+ @collections_sent . each do |collection |
58
+ collection [ 'actions' ] . each do |action |
59
+ c = get_collection ( collection [ 'name' ] )
60
+ a = get_action ( c , action [ 'name' ] )
61
+ load = !a . hooks . nil? && a . hooks . key? ( :load ) && a . hooks [ :load ] . is_a? ( Proc )
62
+ change = !a . hooks . nil? && a . hooks . key? ( :change ) && a . hooks [ :change ] . is_a? ( Hash ) ? a . hooks [ :change ] . keys : [ ]
63
+ action [ 'hooks' ] = { :load => load , :change => change }
64
+ end
65
+ end
66
+ end
67
+
56
68
def generate_apimap
57
69
create_apimap
58
70
require_lib_forest_liana
59
71
format_and_validate_smart_actions
60
72
61
73
if Rails . env . development?
62
74
@collections_sent = ForestLiana . apimap . as_json
63
-
64
- @collections_sent . each do |collection |
65
- collection [ 'actions' ] . each do |action |
66
- c = get_collection ( collection [ 'name' ] )
67
- a = get_action ( c , action [ 'name' ] )
68
- load = !a . hooks . nil? && a . hooks . key? ( :load ) && a . hooks [ :load ] . is_a? ( Proc )
69
- change = !a . hooks . nil? && a . hooks . key? ( :change ) && a . hooks [ :change ] . is_a? ( Hash ) ? a . hooks [ :change ] . keys : [ ]
70
- action [ 'hooks' ] = { :load => load , :change => change }
71
- end
72
- end
73
-
74
75
@meta_sent = ForestLiana . meta
76
+ generate_action_hooks
75
77
SchemaFileUpdater . new ( SCHEMA_FILENAME , @collections_sent , @meta_sent ) . perform ( )
76
78
else
77
79
if File . exists? ( SCHEMA_FILENAME )
78
80
begin
79
81
content = JSON . parse ( File . read ( SCHEMA_FILENAME ) )
80
82
@collections_sent = content [ 'collections' ]
81
83
@meta_sent = content [ 'meta' ]
84
+ generate_action_hooks
82
85
rescue JSON ::JSONError
83
86
FOREST_LOGGER . error "The content of .forestadmin-schema.json file is not a correct JSON."
84
87
FOREST_LOGGER . error "The schema cannot be synchronized with Forest Admin servers."
0 commit comments