lb-project 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43956f0e7b1f6e48a65014512abd750ad68c18318bbf3c00aa6d1d49a46a96bc
4
- data.tar.gz: 40a8e5823b486781458458dd931f4669ccc722bb48a2503f9c846a700c251c50
3
+ metadata.gz: 5277950049547e259c4a214d9ca156e97609a8c0d0977783bd1de8f1b615cc1a
4
+ data.tar.gz: 292b0bedc18ac29e6df8f23428da5ec7f83d9b2e185574bfb7aae3b487627568
5
5
  SHA512:
6
- metadata.gz: ec0c25e1e978a2c8b261de4ad35febecbb21165032863a597020047b0a15932e79258b83f455671f5c829923b3fafdf0d0345074c316c5b85a6298a17f192e00
7
- data.tar.gz: 5bf9094b84a40341f9465fd9a777528c0a1b90f10d5215d532e1b2be2dcfde17cf7e05da585a6d2776579dc2c089497058f7e6ca7d9fb93d365117b2772da575
6
+ metadata.gz: 97272185aeb10d66d3b4ef61c89a05805c77667f5ad936448e1848f4735ef1232138fe3ca45c8b2954b563711b8ea6b68935be0e0412913f4e9b1b02d12e001f
7
+ data.tar.gz: 496cceee927c6a3d3608424064abae94c0ed105ef6fd80ac0d49d3e23aca6093f64c25cce9a5be07e6211cc9d85c4782c2067fd5c610d3d8e11606f1951dcde0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.5.1
data/Gemfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- ruby '2.5.0'
5
+ ruby '2.5.1'
6
6
 
7
7
  gemspec
data/lb-project.gemspec CHANGED
@@ -24,15 +24,14 @@ Gem::Specification.new do |gem|
24
24
  gem.extra_rdoc_files = %w[README.md]
25
25
  gem.required_ruby_version = '>= 2.5'
26
26
 
27
- gem.add_dependency 'dry-initializer', '~> 2.3', '< 2.4'
28
- gem.add_dependency 'dry-struct', '~> 0.4', '< 0.5'
29
- gem.add_dependency 'dry-types', '~> 0.12', '< 0.13'
30
- gem.add_dependency 'dry-view', '~> 0.3', '>= 0.3.0', '< 0.3.1'
31
- gem.add_dependency 'r18n-core', '~> 2.2', '< 2.3'
32
- gem.add_dependency 'roda', '~> 2.29', '< 2.30'
33
- gem.add_dependency 'roda-i18n', '~> 0.3', '< 0.4'
27
+ gem.add_dependency 'dry-initializer', '~> 2.4'
28
+ gem.add_dependency 'dry-struct', '~> 0.5'
29
+ gem.add_dependency 'dry-types', '~> 0.13'
30
+ gem.add_dependency 'dry-view', '~> 0.5'
31
+ gem.add_dependency 'roda', '~> 3.7'
32
+ gem.add_dependency 'roda-i18n', '~> 0.4'
34
33
 
35
- gem.add_development_dependency 'devtools', '~> 0.1.19'
34
+ gem.add_development_dependency 'devtools', '~> 0.1.20'
36
35
  gem.add_development_dependency 'guard', '~> 2.14'
37
36
  gem.add_development_dependency 'guard-bundler', '~> 2.1'
38
37
  gem.add_development_dependency 'guard-rspec', '~> 4.7', '>= 4.7.3'
@@ -4,6 +4,7 @@ module LB
4
4
  module Project
5
5
  # Configuration
6
6
  class Config < Dry::Struct
7
+ ERROR_MSG = 'load failed: config class is not a LB::Project::Condig'
7
8
  RequiredString = Types::Strict::String.constrained(min_size: 1)
8
9
 
9
10
  attribute :base_path, Types::Strict::String
@@ -11,24 +12,17 @@ module LB
11
12
  attribute :public_path, Types::Strict::String
12
13
  attribute :template_path, Types::Strict::String
13
14
 
14
- def self.load(root, name, env)
15
- path = File.join(File.join(root, 'config'), "#{name}.yml")
16
- yaml = File.exist?(path) ? YAML.load_file(path) : {}
15
+ def self.load(path, klass = LB::Project::Config)
16
+ raise ArgumentError, ERROR_MSG unless klass <= LB::Project::Config
17
17
 
18
- new(config(yaml, env))
19
- end
18
+ raise ArgumentError, not_found_msg(path) unless File.exist?(path)
20
19
 
21
- def self.config(yaml, env)
22
- schema.keys.each_with_object({}) do |key, memo|
23
- memo[key] = value_for(yaml, env, key)
24
- end
20
+ yaml = YAML.load_file(path)
21
+ klass.new(yaml.transform_keys!(&:to_sym))
25
22
  end
26
23
 
27
- def self.value_for(yaml, env, key)
28
- ENV.fetch(
29
- key.to_s.upcase,
30
- yaml.fetch(env.to_s, {})[key.to_s]
31
- )
24
+ def self.not_found_msg(path)
25
+ "load failed: config file '#{path}' does not exist!"
32
26
  end
33
27
  end
34
28
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LB
4
+ module Project
5
+ # Settings supplied to LB::Project.setup
6
+ class Settings < Dry::Struct
7
+ attribute :root, Types::Strict::String
8
+ attribute :config, LB::Project::Config
9
+ end
10
+ end
11
+ end
@@ -3,6 +3,6 @@
3
3
  module LB
4
4
  module Project
5
5
  # Version
6
- VERSION = '0.0.1'
6
+ VERSION = '0.1.0'
7
7
  end
8
8
  end
data/lib/lb/project.rb CHANGED
@@ -24,24 +24,29 @@ require 'lb/project/types'
24
24
 
25
25
  # Config
26
26
  require 'lb/project/config'
27
+ require 'lb/project/settings'
27
28
 
28
29
  # LB namespace
29
30
  module LB
30
31
  # Project
31
32
  module Project
32
- CONFIG_NAME = 'application'
33
- DEFAULT_RACK_ENV = 'development'
33
+ ERROR_MSG = 'Setup failed: settings is not a LB::Project::Settings'
34
34
 
35
35
  # Setup
36
36
  #
37
- # @param [File] root Path to project root
37
+ # @param [settings] project settings
38
38
  #
39
39
  # @return [self]
40
40
  #
41
41
  # @api private
42
42
  #
43
- def self.setup(root)
44
- @root = root
43
+ def self.setup(settings)
44
+ unless settings.is_a?(LB::Project::Settings)
45
+ raise ArgumentError,
46
+ ERROR_MSG
47
+ end
48
+
49
+ @settings = settings
45
50
 
46
51
  self
47
52
  end
@@ -53,7 +58,9 @@ module LB
53
58
  # @api private
54
59
  #
55
60
  def self.root
56
- @root
61
+ @settings.root
62
+ rescue NoMethodError
63
+ raise ArgumentError, 'Call LB::Project.setup(...) first!'
57
64
  end
58
65
 
59
66
  # Get root path for file
@@ -99,27 +106,9 @@ module LB
99
106
  # @api private
100
107
  #
101
108
  def self.config
102
- @config ||= Config.load(root, CONFIG_NAME, rack_env)
103
- end
104
-
105
- # Get RACK_ENV
106
- #
107
- # @return [String]
108
- #
109
- # @api private
110
- #
111
- def self.rack_env
112
- @rack_env ||= ENV.fetch('RACK_ENV', DEFAULT_RACK_ENV)
113
- end
114
-
115
- # Check if rack_env is 'development'
116
- #
117
- # @return [Boolean]
118
- #
119
- # @api private
120
- #
121
- def self.development?
122
- DEFAULT_RACK_ENV.eql? rack_env
109
+ @settings.config
110
+ rescue NoMethodError
111
+ raise ArgumentError, 'Call LB::Project.setup(...) first!'
123
112
  end
124
113
 
125
114
  def self.t(*params)
@@ -1,10 +1,4 @@
1
- development: &base
2
- base_path : ''
3
- image_base_path: 'assets/images'
4
- public_path: 'docs'
5
- template_path: 'templates'
6
- test:
7
- <<: *base
8
- production:
9
- <<: *base
10
- public_path: 'htdocs'
1
+ base_path : ''
2
+ image_base_path: 'assets/images'
3
+ public_path: 'docs'
4
+ template_path: 'templates'
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_context 'setup' do
4
+ let(:lb_root) { object.root_for(__FILE__, 3) }
5
+
6
+ let(:root) { File.join(lb_root, 'spec/fixtures') }
7
+
8
+ let(:config_file) { File.join(root, 'config/application.yml') }
9
+
10
+ let(:config) { LB::Project::Config.load(config_file) }
11
+
12
+ let(:settings) do
13
+ LB::Project::Settings.new(
14
+ root: root,
15
+ config: config
16
+ )
17
+ end
18
+
19
+ before(:each) do
20
+ object.setup(settings)
21
+ end
22
+
23
+ after(:each) do
24
+ if object.instance_variable_defined?(:@settings)
25
+ object.remove_instance_variable(:@settings)
26
+ end
27
+ end
28
+ end
@@ -7,51 +7,18 @@ describe LB::Project, '.config' do
7
7
 
8
8
  let(:object) { described_class }
9
9
 
10
- let(:default_hash) do
11
- {
12
- base_path: '',
13
- image_base_path: 'assets/images',
14
- public_path: 'docs',
15
- template_path: 'templates'
16
- }
17
- end
18
-
19
- let(:default) { LB::Project::Config.new(default_hash) }
20
-
21
- let(:env) { 'RACK_ENV' }
22
-
23
- before(:each) do
24
- root = LB::Project.root_for(__FILE__, 6)
25
- LB::Project.setup(File.join(root, 'spec/fixtures'))
26
- end
27
-
28
- after(:each) do
29
- object.remove_instance_variable(:@rack_env)
30
- object.remove_instance_variable(:@config)
31
- object.remove_instance_variable(:@root)
32
- end
33
-
34
- context 'without RACK_ENV' do
35
- it 'should return default config' do
36
- expect(subject).to eql(default)
10
+ context 'without setup' do
11
+ it 'should raise argument error' do
12
+ expect { subject }.to raise_error ArgumentError,
13
+ 'Call LB::Project.setup(...) first!'
37
14
  end
38
15
  end
39
16
 
40
- context 'with RACK_ENV=production' do
41
- let(:production_hash) { default_hash.merge(public_path: 'htdocs') }
42
- let(:production) { LB::Project::Config.new(production_hash) }
43
- let(:rack_env) { 'production' }
44
-
45
- before(:each) do
46
- ENV[env] = rack_env
47
- end
48
-
49
- after(:each) do
50
- ENV.delete(env)
51
- end
17
+ context 'without setup' do
18
+ include_context 'setup'
52
19
 
53
- it 'should return production config' do
54
- expect(subject).to eql(production)
20
+ it 'should return config' do
21
+ expect(subject).to be config
55
22
  end
56
23
  end
57
24
  end
@@ -8,23 +8,16 @@ describe LB::Project, '.root' do
8
8
  let(:object) { described_class }
9
9
 
10
10
  context 'without setup' do
11
- it 'should return nil' do
12
- expect(subject).to be_nil
11
+ it 'should raise argument error' do
12
+ expect { subject }.to raise_error ArgumentError,
13
+ 'Call LB::Project.setup(...) first!'
13
14
  end
14
15
  end
15
16
 
16
17
  context 'without setup' do
17
- let(:root) { double(:root) }
18
+ include_context 'setup'
18
19
 
19
- before(:each) do
20
- object.setup(root)
21
- end
22
-
23
- after(:each) do
24
- object.remove_instance_variable(:@root)
25
- end
26
-
27
- it 'should return nil' do
20
+ it 'should return root' do
28
21
  expect(subject).to be(root)
29
22
  end
30
23
  end
@@ -3,14 +3,11 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe LB::Project, '.setup' do
6
- subject { object.setup(root) }
6
+ include_context 'setup'
7
7
 
8
- let(:root) { double(:root) }
9
- let(:object) { described_class }
8
+ subject { object.setup(settings) }
10
9
 
11
- after(:each) do
12
- object.remove_instance_variable(:@root)
13
- end
10
+ let(:object) { described_class }
14
11
 
15
12
  it 'should return self' do
16
13
  expect(subject).to eql(object)
metadata CHANGED
@@ -1,23 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lb-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firas Zaidan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-06 00:00:00.000000000 Z
11
+ date: 2018-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-initializer
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.3'
20
- - - "<"
21
18
  - !ruby/object:Gem::Version
22
19
  version: '2.4'
23
20
  type: :runtime
@@ -25,9 +22,6 @@ dependencies:
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.3'
30
- - - "<"
31
25
  - !ruby/object:Gem::Version
32
26
  version: '2.4'
33
27
  - !ruby/object:Gem::Dependency
@@ -35,9 +29,6 @@ dependencies:
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '0.4'
40
- - - "<"
41
32
  - !ruby/object:Gem::Version
42
33
  version: '0.5'
43
34
  type: :runtime
@@ -45,9 +36,6 @@ dependencies:
45
36
  version_requirements: !ruby/object:Gem::Requirement
46
37
  requirements:
47
38
  - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '0.4'
50
- - - "<"
51
39
  - !ruby/object:Gem::Version
52
40
  version: '0.5'
53
41
  - !ruby/object:Gem::Dependency
@@ -55,9 +43,6 @@ dependencies:
55
43
  requirement: !ruby/object:Gem::Requirement
56
44
  requirements:
57
45
  - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '0.12'
60
- - - "<"
61
46
  - !ruby/object:Gem::Version
62
47
  version: '0.13'
63
48
  type: :runtime
@@ -65,9 +50,6 @@ dependencies:
65
50
  version_requirements: !ruby/object:Gem::Requirement
66
51
  requirements:
67
52
  - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '0.12'
70
- - - "<"
71
53
  - !ruby/object:Gem::Version
72
54
  version: '0.13'
73
55
  - !ruby/object:Gem::Dependency
@@ -76,74 +58,33 @@ dependencies:
76
58
  requirements:
77
59
  - - "~>"
78
60
  - !ruby/object:Gem::Version
79
- version: '0.3'
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 0.3.0
83
- - - "<"
84
- - !ruby/object:Gem::Version
85
- version: 0.3.1
86
- type: :runtime
87
- prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- requirements:
90
- - - "~>"
91
- - !ruby/object:Gem::Version
92
- version: '0.3'
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: 0.3.0
96
- - - "<"
97
- - !ruby/object:Gem::Version
98
- version: 0.3.1
99
- - !ruby/object:Gem::Dependency
100
- name: r18n-core
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '2.2'
106
- - - "<"
107
- - !ruby/object:Gem::Version
108
- version: '2.3'
61
+ version: '0.5'
109
62
  type: :runtime
110
63
  prerelease: false
111
64
  version_requirements: !ruby/object:Gem::Requirement
112
65
  requirements:
113
66
  - - "~>"
114
67
  - !ruby/object:Gem::Version
115
- version: '2.2'
116
- - - "<"
117
- - !ruby/object:Gem::Version
118
- version: '2.3'
68
+ version: '0.5'
119
69
  - !ruby/object:Gem::Dependency
120
70
  name: roda
121
71
  requirement: !ruby/object:Gem::Requirement
122
72
  requirements:
123
73
  - - "~>"
124
74
  - !ruby/object:Gem::Version
125
- version: '2.29'
126
- - - "<"
127
- - !ruby/object:Gem::Version
128
- version: '2.30'
75
+ version: '3.7'
129
76
  type: :runtime
130
77
  prerelease: false
131
78
  version_requirements: !ruby/object:Gem::Requirement
132
79
  requirements:
133
80
  - - "~>"
134
81
  - !ruby/object:Gem::Version
135
- version: '2.29'
136
- - - "<"
137
- - !ruby/object:Gem::Version
138
- version: '2.30'
82
+ version: '3.7'
139
83
  - !ruby/object:Gem::Dependency
140
84
  name: roda-i18n
141
85
  requirement: !ruby/object:Gem::Requirement
142
86
  requirements:
143
87
  - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '0.3'
146
- - - "<"
147
88
  - !ruby/object:Gem::Version
148
89
  version: '0.4'
149
90
  type: :runtime
@@ -151,9 +92,6 @@ dependencies:
151
92
  version_requirements: !ruby/object:Gem::Requirement
152
93
  requirements:
153
94
  - - "~>"
154
- - !ruby/object:Gem::Version
155
- version: '0.3'
156
- - - "<"
157
95
  - !ruby/object:Gem::Version
158
96
  version: '0.4'
159
97
  - !ruby/object:Gem::Dependency
@@ -162,14 +100,14 @@ dependencies:
162
100
  requirements:
163
101
  - - "~>"
164
102
  - !ruby/object:Gem::Version
165
- version: 0.1.19
103
+ version: 0.1.20
166
104
  type: :development
167
105
  prerelease: false
168
106
  version_requirements: !ruby/object:Gem::Requirement
169
107
  requirements:
170
108
  - - "~>"
171
109
  - !ruby/object:Gem::Version
172
- version: 0.1.19
110
+ version: 0.1.20
173
111
  - !ruby/object:Gem::Dependency
174
112
  name: guard
175
113
  requirement: !ruby/object:Gem::Requirement
@@ -296,6 +234,7 @@ files:
296
234
  - lib/lb/project/registry/registration.rb
297
235
  - lib/lb/project/render.rb
298
236
  - lib/lb/project/route.rb
237
+ - lib/lb/project/settings.rb
299
238
  - lib/lb/project/site.rb
300
239
  - lib/lb/project/types.rb
301
240
  - lib/lb/project/version.rb
@@ -314,12 +253,11 @@ files:
314
253
  - spec/fixtures/templates/index.html.slim
315
254
  - spec/fixtures/templates/layouts/main.html.slim
316
255
  - spec/fixtures/webpack-assets.json
256
+ - spec/shared/setup.rb
317
257
  - spec/spec_helper.rb
318
258
  - spec/support/helper.rb
319
259
  - spec/unit/lb/project/class_methods/config_spec.rb
320
- - spec/unit/lb/project/class_methods/development_quest_spec.rb
321
260
  - spec/unit/lb/project/class_methods/logger_spec.rb
322
- - spec/unit/lb/project/class_methods/rack_env_spec.rb
323
261
  - spec/unit/lb/project/class_methods/root_for_spec.rb
324
262
  - spec/unit/lb/project/class_methods/root_spec.rb
325
263
  - spec/unit/lb/project/class_methods/setup_spec.rb
@@ -344,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
344
282
  version: '0'
345
283
  requirements: []
346
284
  rubyforge_project:
347
- rubygems_version: 2.7.3
285
+ rubygems_version: 2.7.6
348
286
  signing_key:
349
287
  specification_version: 4
350
288
  summary: Static site builder with easy migration to dynamic site
@@ -362,12 +300,11 @@ test_files:
362
300
  - spec/fixtures/templates/index.html.slim
363
301
  - spec/fixtures/templates/layouts/main.html.slim
364
302
  - spec/fixtures/webpack-assets.json
303
+ - spec/shared/setup.rb
365
304
  - spec/spec_helper.rb
366
305
  - spec/support/helper.rb
367
306
  - spec/unit/lb/project/class_methods/config_spec.rb
368
- - spec/unit/lb/project/class_methods/development_quest_spec.rb
369
307
  - spec/unit/lb/project/class_methods/logger_spec.rb
370
- - spec/unit/lb/project/class_methods/rack_env_spec.rb
371
308
  - spec/unit/lb/project/class_methods/root_for_spec.rb
372
309
  - spec/unit/lb/project/class_methods/root_spec.rb
373
310
  - spec/unit/lb/project/class_methods/setup_spec.rb
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe LB::Project, '.development?' do
6
- subject { object.development? }
7
-
8
- let(:object) { described_class }
9
-
10
- let(:default) { 'development' }
11
-
12
- let(:env) { 'RACK_ENV' }
13
-
14
- after(:each) do
15
- object.remove_instance_variable(:@rack_env)
16
- end
17
-
18
- context 'without RACK_ENV' do
19
- it 'should return true' do
20
- expect(subject).to be true
21
- end
22
- end
23
-
24
- context 'with RACK_ENV=production' do
25
- let(:rack_env) { 'production' }
26
-
27
- before(:each) do
28
- ENV[env] = rack_env
29
- end
30
-
31
- after(:each) do
32
- ENV.delete(env)
33
- end
34
-
35
- it 'should return false' do
36
- expect(subject).to be false
37
- end
38
- end
39
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe LB::Project, '.rack_env' do
6
- subject { object.rack_env }
7
-
8
- let(:object) { described_class }
9
-
10
- let(:default) { 'development' }
11
-
12
- let(:env) { 'RACK_ENV' }
13
-
14
- after(:each) do
15
- object.remove_instance_variable(:@rack_env)
16
- end
17
-
18
- context 'without RACK_ENV' do
19
- it 'should return default RACK_ENV' do
20
- expect(subject).to eql(default)
21
- end
22
- end
23
-
24
- context 'with RACK_ENV=production' do
25
- let(:rack_env) { 'production' }
26
-
27
- before(:each) do
28
- ENV[env] = rack_env
29
- end
30
-
31
- after(:each) do
32
- ENV.delete(env)
33
- end
34
-
35
- it 'should return production' do
36
- expect(subject).to eql(rack_env)
37
- end
38
- end
39
- end