lws 6.1.0 → 6.1.1

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: 2eb1ec948cd52f1f5c3610ac4c3fc04d0ee1c711
4
- data.tar.gz: 6368649a24fa9016db6e9e0ca52b77528ad83df2
3
+ metadata.gz: 208979361cc45a960b3e244066fdbc66379585d8
4
+ data.tar.gz: f1745c97f3315d1a33d23d8e0e5dd760c7e09822
5
5
  SHA512:
6
- metadata.gz: b669df0b60760d421f95d4994ff01d554758a40d54767982eb00705cbd988e2a10503200bd1eda281e94ddc3127bc303ede13c75c719e2c9575d0c9b1fd2a3cf
7
- data.tar.gz: 0fd2381ff359b7be8e30c13622d663ccec20ab30e89404cb52127c29f2cb25a950deba303e04bfe6a9fe8a39d75a6385f0358b92630296599bd12d3bb46a64c8
6
+ metadata.gz: 203e6d4dca711def56ff2305e206334540a04d5d481cc6ed6c92d3a57a1f4a9e4ecc3149eba5b5c99a0c8b7218b4758a4ac36a48cf3107b5795efabe8593717c
7
+ data.tar.gz: f271a3e7dea0da2c2e791fe3d85df6d8cdbcccd231baf0ecd03ac65df38408436d6bde759cfa568e01b9d86e418b11f103e5bc4f664028623bbb4d57b3b8df5c
data/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ Up until v6.1.0, we used the standard Gem version numbering starting at v0.0.1.
4
4
  From v6.1.0 on the version will follow the API version of LWS in the major/minor
5
5
  part of te version.
6
6
 
7
+ ## v6.1.1
8
+
9
+ * Support a global and user-specific config file for LWS console
10
+ * Use a separate history and specific prompt for LWS console
11
+ * Small documentation fixes
12
+ * Speed up the tests
13
+
7
14
  ## v6.1.0
8
15
 
9
16
  * Switch to LWS/LeftClick platform release versions
data/bin/lwsconsole CHANGED
@@ -10,6 +10,10 @@ require "optparse"
10
10
  require "pp"
11
11
  require "pry"
12
12
 
13
+ # Defaults
14
+ GLOBAL_CONFIG_FILE = "/etc/LeftClick/lws.yml"
15
+ USER_CONFIG_FILE = "#{ENV['HOME']}/.config/LeftClick/lws.yml"
16
+
13
17
  # Parse the command-line arguments
14
18
  PROG_NAME = File.basename($0)
15
19
  @options = {}
@@ -24,6 +28,9 @@ EOB
24
28
  opts.on("-a", "--app=APP-NAME", "switch to a specific app") do |app|
25
29
  @options[:app] = app
26
30
  end
31
+ opts.on("-c", "--config=CFGFILE", "use a specific configuration file") do |cfg_file|
32
+ @options[:cfg_file] = cfg_file
33
+ end
27
34
  opts.on("-d", "--[no-]debug", "show HTTP and JSON debug information") do |debug|
28
35
  @options[:debug] = debug
29
36
  end
@@ -76,6 +83,15 @@ begin
76
83
  config.http_debug = @options[:debug]
77
84
  config.json_debug = @options[:debug]
78
85
  config.logger = logger
86
+
87
+ if @options[:cfg_file]
88
+ cfg_file = @options[:cfg_file]
89
+ raise "config file does not exist: #{cfg_file}" unless File.exist? cfg_file
90
+ config.load_config_file(cfg_file)
91
+ else
92
+ config.load_config_file(GLOBAL_CONFIG_FILE)
93
+ config.load_config_file(USER_CONFIG_FILE)
94
+ end
79
95
  end
80
96
  if @options[:app]
81
97
  @app_module = LWS.app_module(@options[:app].downcase)
@@ -114,5 +130,10 @@ def reload!
114
130
  LWS.load_app_modules
115
131
  end
116
132
 
133
+ # Set up Pry
134
+ FileUtils.mkdir_p("#{ENV['HOME']}/.local/share/LeftClick")
135
+ Pry.config.history.file = "#{ENV['HOME']}/.local/share/LeftClick/lws_history"
136
+ Pry.config.prompt_name = PROG_NAME
137
+
117
138
  # Use the LWS module or the selected app module as the default namespace
118
139
  (@app_module || LWS).pry
@@ -1454,7 +1454,8 @@ module LWS::DigitalSignage
1454
1454
  attribute :from_version_id
1455
1455
 
1456
1456
  # @!attribute log
1457
- # @return [String] the log of the player OS package version change
1457
+ # @return [String, nil] the log of the player OS package version change
1458
+ # (can be +nil+ if {#to_version} is +nil+)
1458
1459
  attribute :log
1459
1460
 
1460
1461
  # @!attribute package
data/lib/lws/config.rb CHANGED
@@ -19,6 +19,9 @@ module LWS
19
19
  # @note Either the API token or API token middleware needs to be
20
20
  # configured for the library to work properly!
21
21
  class Config < Hashie::Dash
22
+ # The list of properties that can be set using a config file.
23
+ VALID_FILE_PROPERTIES = [:api_token, :endpoints, :http_debug, :http_debug_headers, :json_debug]
24
+
22
25
  #@!attribute api_token
23
26
  # @return [String, nil] the API token necessary to gain access
24
27
  property :api_token
@@ -64,6 +67,73 @@ module LWS
64
67
  # @return [String] the path to a directory with stubbing fixtures
65
68
  # (setting this enables the default stubs)
66
69
  property :stubbing
70
+
71
+ # Supplements the configuration with settings from a config file.
72
+
73
+ # The configuration file has a section per environment that indicates
74
+ # per property what to use if it is unset.
75
+ #
76
+ # Note that this is only done for a specific subset of of properties.
77
+ # See {VALID_FILE_PROPERTIES} for this subset!
78
+ #
79
+ # @example A simple configuration that sets the API token per environment
80
+ # production:
81
+ # api_token: "my-prod-api-token"
82
+ #
83
+ # development:
84
+ # api_token: "my-dev-api-token"
85
+ #
86
+ # The configuration file can optionally have a "default" section with
87
+ # an environment key that selects the default environment (unless
88
+ # overriden by the +LC_LWS_ENV+ environment variable.
89
+ #
90
+ # @example A elaborate configuration that sets the development environment as default, enables debugging and overrides an endpoint
91
+ # default:
92
+ # environment: "development"
93
+ #
94
+ # production:
95
+ # api_token: "my-prod-api-token"
96
+ # http_debug: false
97
+ # json_debug: false
98
+ #
99
+ # development:
100
+ # api_token: "my-dev-api-token"
101
+ # endpoints:
102
+ # maps: http://maps.leftclick.cloud
103
+ # http_debug: true
104
+ # json_debug: true
105
+ #
106
+ # @return [Boolean] whether the config file was used
107
+ def load_config_file(config_file)
108
+ return false unless File.exist? config_file
109
+ config_data = YAML.load_file(config_file)
110
+ environment = ENV["LC_LWS_ENV"] ||
111
+ config_data.dig("default", "environment") ||
112
+ self.environment
113
+ self.environment = environment.to_sym
114
+ config = config_data[environment.to_s] || {}
115
+
116
+ config.each_pair do |key, value|
117
+ unless VALID_FILE_PROPERTIES.include? key.to_sym
118
+ raise "encountered an invalid config property \"#{key}\" " +
119
+ "in config file #{config_file}!"
120
+ end
121
+
122
+ case key
123
+ when "endpoints"
124
+ if self.endpoints.empty?
125
+ self.endpoints = value.inject({}) do |h, (k, v)|
126
+ h[k.to_sym] = v
127
+ h
128
+ end
129
+ end
130
+ else
131
+ self[key.to_sym] = value unless self[key.to_sym]
132
+ end
133
+ end
134
+ true
135
+ end
136
+
67
137
  end
68
138
 
69
139
  end
data/lib/lws/version.rb CHANGED
@@ -13,6 +13,6 @@ module LWS
13
13
 
14
14
  # The LWS library version.
15
15
  # @note The major and minor version parts match the LWS API version!
16
- VERSION = '6.1.0'
16
+ VERSION = '6.1.1'
17
17
 
18
18
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ default: {}
@@ -0,0 +1,4 @@
1
+ ---
2
+ development:
3
+ endpoints:
4
+ maps: http://maps.leftclick.cloud
@@ -0,0 +1,15 @@
1
+ ---
2
+ default:
3
+ environment: development
4
+
5
+ development:
6
+ api_token: "dev-token"
7
+ endpoints:
8
+ maps: "http://maps.leftclick.cloud"
9
+ http_debug: true
10
+ http_debug_headers: true
11
+ json_debug: true
12
+
13
+ production:
14
+ http_debug: false
15
+ json_debug: false
@@ -0,0 +1,3 @@
1
+ ---
2
+ development:
3
+ foo: bar
@@ -0,0 +1,3 @@
1
+ ---
2
+ default:
3
+ environment: production
@@ -0,0 +1,3 @@
1
+ ---
2
+ development:
3
+ api_token: "dev-token"
@@ -16,7 +16,7 @@ class TestPresenceLocation < MiniTest::Test
16
16
  include LWS::Presence
17
17
 
18
18
  def setup
19
- @location = Location.all.first
19
+ @location = Location.find(1)
20
20
  end
21
21
 
22
22
  def test_valid
@@ -38,7 +38,7 @@ class TestPresencePerson < MiniTest::Test
38
38
  include LWS::Presence
39
39
 
40
40
  def setup
41
- @person = Person.all.first
41
+ @person = Person.find(1)
42
42
  end
43
43
 
44
44
  def test_valid
data/test/setup_test.rb CHANGED
@@ -13,6 +13,10 @@ require "test_helper"
13
13
 
14
14
  class TestSetup < MiniTest::Test
15
15
 
16
+ def setup
17
+ @test_config_dir = File.expand_path("../config", __FILE__)
18
+ end
19
+
16
20
  def teardown
17
21
  # Restore the configuration
18
22
  reconfigure
@@ -65,4 +69,50 @@ class TestSetup < MiniTest::Test
65
69
  end
66
70
  end
67
71
 
72
+ def test_load_config_files
73
+ orig_config = LWS.config.dup
74
+
75
+ reconfigure do |config|
76
+ assert config.load_config_file(File.join(@test_config_dir, "empty.yml"))
77
+ end
78
+ assert_equal LWS.config, orig_config
79
+
80
+ reconfigure do |config|
81
+ refute config.load_config_file(File.join(@test_config_dir, "does_not_exist.yml"))
82
+ end
83
+
84
+ reconfigure do |config|
85
+ config.api_token = nil
86
+ assert config.load_config_file(File.join(@test_config_dir, "tokens.yml"))
87
+ end
88
+ assert_equal LWS.config.api_token, "dev-token"
89
+
90
+ reconfigure do |config|
91
+ assert config.load_config_file(File.join(@test_config_dir, "switch_env.yml"))
92
+ end
93
+ assert_equal LWS.config.environment, :production
94
+
95
+ reconfigure do |config|
96
+ assert config.load_config_file(File.join(@test_config_dir, "endpoints.yml"))
97
+ end
98
+ assert_equal LWS.config.endpoints, { maps: "http://maps.leftclick.cloud" }
99
+
100
+ assert_raises do
101
+ reconfigure do |config|
102
+ assert config.load_config_file(File.join(@test_config_dir, "invalid.yml"))
103
+ end
104
+ end
105
+
106
+ reconfigure do |config|
107
+ config.api_token = nil
108
+ assert config.load_config_file(File.join(@test_config_dir, "full.yml"))
109
+ end
110
+ assert_equal LWS.config.api_token, "dev-token"
111
+ assert_equal LWS.config.endpoints, { maps: "http://maps.leftclick.cloud" }
112
+ assert_equal LWS.config.environment, :development
113
+ assert_equal LWS.config.http_debug, true
114
+ assert_equal LWS.config.http_debug_headers, true
115
+ assert_equal LWS.config.json_debug, true
116
+ end
117
+
68
118
  end
data/test/test_helper.rb CHANGED
@@ -43,7 +43,7 @@ Dir[File.expand_path("../support/**.rb", __FILE__)].each { |f| require f }
43
43
 
44
44
  raise "Test token not set" if ENV["LC_LWS_TEST_TOKEN"].blank?
45
45
 
46
- def reconfigure(options = {})
46
+ def reconfigure(options = {}, &block)
47
47
  LWS.setup do |config|
48
48
  config.api_token = ENV["LC_LWS_TEST_TOKEN"]
49
49
  if ENV["LC_LWS_TEST_DEBUG"].present?
@@ -58,6 +58,9 @@ def reconfigure(options = {})
58
58
  options.each do |key, value|
59
59
  config[key] = value
60
60
  end
61
+
62
+ # Finally, yield the block
63
+ yield config if block_given?
61
64
  end
62
65
  end
63
66
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lws
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LeftClick B.V.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-22 00:00:00.000000000 Z
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
@@ -257,6 +257,12 @@ files:
257
257
  - test/api_token_middleware_test.rb
258
258
  - test/auth_test.rb
259
259
  - test/caching_test.rb
260
+ - test/config/empty.yml
261
+ - test/config/endpoints.yml
262
+ - test/config/full.yml
263
+ - test/config/invalid.yml
264
+ - test/config/switch_env.yml
265
+ - test/config/tokens.yml
260
266
  - test/corporate_website_test.rb
261
267
  - test/digital_signage_test.rb
262
268
  - test/fixtures/auth.yml
@@ -290,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
290
296
  version: '0'
291
297
  requirements: []
292
298
  rubyforge_project:
293
- rubygems_version: 2.5.1
299
+ rubygems_version: 2.5.2.1
294
300
  signing_key:
295
301
  specification_version: 4
296
302
  summary: LeftClick web services library for Ruby
@@ -298,6 +304,12 @@ test_files:
298
304
  - test/api_token_middleware_test.rb
299
305
  - test/auth_test.rb
300
306
  - test/caching_test.rb
307
+ - test/config/empty.yml
308
+ - test/config/endpoints.yml
309
+ - test/config/full.yml
310
+ - test/config/invalid.yml
311
+ - test/config/switch_env.yml
312
+ - test/config/tokens.yml
301
313
  - test/corporate_website_test.rb
302
314
  - test/digital_signage_test.rb
303
315
  - test/fixtures/auth.yml