shaf 1.6.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/iana_link_relations.csv.gz +0 -0
- data/lib/shaf.rb +6 -0
- data/lib/shaf/alps/attribute_serializer.rb +41 -0
- data/lib/shaf/alps/json_serializer.rb +50 -0
- data/lib/shaf/alps/relation_serializer.rb +70 -0
- data/lib/shaf/api_doc/link_relations.rb +77 -0
- data/lib/shaf/authenticator.rb +56 -0
- data/lib/shaf/authenticator/base.rb +161 -0
- data/lib/shaf/authenticator/basic_auth.rb +25 -0
- data/lib/shaf/authenticator/challenge.rb +32 -0
- data/lib/shaf/authenticator/parameter.rb +31 -0
- data/lib/shaf/authenticator/request.rb +17 -0
- data/lib/shaf/command/console.rb +1 -1
- data/lib/shaf/command/generate.rb +5 -2
- data/lib/shaf/command/new.rb +20 -7
- data/lib/shaf/command/templates/Gemfile.erb +1 -0
- data/{templates/config/settings.yml → lib/shaf/command/templates/config/settings.yml.erb} +1 -5
- data/lib/shaf/errors.rb +11 -0
- data/lib/shaf/extensions.rb +3 -3
- data/lib/shaf/extensions/api_routes.rb +60 -0
- data/lib/shaf/extensions/authorize.rb +11 -9
- data/lib/shaf/extensions/log.rb +1 -1
- data/lib/shaf/extensions/resource_uris.rb +139 -63
- data/lib/shaf/extensions/symbolic_routes.rb +22 -19
- data/lib/shaf/formable.rb +1 -2
- data/lib/shaf/formable/form.rb +1 -1
- data/lib/shaf/generator.rb +2 -0
- data/lib/shaf/generator/base.rb +2 -3
- data/lib/shaf/generator/controller.rb +11 -7
- data/lib/shaf/generator/doc.rb +17 -0
- data/lib/shaf/generator/forms.rb +1 -0
- data/lib/shaf/generator/helper.rb +2 -1
- data/lib/shaf/generator/migration/base.rb +7 -3
- data/lib/shaf/generator/migration/type.rb +4 -26
- data/lib/shaf/generator/migration/types.rb +45 -16
- data/lib/shaf/generator/model.rb +1 -2
- data/lib/shaf/generator/profile.rb +52 -0
- data/lib/shaf/generator/serializer.rb +38 -73
- data/lib/shaf/generator/templates/api/policy.rb.erb +2 -2
- data/lib/shaf/generator/templates/api/profile.rb.erb +16 -0
- data/lib/shaf/generator/templates/api/serializer.rb.erb +2 -2
- data/lib/shaf/generator/templates/spec/integration_spec.rb.erb +1 -2
- data/lib/shaf/generator/templates/spec/serializer_spec.rb.erb +5 -5
- data/lib/shaf/helpers.rb +4 -0
- data/lib/shaf/helpers/authentication.rb +79 -0
- data/lib/shaf/helpers/payload.rb +14 -34
- data/lib/shaf/helpers/vary.rb +8 -0
- data/lib/shaf/logger.rb +12 -0
- data/lib/shaf/parser.rb +65 -0
- data/lib/shaf/parser/base.rb +44 -0
- data/lib/shaf/parser/form_data.rb +15 -0
- data/lib/shaf/parser/json.rb +26 -0
- data/lib/shaf/profile.rb +110 -0
- data/lib/shaf/profile/attribute.rb +29 -0
- data/lib/shaf/profile/evaluator.rb +46 -0
- data/lib/shaf/profile/relation.rb +29 -0
- data/lib/shaf/profile/unique_id.rb +58 -0
- data/lib/shaf/profiles.rb +42 -0
- data/lib/shaf/profiles/shaf_basic.rb +20 -0
- data/lib/shaf/profiles/shaf_error.rb +48 -0
- data/lib/shaf/profiles/shaf_form.rb +109 -0
- data/lib/shaf/responder.rb +41 -2
- data/lib/shaf/responder/alps_json.rb +25 -0
- data/lib/shaf/responder/base.rb +20 -17
- data/lib/shaf/responder/hal.rb +65 -4
- data/lib/shaf/responder/html.rb +43 -16
- data/lib/shaf/responder/problem_json.rb +1 -1
- data/lib/shaf/serializer.rb +31 -0
- data/lib/shaf/settings.rb +25 -12
- data/lib/shaf/spec.rb +1 -0
- data/lib/shaf/spec/authenticator.rb +13 -0
- data/lib/shaf/spec/base.rb +1 -1
- data/lib/shaf/spec/http_method_utils.rb +1 -1
- data/lib/shaf/spec/integration_spec.rb +25 -13
- data/lib/shaf/spec/payload_utils.rb +2 -2
- data/lib/shaf/supported_http_methods.rb +15 -0
- data/lib/shaf/tasks/api_doc_task.rb +24 -3
- data/lib/shaf/tasks/routes_task.rb +14 -17
- data/lib/shaf/upgrade/manifest.rb +11 -2
- data/lib/shaf/upgrade/package.rb +73 -43
- data/lib/shaf/upgrade/version.rb +11 -10
- data/lib/shaf/utils.rb +19 -5
- data/lib/shaf/version.rb +3 -1
- data/lib/shaf/yard.rb +34 -0
- data/lib/shaf/yard/attribute_method_handler.rb +19 -0
- data/lib/shaf/yard/attribute_object.rb +30 -0
- data/lib/shaf/yard/base_method_handler.rb +30 -0
- data/lib/shaf/yard/link_method_handler.rb +39 -0
- data/lib/shaf/yard/link_object.rb +60 -0
- data/lib/shaf/yard/nested_attributes.rb +37 -0
- data/lib/shaf/yard/parser.rb +64 -0
- data/lib/shaf/yard/profile_method_handler.rb +51 -0
- data/lib/shaf/yard/profile_object.rb +21 -0
- data/lib/shaf/yard/resource_object.rb +55 -0
- data/lib/shaf/yard/serializer_handler.rb +27 -0
- data/templates/api/controllers/base_controller.rb +0 -10
- data/templates/api/controllers/docs_controller.rb +5 -3
- data/templates/api/controllers/root_controller.rb +7 -1
- data/templates/api/policies/base_policy.rb +2 -0
- data/templates/api/serializers/base_serializer.rb +1 -3
- data/templates/api/serializers/error_serializer.rb +1 -5
- data/templates/api/serializers/form_serializer.rb +1 -5
- data/templates/api/serializers/validation_error_serializer.rb +1 -5
- data/templates/config/bootstrap.rb +1 -2
- data/templates/config/directories.rb +52 -44
- data/templates/config/helpers.rb +1 -1
- data/templates/config/initializers.rb +52 -8
- data/templates/config/initializers/authentication.rb +18 -0
- data/templates/config/initializers/db_migrations.rb +2 -2
- data/templates/config/initializers/logging.rb +2 -2
- data/templates/spec/spec_helper.rb +2 -0
- data/upgrades/0.5.0.tar.gz +0 -0
- data/upgrades/1.0.4.tar.gz +0 -0
- data/upgrades/1.1.0.tar.gz +0 -0
- data/upgrades/2.0.0.tar.gz +0 -0
- data/yard_templates/api_doc/doc_index/html/body.erb +3 -0
- data/yard_templates/api_doc/doc_index/setup.rb +8 -0
- data/yard_templates/api_doc/html/css/api-doc.css +222 -0
- data/yard_templates/api_doc/html/favicon.ico +0 -0
- data/yard_templates/api_doc/html/js/switch_tab.js +17 -0
- data/yard_templates/api_doc/html/setup.rb +59 -0
- data/yard_templates/api_doc/layout/html/footer.erb +3 -0
- data/yard_templates/api_doc/layout/html/header.erb +7 -0
- data/yard_templates/api_doc/layout/html/layout.erb +13 -0
- data/yard_templates/api_doc/layout/setup.rb +24 -0
- data/yard_templates/api_doc/profile/html/attributes.erb +10 -0
- data/yard_templates/api_doc/profile/html/profile.erb +6 -0
- data/yard_templates/api_doc/profile/html/relations.erb +10 -0
- data/yard_templates/api_doc/profile/setup.rb +38 -0
- data/yard_templates/api_doc/profile_attribute/html/attribute.erb +23 -0
- data/yard_templates/api_doc/profile_attribute/setup.rb +21 -0
- data/yard_templates/api_doc/profile_relation/html/relation.erb +37 -0
- data/yard_templates/api_doc/profile_relation/setup.rb +41 -0
- data/yard_templates/api_doc/resource/html/attributes.erb +10 -0
- data/yard_templates/api_doc/resource/html/profile.erb +14 -0
- data/yard_templates/api_doc/resource/html/relations.erb +10 -0
- data/yard_templates/api_doc/resource/html/resource.erb +5 -0
- data/yard_templates/api_doc/resource/setup.rb +56 -0
- data/yard_templates/api_doc/resource_attribute/html/attribute.erb +23 -0
- data/yard_templates/api_doc/resource_attribute/setup.rb +20 -0
- data/yard_templates/api_doc/resource_relation/html/relation.erb +47 -0
- data/yard_templates/api_doc/resource_relation/setup.rb +80 -0
- data/yard_templates/api_doc/setup.rb +31 -0
- data/yard_templates/api_doc/sidebar/html/profile_list.erb +8 -0
- data/yard_templates/api_doc/sidebar/html/search.erb +7 -0
- data/yard_templates/api_doc/sidebar/html/serializer_list.erb +8 -0
- data/yard_templates/api_doc/sidebar/html/sidebar.erb +13 -0
- data/yard_templates/api_doc/sidebar/setup.rb +56 -0
- metadata +137 -30
- metadata.gz.sig +1 -3
- data/lib/shaf/extensions/current_user.rb +0 -48
- data/lib/shaf/responder/hal_serializable.rb +0 -64
data/lib/shaf/spec.rb
CHANGED
data/lib/shaf/spec/base.rb
CHANGED
@@ -8,13 +8,18 @@ module Shaf
|
|
8
8
|
|
9
9
|
register_spec_type self do |_desc, args|
|
10
10
|
next unless args&.is_a?(Hash)
|
11
|
-
args[:type]
|
11
|
+
args[:type].to_s == 'integration'
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
attr_accessor :__authenticated_user_id
|
17
|
+
|
18
|
+
def set_authentication
|
19
|
+
id = __authenticated_user_id
|
20
|
+
authorization = "#{Authenticator.scheme} #{id}" if id
|
21
|
+
|
22
|
+
header 'Authorization', authorization
|
18
23
|
end
|
19
24
|
|
20
25
|
def parse_response(body)
|
@@ -28,6 +33,21 @@ module Shaf
|
|
28
33
|
App.app
|
29
34
|
end
|
30
35
|
|
36
|
+
def authenticate(user)
|
37
|
+
self.__authenticated_user_id = user&.id
|
38
|
+
end
|
39
|
+
|
40
|
+
def unauthenticate
|
41
|
+
self.__authenticated_user_id = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def with_authenticated(user, &block)
|
45
|
+
authenticate(user)
|
46
|
+
yield
|
47
|
+
ensure
|
48
|
+
unauthenticate
|
49
|
+
end
|
50
|
+
|
31
51
|
def follow_rel(rel, method: nil)
|
32
52
|
assert_has_link(rel)
|
33
53
|
link = links[rel.to_sym]
|
@@ -37,14 +57,6 @@ module Shaf
|
|
37
57
|
get link[:href]
|
38
58
|
end
|
39
59
|
end
|
40
|
-
|
41
|
-
def auth_token(token)
|
42
|
-
@__integration_test_auth_token = token
|
43
|
-
end
|
44
|
-
|
45
|
-
def clear_auth_token
|
46
|
-
@__integration_test_auth_token = nil
|
47
|
-
end
|
48
60
|
end
|
49
61
|
end
|
50
62
|
end
|
@@ -29,11 +29,11 @@ module Shaf
|
|
29
29
|
last_payload[:_embedded]&.keys || []
|
30
30
|
end
|
31
31
|
|
32
|
-
def embedded(name = nil)
|
32
|
+
def embedded(name = nil, &block)
|
33
33
|
assert_has_embedded name unless name.nil?
|
34
34
|
keys = [:_embedded, name&.to_sym].compact
|
35
35
|
return last_payload.dig(*keys) unless block_given?
|
36
|
-
exec_embed_block(last_payload.dig(*keys),
|
36
|
+
exec_embed_block(last_payload.dig(*keys), block)
|
37
37
|
end
|
38
38
|
|
39
39
|
def each_embedded(name, &block)
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'shaf/api_doc/document'
|
2
|
-
require 'shaf/api_doc/comment'
|
3
|
-
|
4
1
|
module Shaf
|
5
2
|
module Tasks
|
6
3
|
class ApiDocTask
|
@@ -9,6 +6,11 @@ module Shaf
|
|
9
6
|
attr_accessor :document_class, :source_dir, :html_output_dir, :yaml_output_dir
|
10
7
|
|
11
8
|
def initialize
|
9
|
+
return show_deprecation_message if RUBY_VERSION >= '3.0.0'
|
10
|
+
|
11
|
+
require 'shaf/api_doc/document'
|
12
|
+
require 'shaf/api_doc/comment'
|
13
|
+
|
12
14
|
yield self if block_given?
|
13
15
|
validate_attributes!
|
14
16
|
@document_class ||= ApiDoc::Document
|
@@ -25,6 +27,8 @@ module Shaf
|
|
25
27
|
namespace :doc do
|
26
28
|
desc "Generate API documentation"
|
27
29
|
task :generate do
|
30
|
+
show_deprecation_message
|
31
|
+
|
28
32
|
files = Dir.glob(File.join(source_dir, "*.rb"))
|
29
33
|
files.each do |file|
|
30
34
|
read_file file do |doc|
|
@@ -47,6 +51,23 @@ module Shaf
|
|
47
51
|
end
|
48
52
|
end
|
49
53
|
|
54
|
+
def show_deprecation_message
|
55
|
+
ruby3_msg = <<~RUBY3 if RUBY_VERSION >= '3.0.0'
|
56
|
+
|
57
|
+
Due to errors with the Redcarpet gem it's not possible to use this deprecated rake task with Ruby >= 3.0.0
|
58
|
+
If you need to continue with this task please use an older version of Ruby.
|
59
|
+
RUBY3
|
60
|
+
|
61
|
+
puts <<~MSG
|
62
|
+
This way of generating documentation is DEPRECATED.#{ruby3_msg}
|
63
|
+
|
64
|
+
Please move the documentation comments into profiles instead and run:
|
65
|
+
shaf generate doc
|
66
|
+
See https://github.com/sammyhenningsson/shaf/blob/main/doc/DOCUMENTATION.md for more info
|
67
|
+
|
68
|
+
MSG
|
69
|
+
end
|
70
|
+
|
50
71
|
def read_file(file)
|
51
72
|
doc = document_class.new
|
52
73
|
comment = ApiDoc::Comment.new
|
@@ -1,29 +1,26 @@
|
|
1
1
|
module Shaf
|
2
2
|
module Tasks
|
3
3
|
class RoutesTask
|
4
|
-
|
4
|
+
extend Rake::DSL
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
require 'config/database'
|
6
|
+
desc 'List path helpers'
|
7
|
+
task :routes do
|
8
|
+
require 'shaf/utils'
|
9
|
+
require 'config/database'
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
extend Shaf::Utils
|
12
|
+
bootstrap
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
Shaf::ApiRoutes::Registry.controllers.each do |controller|
|
15
|
+
puts "\n#{controller}:"
|
16
|
+
Shaf::ApiRoutes::Registry.routes_for(controller) do |methods, template, symbol|
|
17
|
+
puts format(
|
18
|
+
' %-50<symbol>s%-30<methods>s%<template>s',
|
19
|
+
{symbol: symbol, methods: methods.join(' | '), template: template}
|
20
|
+
)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
end
|
26
|
-
|
27
|
-
RoutesTask.new
|
28
25
|
end
|
29
26
|
end
|
@@ -12,6 +12,7 @@ module Shaf
|
|
12
12
|
@files[:add] = params[:add] || {}
|
13
13
|
@files[:drop] = (params[:drop] || []).map { |d| Regexp.new(d) }
|
14
14
|
@files[:regexp] = build_patterns(params[:substitutes])
|
15
|
+
@files[:messages] = params[:messages] || []
|
15
16
|
end
|
16
17
|
|
17
18
|
def patches
|
@@ -30,6 +31,10 @@ module Shaf
|
|
30
31
|
files[:regexp]
|
31
32
|
end
|
32
33
|
|
34
|
+
def messages
|
35
|
+
files[:messages]
|
36
|
+
end
|
37
|
+
|
33
38
|
def patches_for(file)
|
34
39
|
patches.select { |_, pattern| file =~ pattern }.keys
|
35
40
|
end
|
@@ -47,7 +52,8 @@ module Shaf
|
|
47
52
|
additions: additions.size,
|
48
53
|
removals: removals.size,
|
49
54
|
patches: patches.size,
|
50
|
-
regexps: regexps.size
|
55
|
+
regexps: regexps.size,
|
56
|
+
messages: messages.size
|
51
57
|
}
|
52
58
|
end
|
53
59
|
|
@@ -55,7 +61,8 @@ module Shaf
|
|
55
61
|
"Add: #{additions.size}, " \
|
56
62
|
"Del: #{removals.size}, " \
|
57
63
|
"Patch: #{patches.size}, " \
|
58
|
-
"Regexp: #{regexps.size}"
|
64
|
+
"Regexp: #{regexps.size}, " \
|
65
|
+
"Messages: #{messages.size}"
|
59
66
|
end
|
60
67
|
|
61
68
|
private
|
@@ -82,3 +89,5 @@ end
|
|
82
89
|
# - api/policies/base_policy.rb
|
83
90
|
# substitutes:
|
84
91
|
# d3b07384d113edec49eaa6238ad5ff00: api/models/.*.rb
|
92
|
+
# messages:
|
93
|
+
# - b1946ac92492d2347c6235b4d2611184
|
data/lib/shaf/upgrade/package.rb
CHANGED
@@ -6,6 +6,9 @@ require 'open3'
|
|
6
6
|
require 'fileutils'
|
7
7
|
require 'tempfile'
|
8
8
|
require 'yaml'
|
9
|
+
require 'file_transactions'
|
10
|
+
|
11
|
+
FT = FileTransactions
|
9
12
|
|
10
13
|
module Shaf
|
11
14
|
module Upgrade
|
@@ -23,8 +26,6 @@ module Shaf
|
|
23
26
|
MANIFEST_FILENAME = 'manifest'.freeze
|
24
27
|
IGNORE_FILE_PATTERNS = [/.rej\z/, /.orig\z/]
|
25
28
|
|
26
|
-
attr_reader :version
|
27
|
-
|
28
29
|
class << self
|
29
30
|
def all
|
30
31
|
target_versions.map(&method(:new))
|
@@ -53,6 +54,8 @@ module Shaf
|
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
attr_reader :version, :manifest
|
58
|
+
|
56
59
|
def initialize(version, manifest = nil, files = {})
|
57
60
|
@version = Version.new(version)
|
58
61
|
@manifest = manifest
|
@@ -77,25 +80,32 @@ module Shaf
|
|
77
80
|
end
|
78
81
|
|
79
82
|
def apply(dir = nil)
|
80
|
-
puts "Applying changes for version #{version}"
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
puts "\n ## Applying changes for Shaf version: #{version} ##"
|
84
|
+
|
85
|
+
FT.transaction do
|
86
|
+
result = [
|
87
|
+
apply_patches(dir),
|
88
|
+
apply_drops(dir),
|
89
|
+
apply_additions,
|
90
|
+
apply_substitutes(dir),
|
91
|
+
print_messages,
|
92
|
+
]
|
93
|
+
raise UpgradeError, 'Upgrade failed' unless result.all?
|
94
|
+
end
|
95
|
+
|
96
|
+
true
|
87
97
|
end
|
88
98
|
|
89
99
|
def to_s
|
90
|
-
str = "Shaf::Upgrade::Package for version #{
|
91
|
-
return str if
|
92
|
-
"#{str} (#{
|
100
|
+
str = "Shaf::Upgrade::Package for version #{version}"
|
101
|
+
return str if manifest.nil?
|
102
|
+
"#{str} (#{manifest.stats_str})"
|
93
103
|
end
|
94
104
|
|
95
105
|
private
|
96
106
|
|
97
107
|
def tarball
|
98
|
-
file = File.join(UPGRADE_FILES_PATH, "#{
|
108
|
+
file = File.join(UPGRADE_FILES_PATH, "#{version}.tar.gz")
|
99
109
|
return file if File.exist? file
|
100
110
|
raise VersionNotFoundError
|
101
111
|
end
|
@@ -114,24 +124,25 @@ module Shaf
|
|
114
124
|
def parse_manifest(content)
|
115
125
|
hash = YAML.safe_load(content)
|
116
126
|
@manifest = Manifest.new(
|
117
|
-
target_version: hash[
|
118
|
-
patches: hash[
|
119
|
-
add: hash[
|
120
|
-
drop: hash[
|
121
|
-
substitutes: hash[
|
127
|
+
target_version: hash['target_version'],
|
128
|
+
patches: hash['patches'],
|
129
|
+
add: hash['add'],
|
130
|
+
drop: hash['drop'],
|
131
|
+
substitutes: hash['substitutes'],
|
132
|
+
messages: hash['messages']
|
122
133
|
)
|
123
134
|
end
|
124
135
|
|
125
136
|
def validate
|
126
|
-
raise ManifestNotFoundError unless
|
127
|
-
raise VersionConflictError unless
|
137
|
+
raise ManifestNotFoundError unless manifest
|
138
|
+
raise VersionConflictError unless version == manifest.target_version
|
128
139
|
|
129
140
|
from_file = @files.keys.to_set
|
130
141
|
|
131
|
-
manifest_patches =
|
142
|
+
manifest_patches = manifest.patches.keys.to_set
|
132
143
|
raise MissingFileError if from_file < manifest_patches
|
133
144
|
|
134
|
-
to_add =
|
145
|
+
to_add = manifest.additions.keys.to_set
|
135
146
|
raise MissingFileError if from_file < to_add
|
136
147
|
|
137
148
|
@files.each do |md5, content|
|
@@ -156,7 +167,7 @@ module Shaf
|
|
156
167
|
|
157
168
|
def apply_patches(dir = nil)
|
158
169
|
files_in(dir).map do |file|
|
159
|
-
|
170
|
+
manifest.patches_for(file).map do |name|
|
160
171
|
patch = @files[name]
|
161
172
|
apply_patch(file, patch)
|
162
173
|
end.all?
|
@@ -164,25 +175,29 @@ module Shaf
|
|
164
175
|
end
|
165
176
|
|
166
177
|
def apply_patch(file, patch)
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
178
|
+
result = nil
|
179
|
+
|
180
|
+
FT::ChangeFileCommand.execute(file) do
|
181
|
+
Open3.popen3('patch', file) do |i, o, e, t|
|
182
|
+
i.write patch
|
183
|
+
i.close
|
184
|
+
puts o.read
|
185
|
+
err = e.read
|
186
|
+
puts err unless err.empty?
|
187
|
+
result = t.value.success?
|
188
|
+
end
|
176
189
|
end
|
190
|
+
|
191
|
+
STDERR.puts "Failed to apply patch for: #{file}\n" unless result
|
192
|
+
result
|
177
193
|
end
|
178
194
|
|
179
195
|
def apply_additions
|
180
|
-
puts '' unless
|
181
|
-
|
196
|
+
puts '' unless manifest.additions.empty?
|
197
|
+
manifest.additions.all? do |chksum, filename|
|
182
198
|
content = @files[chksum]
|
183
|
-
FileUtils.mkdir_p File.dirname(filename)
|
184
199
|
puts "adding file: #{filename}"
|
185
|
-
|
200
|
+
FT::CreateFileCommand.execute(filename) { content }
|
186
201
|
true
|
187
202
|
rescue StandardError => e
|
188
203
|
STDERR.puts "Failed to add '#{filename}': #{e.message}\n"
|
@@ -191,11 +206,11 @@ module Shaf
|
|
191
206
|
end
|
192
207
|
|
193
208
|
def apply_drops(dir = nil)
|
194
|
-
puts '' unless
|
209
|
+
puts '' unless manifest.removals.empty?
|
195
210
|
files_in(dir).all? do |file|
|
196
|
-
next true unless
|
211
|
+
next true unless manifest.drop?(file)
|
197
212
|
puts "removing file: #{file}"
|
198
|
-
|
213
|
+
FT::DeleteFileCommand.execute file
|
199
214
|
true
|
200
215
|
rescue StandardError => e
|
201
216
|
STDERR.puts "Failed to unlink '#{file}': #{e.message}\n"
|
@@ -204,9 +219,9 @@ module Shaf
|
|
204
219
|
end
|
205
220
|
|
206
221
|
def apply_substitutes(dir = nil)
|
207
|
-
puts '' unless
|
222
|
+
puts '' unless manifest.regexps.empty?
|
208
223
|
files_in(dir).map do |file|
|
209
|
-
|
224
|
+
manifest.regexps_for(file).map do |name|
|
210
225
|
params = YAML.safe_load(@files[name])
|
211
226
|
params.transform_keys!(&:to_sym)
|
212
227
|
apply_substitute(file, params)
|
@@ -220,14 +235,29 @@ module Shaf
|
|
220
235
|
pattern = Regexp.new(params[:pattern])
|
221
236
|
replacement = params[:replace]
|
222
237
|
|
238
|
+
changed = false
|
223
239
|
tmp = Tempfile.open do |new_file|
|
224
240
|
File.readlines(file).each do |line|
|
225
|
-
|
241
|
+
changed = line.gsub!(pattern, replacement) || changed
|
242
|
+
new_file << line
|
226
243
|
end
|
227
244
|
new_file
|
228
245
|
end
|
229
246
|
|
230
|
-
|
247
|
+
return true unless changed
|
248
|
+
|
249
|
+
puts "modifying file: #{file}"
|
250
|
+
FT::MoveFileCommand.new(from: tmp.path, to: file).execute
|
251
|
+
true
|
252
|
+
end
|
253
|
+
|
254
|
+
def print_messages
|
255
|
+
manifest.messages.each do |chksum|
|
256
|
+
message = @files[chksum]
|
257
|
+
puts "\n#{message}"
|
258
|
+
end
|
259
|
+
|
260
|
+
true
|
231
261
|
end
|
232
262
|
end
|
233
263
|
end
|