lhs 9.1.0 → 9.1.1

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
  SHA1:
3
- metadata.gz: 6332862581250354312558fba4a8aa584b4a0611
4
- data.tar.gz: 61d791ccc6b3153ad1928c9d743abfaac4005eff
3
+ metadata.gz: 580d8981ba9059cb3e1e5a5d598313e167421279
4
+ data.tar.gz: 561ba57069262b2c87a825b935b933522daac02f
5
5
  SHA512:
6
- metadata.gz: e47a127a76131cb1cf82f65c525fdc55b29e32b24b9d57366a24aa7ce2d034e3fc1681e9b239527e8d98bd1628f56a69e8b03f30fce5d5ed544b3d22f4c00412
7
- data.tar.gz: 3961c7b47fca9e438cc426cef6ea3daa873be38210ff46684726371019981397576c78235d08f50e893675abe0cddcdec83aa62e16d416b6e4905fd84e369bd4
6
+ metadata.gz: 1aaad8a56559f5a27c4fd5b9a82d31732525c8eb11e20d6b5b30b3b3913749caf7bc674bc71fa837c6c7cb9bb032983358f4fe3017e6621b6b8ace5bd04b9b8a
7
+ data.tar.gz: 2b298c29b539f34559693c83489809919005f7879a63731c217aecd07df222e9fcfa5646949775b9d0f1f8ee8ed3475fac472bf345f3619b55a506b92efbace4
data/lib/lhs.rb CHANGED
@@ -7,10 +7,14 @@ module LHS
7
7
  end
8
8
 
9
9
  def call(env)
10
+ self.class.require_records
11
+ @app.call(env)
12
+ end
13
+
14
+ def self.require_records
10
15
  Dir.glob(Rails.root.join('app/models/**/*.rb')).each do |file|
11
16
  require_dependency file if File.read(file).match('LHS::Record')
12
17
  end
13
- @app.call(env)
14
18
  end
15
19
  end
16
20
  end
@@ -20,6 +24,7 @@ Gem.find_files('lhs/**/*.rb').sort.each { |path| require path }
20
24
  # Preload all the LHS::Records that are defined in app/models
21
25
  class Engine < Rails::Engine
22
26
  initializer 'Load all LHS::Records from app/models/**' do |app|
27
+ LHS::RequireLhsRecords.require_records
23
28
  next if app.config.cache_classes
24
29
 
25
30
  app.config.middleware.use LHS::RequireLhsRecords
data/lib/lhs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "9.1.0"
2
+ VERSION = "9.1.1"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require "rails_helper"
2
+
3
+ describe LHS, type: :request do
4
+ context 'autoloading' do
5
+ it "pre/re-loads all LHS classes initialy,|
6
+ because it's necessary for endpoint-to-record-class-discovery",
7
+ cleanup_before: false do
8
+ all_endpoints = LHS::Record::Endpoints.all
9
+ expect(all_endpoints[':datastore/v2/users']).to be
10
+ expect(all_endpoints[':datastore/v2/users/:id']).to be
11
+ expect(
12
+ User.endpoints.detect { |endpoint| endpoint.url == ':datastore/v2/users' }
13
+ ).to be
14
+ expect(
15
+ User.endpoints.detect { |endpoint| endpoint.url == ':datastore/v2/users/:id' }
16
+ ).to be
17
+ end
18
+ end
19
+ end
@@ -2,4 +2,8 @@ class ApplicationController < ActionController::Base
2
2
  # Prevent CSRF attacks by raising an exception.
3
3
  # For APIs, you may want to use :null_session instead.
4
4
  protect_from_forgery with: :exception
5
+
6
+ def root
7
+ render nothing: true
8
+ end
5
9
  end
@@ -0,0 +1,4 @@
1
+ class User < LHS::Record
2
+ endpoint ':datastore/v2/users'
3
+ endpoint ':datastore/v2/users/:id'
4
+ end
@@ -0,0 +1,3 @@
1
+ LHC.configure do |config|
2
+ config.placeholder(:datastore, 'http://datastore')
3
+ end
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
3
3
  # See how all your routes lay out with "rake routes".
4
4
 
5
5
  # You can have the root of your site routed with "root"
6
- # root 'welcome#index'
6
+ root 'application#root'
7
7
 
8
8
  # Example of regular route:
9
9
  # get 'products/:id' => 'catalog#view'
@@ -0,0 +1,32 @@
1
+ require 'lhc'
2
+ class LHC::Config
3
+
4
+ def _cleanup
5
+ @endpoints = {}
6
+ @placeholders = {}
7
+ @interceptors = nil
8
+ end
9
+ end
10
+
11
+ class LHS::Record
12
+
13
+ CHILDREN = []
14
+
15
+ def self.inherited(child)
16
+ CHILDREN.push(child)
17
+ super
18
+ end
19
+
20
+ end
21
+
22
+ RSpec.configure do |config|
23
+ config.before(:each) do |spec|
24
+ next if spec.metadata.key?(:cleanup_before) && spec.metadata[:cleanup_before] == false
25
+ LHC::Config.instance._cleanup
26
+ LHS::Record::Endpoints.all = {}
27
+ LHS::Record::CHILDREN.each do |child|
28
+ child.endpoints = [] if !child.name['LHS']
29
+ child.configuration({}) if !child.name['LHS']
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.1.0
4
+ version: 9.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -233,6 +233,7 @@ files:
233
233
  - lib/lhs/version.rb
234
234
  - script/ci/build.sh
235
235
  - spec/.DS_Store
236
+ - spec/autoloading_spec.rb
236
237
  - spec/collection/accessors_spec.rb
237
238
  - spec/collection/collection_items_spec.rb
238
239
  - spec/collection/configurable_spec.rb
@@ -265,6 +266,7 @@ files:
265
266
  - spec/dummy/app/mailers/.keep
266
267
  - spec/dummy/app/models/.keep
267
268
  - spec/dummy/app/models/concerns/.keep
269
+ - spec/dummy/app/models/user.rb
268
270
  - spec/dummy/app/views/form_for.html.erb
269
271
  - spec/dummy/app/views/layouts/application.html.erb
270
272
  - spec/dummy/bin/bundle
@@ -282,6 +284,7 @@ files:
282
284
  - spec/dummy/config/initializers/cookies_serializer.rb
283
285
  - spec/dummy/config/initializers/filter_parameter_logging.rb
284
286
  - spec/dummy/config/initializers/inflections.rb
287
+ - spec/dummy/config/initializers/lhc.rb
285
288
  - spec/dummy/config/initializers/mime_types.rb
286
289
  - spec/dummy/config/initializers/session_store.rb
287
290
  - spec/dummy/config/initializers/wrap_parameters.rb
@@ -357,9 +360,7 @@ files:
357
360
  - spec/record/where_spec.rb
358
361
  - spec/record/where_values_hash_spec.rb
359
362
  - spec/spec_helper.rb
360
- - spec/support/cleanup_configuration.rb
361
- - spec/support/cleanup_endpoints.rb
362
- - spec/support/cleanup_records.rb
363
+ - spec/support/cleanup.rb
363
364
  - spec/support/fixtures/json/feedback.json
364
365
  - spec/support/fixtures/json/feedbacks.json
365
366
  - spec/support/fixtures/json/localina_content_ad.json
@@ -391,6 +392,7 @@ signing_key:
391
392
  specification_version: 4
392
393
  summary: Rails gem providing an easy, active-record-like interface for http json services
393
394
  test_files:
395
+ - spec/autoloading_spec.rb
394
396
  - spec/collection/accessors_spec.rb
395
397
  - spec/collection/collection_items_spec.rb
396
398
  - spec/collection/configurable_spec.rb
@@ -423,6 +425,7 @@ test_files:
423
425
  - spec/dummy/app/mailers/.keep
424
426
  - spec/dummy/app/models/.keep
425
427
  - spec/dummy/app/models/concerns/.keep
428
+ - spec/dummy/app/models/user.rb
426
429
  - spec/dummy/app/views/form_for.html.erb
427
430
  - spec/dummy/app/views/layouts/application.html.erb
428
431
  - spec/dummy/bin/bundle
@@ -440,6 +443,7 @@ test_files:
440
443
  - spec/dummy/config/initializers/cookies_serializer.rb
441
444
  - spec/dummy/config/initializers/filter_parameter_logging.rb
442
445
  - spec/dummy/config/initializers/inflections.rb
446
+ - spec/dummy/config/initializers/lhc.rb
443
447
  - spec/dummy/config/initializers/mime_types.rb
444
448
  - spec/dummy/config/initializers/session_store.rb
445
449
  - spec/dummy/config/initializers/wrap_parameters.rb
@@ -515,9 +519,7 @@ test_files:
515
519
  - spec/record/where_spec.rb
516
520
  - spec/record/where_values_hash_spec.rb
517
521
  - spec/spec_helper.rb
518
- - spec/support/cleanup_configuration.rb
519
- - spec/support/cleanup_endpoints.rb
520
- - spec/support/cleanup_records.rb
522
+ - spec/support/cleanup.rb
521
523
  - spec/support/fixtures/json/feedback.json
522
524
  - spec/support/fixtures/json/feedbacks.json
523
525
  - spec/support/fixtures/json/localina_content_ad.json
@@ -1,15 +0,0 @@
1
- require 'lhc'
2
- class LHC::Config
3
-
4
- def _cleanup
5
- @endpoints = {}
6
- @placeholders = {}
7
- @interceptors = nil
8
- end
9
- end
10
-
11
- RSpec.configure do |config|
12
- config.before(:each) do
13
- LHC::Config.instance._cleanup
14
- end
15
- end
@@ -1,5 +0,0 @@
1
- RSpec.configure do |config|
2
- config.before(:each) do
3
- LHS::Record::Endpoints.all = {}
4
- end
5
- end
@@ -1,19 +0,0 @@
1
- class LHS::Record
2
-
3
- CHILDREN = []
4
-
5
- def self.inherited(child)
6
- CHILDREN.push(child)
7
- super
8
- end
9
-
10
- end
11
-
12
- RSpec.configure do |config|
13
- config.before(:each) do
14
- LHS::Record::CHILDREN.each do |child|
15
- child.endpoints = [] if !child.name['LHS']
16
- child.configuration({}) if !child.name['LHS']
17
- end
18
- end
19
- end