MuranoCLI 2.2.4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.agignore +3 -0
  3. data/.gitignore +18 -1
  4. data/.rubocop.yml +222 -0
  5. data/.trustme.sh +185 -0
  6. data/.trustme.vim +24 -0
  7. data/Gemfile +23 -4
  8. data/LICENSE.txt +1 -1
  9. data/MuranoCLI.gemspec +43 -8
  10. data/README.markdown +9 -11
  11. data/Rakefile +187 -143
  12. data/TODO.taskpaper +2 -2
  13. data/bin/murano +51 -52
  14. data/docs/basic_example.rst +436 -0
  15. data/docs/completions/murano_completion-bash +3484 -0
  16. data/docs/demo.md +32 -32
  17. data/docs/develop.rst +391 -0
  18. data/lib/MrMurano.rb +21 -7
  19. data/lib/MrMurano/Account.rb +159 -174
  20. data/lib/MrMurano/Business.rb +381 -0
  21. data/lib/MrMurano/Config-Migrate.rb +32 -26
  22. data/lib/MrMurano/Config.rb +407 -128
  23. data/lib/MrMurano/Content.rb +191 -0
  24. data/lib/MrMurano/Gateway.rb +489 -0
  25. data/lib/MrMurano/Keystore.rb +48 -0
  26. data/lib/MrMurano/Passwords.rb +103 -0
  27. data/lib/MrMurano/ProjectFile.rb +121 -79
  28. data/lib/MrMurano/ReCommander.rb +114 -10
  29. data/lib/MrMurano/Setting.rb +90 -0
  30. data/lib/MrMurano/Solution-ServiceConfig.rb +89 -45
  31. data/lib/MrMurano/Solution-Services.rb +461 -166
  32. data/lib/MrMurano/Solution-Users.rb +70 -31
  33. data/lib/MrMurano/Solution.rb +372 -13
  34. data/lib/MrMurano/SolutionId.rb +73 -0
  35. data/lib/MrMurano/SyncRoot.rb +137 -0
  36. data/lib/MrMurano/SyncUpDown.rb +594 -284
  37. data/lib/MrMurano/Webservice-Cors.rb +71 -0
  38. data/lib/MrMurano/Webservice-Endpoint.rb +234 -0
  39. data/lib/MrMurano/Webservice-File.rb +193 -0
  40. data/lib/MrMurano/Webservice.rb +51 -0
  41. data/lib/MrMurano/commands.rb +18 -15
  42. data/lib/MrMurano/commands/business.rb +300 -6
  43. data/lib/MrMurano/commands/completion-bash.erb +166 -0
  44. data/lib/MrMurano/commands/{zshcomplete.erb → completion-zsh.erb} +0 -0
  45. data/lib/MrMurano/commands/completion.rb +76 -39
  46. data/lib/MrMurano/commands/config.rb +108 -44
  47. data/lib/MrMurano/commands/content.rb +115 -72
  48. data/lib/MrMurano/commands/cors.rb +29 -14
  49. data/lib/MrMurano/commands/devices.rb +286 -0
  50. data/lib/MrMurano/commands/domain.rb +52 -12
  51. data/lib/MrMurano/commands/gb.rb +24 -9
  52. data/lib/MrMurano/commands/globals.rb +64 -0
  53. data/lib/MrMurano/commands/init.rb +377 -155
  54. data/lib/MrMurano/commands/keystore.rb +92 -82
  55. data/lib/MrMurano/commands/link.rb +300 -0
  56. data/lib/MrMurano/commands/login.rb +74 -11
  57. data/lib/MrMurano/commands/logs.rb +63 -32
  58. data/lib/MrMurano/commands/mock.rb +57 -29
  59. data/lib/MrMurano/commands/password.rb +57 -39
  60. data/lib/MrMurano/commands/postgresql.rb +127 -94
  61. data/lib/MrMurano/commands/settings.rb +203 -0
  62. data/lib/MrMurano/commands/show.rb +79 -38
  63. data/lib/MrMurano/commands/solution.rb +423 -5
  64. data/lib/MrMurano/commands/solution_picker.rb +547 -0
  65. data/lib/MrMurano/commands/status.rb +195 -61
  66. data/lib/MrMurano/commands/sync.rb +78 -39
  67. data/lib/MrMurano/commands/timeseries.rb +71 -55
  68. data/lib/MrMurano/commands/tsdb.rb +113 -87
  69. data/lib/MrMurano/commands/usage.rb +57 -15
  70. data/lib/MrMurano/hash.rb +100 -10
  71. data/lib/MrMurano/http.rb +187 -43
  72. data/lib/MrMurano/makePretty.rb +16 -14
  73. data/lib/MrMurano/optparse.rb +2178 -0
  74. data/lib/MrMurano/progress.rb +138 -0
  75. data/lib/MrMurano/schema/resource-v1.0.0.yaml +32 -0
  76. data/lib/MrMurano/template/projectFile.murano.erb +16 -13
  77. data/lib/MrMurano/verbosing.rb +166 -29
  78. data/lib/MrMurano/version.rb +30 -1
  79. data/spec/Account-Passwords_spec.rb +21 -4
  80. data/spec/Account_spec.rb +69 -146
  81. data/spec/Business_spec.rb +290 -0
  82. data/spec/ConfigFile_spec.rb +1 -0
  83. data/spec/ConfigMigrate_spec.rb +12 -8
  84. data/spec/Config_spec.rb +40 -34
  85. data/spec/Content_spec.rb +363 -0
  86. data/spec/GatewayBase_spec.rb +54 -0
  87. data/spec/GatewayDevice_spec.rb +321 -0
  88. data/spec/GatewayResource_spec.rb +266 -0
  89. data/spec/GatewaySettings_spec.rb +120 -0
  90. data/spec/Http_spec.rb +18 -8
  91. data/spec/Mock_spec.rb +2 -2
  92. data/spec/ProjectFile_spec.rb +25 -14
  93. data/spec/Setting_spec.rb +110 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +44 -5
  95. data/spec/Solution-ServiceEventHandler_spec.rb +23 -14
  96. data/spec/Solution-ServiceModules_spec.rb +47 -37
  97. data/spec/Solution-UsersRoles_spec.rb +10 -8
  98. data/spec/Solution_spec.rb +17 -8
  99. data/spec/SyncRoot_spec.rb +46 -20
  100. data/spec/SyncUpDown_spec.rb +437 -201
  101. data/spec/Verbosing_spec.rb +12 -4
  102. data/spec/{Solution-Cors_spec.rb → Webservice-Cors_spec.rb} +23 -20
  103. data/spec/{Solution-Endpoint_spec.rb → Webservice-Endpoint_spec.rb} +43 -41
  104. data/spec/{Solution-File_spec.rb → Webservice-File_spec.rb} +44 -33
  105. data/spec/Webservice-Setting_spec.rb +89 -0
  106. data/spec/_workspace.rb +4 -4
  107. data/spec/cmd_business_spec.rb +9 -4
  108. data/spec/cmd_common.rb +44 -1
  109. data/spec/cmd_content_spec.rb +43 -17
  110. data/spec/cmd_cors_spec.rb +4 -4
  111. data/spec/cmd_device_spec.rb +61 -16
  112. data/spec/cmd_domain_spec.rb +29 -6
  113. data/spec/cmd_init_spec.rb +281 -126
  114. data/spec/cmd_keystore_spec.rb +3 -3
  115. data/spec/cmd_link_spec.rb +98 -0
  116. data/spec/cmd_password_spec.rb +1 -1
  117. data/spec/cmd_setting_application_spec.rb +260 -0
  118. data/spec/cmd_setting_product_spec.rb +220 -0
  119. data/spec/cmd_status_spec.rb +223 -114
  120. data/spec/cmd_syncdown_spec.rb +115 -35
  121. data/spec/cmd_syncup_spec.rb +68 -15
  122. data/spec/cmd_usage_spec.rb +35 -8
  123. data/spec/fixtures/dumped_config +6 -4
  124. data/spec/fixtures/gateway_resource_files/resources.notyaml +12 -0
  125. data/spec/fixtures/gateway_resource_files/resources.yaml +13 -0
  126. data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +13 -0
  127. data/spec/fixtures/mrmuranorc_deleted_bob +0 -2
  128. data/spec/fixtures/product_spec_files/lightbulb.yaml +20 -13
  129. data/spec/fixtures/{syncable_content → syncable_conflict}/services/devdata.lua +1 -1
  130. data/spec/fixtures/{syncable_content → syncable_conflict}/services/timers.lua +0 -0
  131. data/spec/spec_helper.rb +5 -0
  132. metadata +262 -171
  133. data/bin/mr +0 -8
  134. data/lib/MrMurano/Product-1P-Device.rb +0 -145
  135. data/lib/MrMurano/Product-Resources.rb +0 -205
  136. data/lib/MrMurano/Product.rb +0 -358
  137. data/lib/MrMurano/Solution-Cors.rb +0 -47
  138. data/lib/MrMurano/Solution-Endpoint.rb +0 -191
  139. data/lib/MrMurano/Solution-File.rb +0 -166
  140. data/lib/MrMurano/commands/assign.rb +0 -57
  141. data/lib/MrMurano/commands/businessList.rb +0 -45
  142. data/lib/MrMurano/commands/product.rb +0 -14
  143. data/lib/MrMurano/commands/productCreate.rb +0 -39
  144. data/lib/MrMurano/commands/productDelete.rb +0 -33
  145. data/lib/MrMurano/commands/productDevice.rb +0 -87
  146. data/lib/MrMurano/commands/productDeviceIdCmds.rb +0 -89
  147. data/lib/MrMurano/commands/productList.rb +0 -45
  148. data/lib/MrMurano/commands/productWrite.rb +0 -27
  149. data/lib/MrMurano/commands/solutionCreate.rb +0 -41
  150. data/lib/MrMurano/commands/solutionDelete.rb +0 -34
  151. data/lib/MrMurano/commands/solutionList.rb +0 -45
  152. data/spec/ProductBase_spec.rb +0 -113
  153. data/spec/ProductContent_spec.rb +0 -162
  154. data/spec/ProductResources_spec.rb +0 -329
  155. data/spec/Product_1P_Device_spec.rb +0 -202
  156. data/spec/Product_1P_RPC_spec.rb +0 -175
  157. data/spec/Product_spec.rb +0 -153
  158. data/spec/Solution-ServiceDevice_spec.rb +0 -176
  159. data/spec/cmd_assign_spec.rb +0 -51
@@ -0,0 +1,48 @@
1
+ # Last Modified: 2017.08.16 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
8
+ module MrMurano
9
+ class Keystore < ServiceConfig
10
+ def initialize(sid=nil)
11
+ # FIXME/2017-07-03: Do products have a keystore service? What about other soln types?
12
+ @solntype = 'application.id'
13
+ super
14
+ @service_name = 'keystore'
15
+ end
16
+
17
+ def keyinfo
18
+ call(:info)
19
+ end
20
+
21
+ def listkeys
22
+ ret = call(:list)
23
+ ret[:keys]
24
+ end
25
+
26
+ def getkey(key)
27
+ ret = call(:get, :post, key: key)
28
+ ret[:value]
29
+ end
30
+
31
+ def setkey(key, value)
32
+ call(:set, :post, key: key, value: value)
33
+ end
34
+
35
+ def delkey(key)
36
+ call(:delete, :post, key: key)
37
+ end
38
+
39
+ def command(key, cmd, args)
40
+ call(:command, :post, key: key, command: cmd, args: args)
41
+ end
42
+
43
+ def clearall
44
+ call(:clear, :post, {})
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,103 @@
1
+ # Last Modified: 2017.08.17 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
8
+ require 'date'
9
+ require 'json'
10
+ require 'net/http'
11
+ require 'pathname'
12
+ require 'uri'
13
+ require 'yaml'
14
+ require 'MrMurano/http'
15
+ require 'MrMurano/verbosing'
16
+ require 'MrMurano/Config'
17
+ require 'MrMurano/Solution'
18
+
19
+ module MrMurano
20
+ # The Passwords class manages an end user's Murano user name and password.
21
+ class Passwords
22
+ include Verbose
23
+
24
+ def initialize(path=nil)
25
+ path = $cfg.file_at('passwords', :user) if path.nil?
26
+ path = Pathname.new(path) unless path.is_a?(Pathname)
27
+ @path = path
28
+ @data = nil
29
+ end
30
+
31
+ def load
32
+ return unless @path.exist?
33
+ @path.chmod(0o600)
34
+ @path.open('rb') do |io|
35
+ # 2017-07-01: Rubocop suggests using safe_load.
36
+ # https://ruby-doc.org/stdlib-2.1.0/libdoc/psych/rdoc/Psych.html#method-c-load
37
+ # https://ruby-doc.org/stdlib-2.1.0/libdoc/psych/rdoc/Psych.html#method-c-safe_load
38
+ # 2017-07-05: Oh, I don't think safe_load exists in Ruby 2 or 2.2...
39
+ #@data = YAML.safe_load(io)
40
+ # rubocop:disable Security/YAMLLoad
41
+ @data = YAML.load(io)
42
+ end
43
+ end
44
+
45
+ def save
46
+ if $cfg['tool.dry']
47
+ say '--dry: Not saving config'
48
+ return
49
+ end
50
+ @path.dirname.mkpath unless @path.dirname.exist?
51
+ @path.open('wb') do |io|
52
+ io << @data.to_yaml
53
+ end
54
+ @path.chmod(0o600)
55
+ end
56
+
57
+ def set(host, user, pass)
58
+ unless @data.is_a?(Hash)
59
+ @data = { host => { user => pass } }
60
+ return
61
+ end
62
+ hd = @data[host]
63
+ if hd.nil? || !hd.is_a?(Hash)
64
+ @data[host] = { user => pass }
65
+ return
66
+ end
67
+ @data[host][user] = pass
68
+ end
69
+
70
+ def get(host, user)
71
+ return ENV['MURANO_PASSWORD'] unless ENV['MURANO_PASSWORD'].to_s.empty?
72
+ unless ENV['MR_PASSWORD'].nil?
73
+ warning %(
74
+ Using deprecated environment variable, "MR_PASSWORD". Please rename to "MURANO_PASSWORD"
75
+ ).strip
76
+ return ENV['MR_PASSWORD']
77
+ end
78
+ return nil unless @data.is_a?(Hash)
79
+ return nil unless @data.key?(host)
80
+ return nil unless @data[host].is_a?(Hash)
81
+ return nil unless @data[host].key?(user)
82
+ @data[host][user]
83
+ end
84
+
85
+ ## Remove the password for a user.
86
+ def remove(host, user)
87
+ return unless @data.is_a?(Hash)
88
+ hd = @data[host]
89
+ return unless !hd.nil? && hd.is_a?(Hash)
90
+ @data[host].delete(user) if hd.key?(user)
91
+ end
92
+
93
+ ## Get all hosts and usernames. Does not return passwords.
94
+ def list
95
+ ret = {}
96
+ @data.each_pair { |key, value| ret[key] = value.keys } unless @data.nil?
97
+ ret
98
+ # MAYBE/2017-08-17:
99
+ # sort_by_name(ret)
100
+ end
101
+ end
102
+ end
103
+
@@ -1,3 +1,13 @@
1
+ # Last Modified: 2017.08.18 /coding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # Copyright © 2016-2017 Exosite LLC.
5
+ # License: MIT. See LICENSE.txt.
6
+ # vim:tw=0:ts=2:sw=2:et:ai
7
+
8
+ # 2017-07-01: This ordered list hacks around having
9
+ # individual files include all the files they need.
10
+
1
11
  require 'yaml'
2
12
  require 'json-schema'
3
13
  require 'pathname'
@@ -5,14 +15,21 @@ require 'MrMurano/verbosing'
5
15
  require 'MrMurano/Config'
6
16
  require 'MrMurano/hash'
7
17
 
18
+ # FIXME/EXPLAIN/2017-06-30: Is a project file a legacy construct?
19
+ # I believe MurCLI currently stores config in .murano/config,
20
+ # and it uses a known set of directories for storing Murano
21
+ # things. Is a solution file just a way to specify your own
22
+ # paths to things? Is there any reason to prefer using a
23
+ # solution file to not using one?
24
+
8
25
  module MrMurano
9
26
  ##
10
- # A Project File that describes details about a project that is synced into
11
- # Murano
27
+ # A Project File that describes details about a project that is
28
+ # synced into Murano.
12
29
  class ProjectFile
13
30
  include Verbose
14
31
 
15
- attr_reader :usingProjectfile, :usingSolutionfile
32
+ attr_reader :using_projectfile, :using_solutionfile
16
33
 
17
34
  # Methods that are common to various internal structs.
18
35
  module PrjStructCommonMethods
@@ -22,29 +39,29 @@ module MrMurano
22
39
  #
23
40
  # @param obj [Hash] Data to load in
24
41
  def load(obj)
25
- self.members.reject{|key| [:legacy].include? key}.each do |key|
26
- self[key] = obj[key] if obj.has_key? key
42
+ members.reject { |key| [:legacy].include? key }.each do |key|
43
+ self[key] = obj[key] if obj.key?(key)
27
44
  end
28
- self.members.select{|k| [:include, :exclude].include? k}.each do |key|
29
- self[key] = [self[key]] unless self[key].kind_of? Array
45
+ members.select { |k| %i[include exclude].include? k }.each do |key|
46
+ self[key] = [self[key]] unless self[key].nil? || self[key].is_a?(Array)
30
47
  end
31
48
  end
32
49
 
33
50
  ## Returns a sparse hash of the data in self
34
51
  # @return [Hash] Just the non-nil members of this
35
52
  def save
36
- ret={}
37
- self.members.reject{|key| [:legacy].include? key}.each do |key|
53
+ ret = {}
54
+ members.reject { |key| [:legacy].include? key }.each do |key|
38
55
  ret[key] = self[key] unless self[key].nil?
39
56
  end
40
57
  ret
41
58
  end
42
59
  end
43
60
 
44
- # The contents of this is explictily not just a nest of hashes and arrays.
61
+ # The contents of this is explicitly not just a nest of hashes and arrays.
45
62
  # To keep expectations in check, there is a set number of known keys.
46
- # This should also help by keeping the file format seperate from the internal
47
- # lookups. Hopefully, this will avoid (or at least minimize) changes to the
63
+ # This should also help by keeping the file format separate from the internal
64
+ # lookups. Hopefully, this will avoid (or at least minimize) changes to the
48
65
  # file format affecting all kinds of code.
49
66
  PrjMeta = Struct.new(:name, :summary, :description, :authors, :version, :source, :dependencies) do
50
67
  include PrjStructCommonMethods
@@ -74,33 +91,26 @@ module MrMurano
74
91
  ## Returns a sparse hash of the data in self
75
92
  # @return [Hash] Just the non-empty members of this
76
93
  def save
77
- ret={}
78
- self.members.each do |key|
94
+ ret = {}
95
+ members.each do |key|
79
96
  value = self[key].save
80
97
  ret[key] = value unless value.empty?
81
98
  end
82
99
  ret
83
100
  end
101
+
102
+ # rubocop:disable Style/AccessorMethodName: "Do not prefix reader method names with get_."
84
103
  def get_binding
85
- binding()
104
+ binding
86
105
  end
87
106
  end
88
107
 
89
- def initialize()
90
- @usingProjectfile = false
91
- @usingSolutionfile = false
92
- @prjFile = nil
93
- tname = $cfg['location.base'].basename.to_s.gsub(/[^A-Za-z0-9]/, '')
108
+ def initialize
109
+ @using_projectfile = false
110
+ @using_solutionfile = false
111
+ @prj_file = nil
94
112
  @data = PrfFile.new(
95
- PrjMeta.new(
96
- tname,
97
- "One line summary of #{tname}",
98
- "In depth description of #{tname}\n\nWith lots of details.",
99
- [$cfg['user.name']],
100
- "1.0.0",
101
- nil,
102
- nil
103
- ),
113
+ new_meta,
104
114
  PrjFiles.new,
105
115
  PrjModules.new,
106
116
  PrjEndpoints.new,
@@ -109,11 +119,29 @@ module MrMurano
109
119
  )
110
120
  end
111
121
 
122
+ def new_meta
123
+ tname = $cfg['location.base'].basename.to_s.gsub(/[^A-Za-z0-9]/, '')
124
+ PrjMeta.new(
125
+ tname,
126
+ "One line summary of #{tname}",
127
+ "In depth description of #{tname}\n\nWith lots of details.",
128
+ [$cfg['user.name']],
129
+ '1.0.0',
130
+ nil,
131
+ nil
132
+ )
133
+ end
134
+
135
+ def refresh_user_name
136
+ @data.info = new_meta
137
+ end
138
+
112
139
  # Get the current Project file
113
140
  # @return [Pathname] PAth to current project file.
114
141
  def project_file
115
- @prjFile
142
+ @prj_file
116
143
  end
144
+
117
145
  # Get a binding to the data for building the example ProjectFile
118
146
  def data_binding
119
147
  @data.get_binding
@@ -122,13 +150,13 @@ module MrMurano
122
150
  # Get a value for a key.
123
151
  # Keys are 'section.key'
124
152
  def get(key)
125
- raise "Empty key" if key.empty?
153
+ raise 'Empty key' if key.empty?
126
154
  section, ikey = key.split('.')
127
- raise "Missing dot" if ikey.nil? and section == key
128
- raise "Missing key" if ikey.nil? and section != key
155
+ raise 'Missing dot' if ikey.nil? && section == key
156
+ raise 'Missing key' if ikey.nil? && section != key
129
157
  ret = @data[section.to_sym][ikey.to_sym]
130
158
  return default_value_for(key) if ret.nil?
131
- return ret
159
+ ret
132
160
  end
133
161
  alias [] get
134
162
 
@@ -139,31 +167,46 @@ module MrMurano
139
167
  # All of these are currently stored in $cfg, but under different names.
140
168
  def default_value_for(key)
141
169
  keymap = {
170
+ # The left-side is the SolutionFile key;
171
+ # the right-side is the $cfg key.
172
+
142
173
  'assets.location' => 'location.files',
143
174
  'assets.include' => 'files.searchFor',
144
175
  'assets.exclude' => 'files.ignoring',
176
+
145
177
  'assets.default_page' => 'files.default_page',
178
+
146
179
  'modules.location' => 'location.modules',
147
180
  'modules.include' => 'modules.searchFor',
148
181
  'modules.exclude' => 'modules.ignoring',
182
+
149
183
  'routes.location' => 'location.endpoints',
150
184
  'routes.include' => 'endpoints.searchFor',
151
185
  'routes.exclude' => 'endpoints.ignoring',
186
+
152
187
  'routes.cors' => 'location.cors',
188
+
153
189
  'services.location' => 'location.eventhandlers',
154
190
  'services.include' => 'eventhandler.searchFor',
155
191
  'services.exclude' => 'eventhandler.ignoring',
156
- 'resources.location' => 'location.specs',
192
+
193
+ 'resources.location' => 'location.resources',
194
+ # EXPLAIN/2017-07-05: [lb] not finding either resources.include
195
+ # nor product.spec used anywhere.
157
196
  'resources.include' => 'product.spec',
158
197
  'resources.exclude' => 'product.ignoring',
159
198
  }.freeze
160
- needSplit = %r{.*\.(searchFor|ignoring)$}.freeze
161
- return nil unless keymap.has_key? key
162
- # *.{include,exclude} want arrays returned. But what they map to is
163
- # strings.
199
+ need_split = /.*\.(searchFor|ignoring)$/
200
+ return nil unless keymap.key? key
201
+ # *.{include,exclude} want arrays returned.
202
+ # But what they map to is strings.
164
203
  cfg_key = keymap[key]
165
- ret = ($cfg[cfg_key] or '')
166
- ret = ret.split() if cfg_key =~ needSplit
204
+ ret = ($cfg[cfg_key] || '')
205
+ # split uses $; when no delimiter is specified.
206
+ # In Ruby, $; is $FS or $FIELD_SEPARATOR.
207
+ # It defaults to nil, which splits on whitespace.
208
+ # https://ruby-doc.org/stdlib-2.3.3/libdoc/English/rdoc/English.html
209
+ ret = ret.split if cfg_key =~ need_split
167
210
  ret
168
211
  end
169
212
 
@@ -204,41 +247,42 @@ module MrMurano
204
247
  return 0 if possible.empty? # this is ok.
205
248
 
206
249
  warning "Multiple possible Project files! #{possible}" if possible.count > 1
207
- @prjFile = Pathname.new(possible.first)
250
+ @prj_file = Pathname.new(possible.first)
208
251
 
209
252
  data = nil
210
253
  begin
211
- data = YAML.load_file(@prjFile.to_s)
212
- rescue Exception => e
254
+ data = YAML.load_file(@prj_file.to_s)
255
+ #rescue Exception => e
256
+ rescue StandardError => e
213
257
  error "Load error; #{e}"
214
258
  pp e
215
259
  return -3
216
260
  end
217
- if data.nil? then
218
- error "Failed to load #{@prjFile}"
261
+ if data.nil?
262
+ error "Failed to load #{@prj_file}"
219
263
  return -2
220
264
  end
221
- unless data.kind_of?(Hash) then
222
- error "Bad format in #{@prjFile}"
265
+ unless data.is_a?(Hash)
266
+ error "Bad format in #{@prj_file}"
223
267
  return -4
224
268
  end
225
269
 
226
270
  data = Hash.transform_keys_to_symbols(data)
227
271
 
228
- # get format version; little different for older format.
229
- if @prjFile.basename.to_s == "Solutionfile.json" then
230
- fmtvers = (data[:version] or '0.2.0')
272
+ # Get format version; little different for older format.
273
+ if @prj_file.basename.to_s == 'Solutionfile.json'
274
+ fmtvers = (data[:version] || '0.2.0')
231
275
  else
232
- fmtvers = (data[:formatversion] or '1.0.0')
276
+ fmtvers = (data[:formatversion] || '1.0.0')
233
277
  end
234
278
 
235
- methodname = "load_#{fmtvers.gsub(/\./, '_')}".to_sym
279
+ methodname = "load_#{fmtvers.tr('.', '_')}".to_sym
236
280
  debug "Will try to #{methodname}"
237
- if respond_to? methodname then
281
+ if respond_to? methodname
238
282
  errorlist = __send__(methodname, data)
239
- unless errorlist.empty? then
240
- error %{Project file #{@prjFile} not valid.}
241
- errorlist.each{|er| error er}
283
+ unless errorlist.empty?
284
+ error %(Project file #{@prj_file} not valid.)
285
+ errorlist.each { |er| error er }
242
286
  return -5
243
287
  end
244
288
  else
@@ -252,21 +296,21 @@ module MrMurano
252
296
  # @param dest [Hash,Struct] Destination to save value in
253
297
  # @param dkey [String,Symbol] Key in destination to save to
254
298
  def ifset(src, skey, dest, dkey)
255
- dest[dkey] = src[skey] if src.has_key? skey
299
+ dest[dkey] = src[skey] if src.key? skey
256
300
  end
257
301
 
258
302
  # Load data in the 1.0.0 format.
259
303
  # @param data [Hash] the data to load
260
304
  # @return [Array] An array of validation errors in the data
261
305
  def load_1_0_0(data)
262
- schemaPath = Pathname.new(::File.dirname(__FILE__)) + 'schema/pf-v1.0.0.yaml'
263
- schema = YAML.load_file(schemaPath.to_s)
306
+ schema_path = Pathname.new(::File.dirname(__FILE__)) + 'schema/pf-v1.0.0.yaml'
307
+ schema = YAML.load_file(schema_path.to_s)
264
308
  v = JSON::Validator.fully_validate(schema, data)
265
309
  return v unless v.empty?
266
- @usingProjectfile = true
310
+ @using_projectfile = true
267
311
 
268
312
  @data.each_pair do |key, str|
269
- str.load(data[key]) if data.has_key? key
313
+ str.load(data[key]) if data.key? key
270
314
  end
271
315
 
272
316
  []
@@ -278,27 +322,27 @@ module MrMurano
278
322
  # @param data [Hash] the data to load
279
323
  # @return [Array] An array of validation errors in the data
280
324
  def load_0_2_0(data)
281
- schemaPath = Pathname.new(::File.dirname(__FILE__)) + 'schema/sf-v0.2.0.yaml'
282
- schema = YAML.load_file(schemaPath.to_s)
325
+ schema_path = Pathname.new(::File.dirname(__FILE__)) + 'schema/sf-v0.2.0.yaml'
326
+ schema = YAML.load_file(schema_path.to_s)
283
327
  v = JSON::Validator.fully_validate(schema, data)
284
328
  return v unless v.empty?
285
- @usingSolutionfile = true
329
+ @using_solutionfile = true
286
330
 
287
331
  ifset(data, :default_page, @data[:assets], :default_page)
288
332
  ifset(data, :file_dir, @data[:assets], :location)
289
333
 
290
334
  @data[:routes].location = '.'
291
- @data[:routes][:include] = [data[:custom_api]] if data.has_key? :custom_api
335
+ @data[:routes][:include] = [data[:custom_api]] if data.key? :custom_api
292
336
  ifset(data, :cors, @data[:routes], :cors)
293
337
 
294
- if data.has_key? :modules then
338
+ if data.key? :modules
295
339
  @data[:modules].location = '.'
296
340
  @data[:modules][:include] = data[:modules].values
297
341
  end
298
342
 
299
- if data.has_key? :event_handler then
343
+ if data.key? :event_handler
300
344
  @data[:services].location = '.'
301
- evd = data[:event_handler].values.map{|e| e.values}.flatten
345
+ evd = data[:event_handler].values.map(&:values).flatten
302
346
  @data[:services].include = evd
303
347
  @data.services.legacy = store_legacy_service_handlers(data[:event_handler])
304
348
  end
@@ -320,27 +364,27 @@ module MrMurano
320
364
  # @param data [Hash] the data to load
321
365
  # @return [Array] An array of validation errors in the data
322
366
  def load_0_3_0(data)
323
- schemaPath = Pathname.new(::File.dirname(__FILE__)) + 'schema/sf-v0.3.0.yaml'
324
- schema = YAML.load_file(schemaPath.to_s)
367
+ schema_path = Pathname.new(::File.dirname(__FILE__)) + 'schema/sf-v0.3.0.yaml'
368
+ schema = YAML.load_file(schema_path.to_s)
325
369
  v = JSON::Validator.fully_validate(schema, data)
326
370
  return v unless v.empty?
327
- @usingSolutionfile = true
371
+ @using_solutionfile = true
328
372
 
329
373
  ifset(data, :default_page, @data[:assets], :default_page)
330
374
  ifset(data, :assets, @data[:assets], :location)
331
375
 
332
376
  @data[:routes].location = '.'
333
- @data[:routes][:include] = [data[:routes]] if data.has_key? :routes
377
+ @data[:routes][:include] = [data[:routes]] if data.key? :routes
334
378
  ifset(data, :cors, @data[:routes], :cors)
335
379
 
336
- if data.has_key? :modules then
380
+ if data.key? :modules
337
381
  @data[:modules].location = '.'
338
382
  @data[:modules][:include] = data[:modules].values
339
383
  end
340
384
 
341
- if data.has_key? :services then
385
+ if data.key? :services
342
386
  @data[:services].location = '.'
343
- evd = data[:services].values.map{|e| e.values}.flatten
387
+ evd = data[:services].values.map(&:values).flatten
344
388
  @data[:services].include = evd
345
389
  @data.services.legacy = store_legacy_service_handlers(data[:services])
346
390
  end
@@ -350,7 +394,5 @@ module MrMurano
350
394
  alias load_0_3 load_0_3_0
351
395
  alias load_0 load_0_3_0
352
396
  end
353
-
354
-
355
397
  end
356
- # vim: set ai et sw=2 ts=2 :
398
+