artirix_data_models 0.18.0 → 0.19.0

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: d663a0947a081d9dbd5145eb404521db0a42b4bd
4
- data.tar.gz: ed757c3c5c1676982ccbb3d093a55134eae9ad60
3
+ metadata.gz: dfd953c7eaed394dbc237e87abfd355c97d19b1b
4
+ data.tar.gz: 5acbc42af128b2e3e89502eb40eb9049066739ad
5
5
  SHA512:
6
- metadata.gz: 6bcc9f58f64f314fd09168500f6039ff829943c2cbad1adabbef34e8bbf16893d58917daeceba3aa0178da3d09f9c31b9253d1079643ba742c708330ed9e202e
7
- data.tar.gz: f4777f21f1017f5edc30e898d71e4f1fe26f13cc2b2c873fdeaa76b424a126364ea417be826707af3797250acb5cc6c8c9576ab62bf55b92b64c0e5de866a629
6
+ metadata.gz: 250462062fac4f0eb4a93fcbcc83b4cb39b940f18a77517a25ad0e22071488340385e2a2c44b8160b88441f4cd86a258bc657380913c44572e883b99b65cd282
7
+ data.tar.gz: 37fdda63565fc00eca22bbe825894a14065b41b454abb4207bf17ef346da29cc84e44bb9dd6008cabf7702df4bdbe2ef13f33aad4adb82ab0a0579f1529b9aa1
data/README.md CHANGED
@@ -24,11 +24,56 @@ note: for making a model compatible with [ActiveModelSerializers](https://github
24
24
 
25
25
  ## Usage
26
26
 
27
+ ### Configuration
28
+
29
+ In previous versions, ADM required the use of `SimpleConfig` to configure itself. Now you have the alternative of using
30
+ `Rails.configuration` with the `config.x` support for custom configurations.
31
+
32
+ The configuration loaded will be `Rails.configuration.x.artirix_data_models` if present, or if not it will try to load
33
+ `SimpleConfig.for(:site)`. *important: it will not merge configs, it will load one or the other*
34
+
35
+ note: see [http://guides.rubyonrails.org/configuring.html#custom-configuration](http://guides.rubyonrails.org/configuring.html#custom-configuration)
36
+
37
+ You can also specify a different config by passing a config loader to `ArtirixDataModels.configuration_loader = -> { myconfig }`.
38
+
39
+ #### Using Rails config
40
+ ```ruby
41
+ module SomeApplication
42
+ class Application < Rails::Application
43
+
44
+ # normal Rails config...
45
+ config.action_mailer.perform_caching = false
46
+
47
+
48
+
49
+ # ADM CONFIG
50
+ config.x.artirix_data_models.data_gateway = ActiveSupport::OrderedOptions.new
51
+ config.x.artirix_data_models.data_gateway.url = 'http://super-secure-domain-123456.com'
52
+ end
53
+ end
54
+ ```
55
+
56
+ #### Using SimpleConfig
57
+
58
+ ```ruby
59
+ # config using SimpleConfig
60
+ SimpleConfig.for(:site) do
61
+ group :data_gateway do
62
+ set :url, 'http://super-secure-domain-123456.com'
63
+ end
64
+ end
65
+ ```
66
+
27
67
  ### Connection
28
68
 
29
69
  You have to specify the location of data-layer. It can be done in the config like this:
30
70
 
31
71
  ```ruby
72
+ # config using Rails.configuration
73
+ config.x.artirix_data_models.data_gateway.url = 'http://super-secure-domain-123456.com'
74
+
75
+
76
+ # config using SimpleConfig
32
77
  SimpleConfig.for(:site) do
33
78
  group :data_gateway do
34
79
  set :url, 'http://super-secure-domain-123456.com'
@@ -270,6 +315,9 @@ end
270
315
 
271
316
  ## Changes
272
317
 
318
+ ### 0.19.0
319
+ Added `configuration_loader` and support for `Rails.configuration.x.artirix_data_models`.
320
+
273
321
  ### 0.18.0
274
322
 
275
323
  `DataGateway` connection loader now moved to `DataGateway::ConnectionLoader`, with 3 public methods:
@@ -20,13 +20,14 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'activesupport'
22
22
  spec.add_dependency 'activemodel'
23
- spec.add_dependency 'simpleconfig'
24
23
  spec.add_dependency 'oj'
25
24
  spec.add_dependency 'faraday'
26
25
  spec.add_dependency 'keyword_init', '~> 1.4'
27
26
  spec.add_dependency 'naught'
28
27
  spec.add_dependency 'hashie', '~> 3.4'
29
28
 
29
+ spec.add_development_dependency 'simpleconfig'
30
+
30
31
  spec.add_development_dependency 'kaminari', '~> 0.16'
31
32
  spec.add_development_dependency 'will_paginate', '~> 3.0'
32
33
 
@@ -3,7 +3,6 @@ require 'artirix_data_models/version'
3
3
  # dependencies
4
4
  require 'active_support/all'
5
5
  require 'active_model'
6
- require 'simple_config'
7
6
  require 'oj'
8
7
  require 'faraday'
9
8
  require 'keyword_init'
@@ -11,6 +10,7 @@ require 'naught'
11
10
  require 'hashie'
12
11
 
13
12
  # note DO NOT require kaminari or will_paginate, it'll be done when invoking `ArtirixDataModels::EsCollection.work_with_will_paginate`
13
+ # note: do not require SimpleConfig, it has to exist before used. Same as we don't require Rails.
14
14
 
15
15
 
16
16
  # loading features
@@ -130,7 +130,42 @@ module ArtirixDataModels
130
130
  @disabled_cache ||= DisabledCache.new
131
131
  end
132
132
 
133
+ # CONFIGURATION
134
+
135
+ def self.configuration
136
+ configuration_loader.call
137
+ end
138
+
139
+ def self.configuration_loader=(loader=nil, &block)
140
+ if block_given?
141
+ @configuration_loader = block
142
+ elsif loader.present? && loader.respond_to?(:call)
143
+ @configuration_loader = loader
144
+ else
145
+ raise 'no block or callable object given as a loader'
146
+ end
147
+ end
148
+
149
+ def self.configuration_loader
150
+ @configuration_loader ||= default_configuration_loader
151
+ end
152
+
153
+ def self.default_configuration_loader
154
+ lambda do
155
+ if defined?(Rails) && Rails.configuration.try(:x) && Rails.configuration.x.artirix_data_models.present?
156
+ Rails.configuration.x.artirix_data_models
157
+ elsif defined?(SimpleConfig)
158
+ SimpleConfig.for(:site)
159
+ else
160
+ raise ConfigurationNeededError, 'Rails.configuration.x.artirix_data_models not available, and SimpleConfig.for(:site) not available'
161
+ end
162
+ end
163
+ end
164
+
133
165
  class IllegalActionError < StandardError
134
166
  end
135
167
 
168
+ class ConfigurationNeededError < StandardError
169
+ end
170
+
136
171
  end
@@ -120,7 +120,7 @@ module ArtirixDataModels::CacheService
120
120
  end
121
121
 
122
122
  def self.option_store
123
- @option_store ||= SimpleConfig.for(:site).try(:cache_options) || disabled_options_store
123
+ @option_store ||= ArtirixDataModels.configuration.try(:cache_options) || disabled_options_store
124
124
  end
125
125
 
126
126
  def self.disabled_options_store
@@ -172,7 +172,7 @@ module ArtirixDataModels::CacheService
172
172
  end
173
173
 
174
174
  def self.prefix
175
- SimpleConfig.for(:site).try(:cache_app_prefix)
175
+ ArtirixDataModels.configuration.try(:cache_app_prefix)
176
176
  end
177
177
  end
178
178
 
@@ -158,7 +158,7 @@ module ArtirixDataModels
158
158
  end
159
159
 
160
160
  def enabled?
161
- SimpleConfig.for(:site).try(:data_fake_mode).try(fake_mode_key)
161
+ ArtirixDataModels.configuration.try(:data_fake_mode).try(fake_mode_key)
162
162
  end
163
163
 
164
164
  def partial_hash_from_model(given_model_to_reload)
@@ -53,7 +53,7 @@ module ArtirixDataModels::GatewayResponseAdaptors
53
53
  end
54
54
 
55
55
  def self.collection(object_class_or_factory, from = 0, size = nil)
56
- size ||= SimpleConfig.for(:site).search_page_size.default
56
+ size ||= ArtirixDataModels.configuration.try(:search_page_size).try(:default) || 10
57
57
  new ->(data_collection) { ArtirixDataModels::EsCollection.new object_class_or_factory, response: data_collection, from: from, size: size }
58
58
  end
59
59
 
@@ -234,7 +234,7 @@ class ArtirixDataModels::DataGateway
234
234
  end
235
235
 
236
236
  def connection_by_config_key(config_key, **others)
237
- connection config: SimpleConfig.for(:site).send(config_key), **others
237
+ connection config: ArtirixDataModels.configuration.send(config_key), **others
238
238
  end
239
239
 
240
240
  def connection(config: {}, url: nil, login: nil, password: nil, bearer_token: nil, token_hash: nil)
@@ -1,25 +1,18 @@
1
1
  # :nocov:
2
2
  def fake_mode_for(model_name)
3
- before(:all) do
4
- SimpleConfig.for(:site) do
3
+ before(:each) do
4
+ config = ArtirixDataModels.configuration
5
5
 
6
- set :debug_model_mode_enabled, true
7
-
8
- group :data_fake_mode do
9
- set model_name, true
10
- end
6
+ # fix in case of SimpleConfig (mocking SimpleConfig with rspec explodes if not)
7
+ if defined?(SimpleConfig) && config.kind_of?(SimpleConfig::Config)
8
+ SimpleConfig::Config.class_eval { public :singleton_class }
11
9
  end
12
- end
13
10
 
14
- after(:all) do
15
- SimpleConfig.for(:site) do
11
+ dfm = config.try(:data_fake_mode) || double
12
+ allow(dfm).to receive(model_name).and_return(true)
13
+ allow(config).to receive(:data_fake_mode).and_return(dfm)
16
14
 
17
- set :debug_model_mode_enabled, false
18
-
19
- group :data_fake_mode do
20
- set model_name, false
21
- end
22
- end
15
+ allow(config).to receive(:debug_model_mode_enabled).and_return(true)
23
16
  end
24
17
  end
25
18
 
@@ -1,13 +1,18 @@
1
1
  # :nocov:
2
2
  def given_gateway_config(connection_url = nil)
3
3
  connection_url ||= 'http://example.com/other'
4
- before(:all) do
5
- c = connection_url
6
- SimpleConfig.for(:site) do
7
- group :data_gateway do
8
- set :url, c
9
- end
4
+
5
+ before(:each) do
6
+ config = ArtirixDataModels.configuration
7
+
8
+ # fix in case of SimpleConfig (mocking SimpleConfig with rspec explodes if not)
9
+ if defined?(SimpleConfig) && config.kind_of?(SimpleConfig::Config)
10
+ SimpleConfig::Config.class_eval { public :singleton_class }
10
11
  end
12
+
13
+ dg = config.try(:data_gateway) || double
14
+ allow(dg).to receive(:url).and_return(connection_url)
15
+ allow(config).to receive(:data_gateway).and_return(dg)
11
16
  end
12
17
  end
13
18
 
@@ -1,3 +1,3 @@
1
1
  module ArtirixDataModels
2
- VERSION = '0.18.0'
2
+ VERSION = '0.19.0'
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'simple_config'
2
3
 
3
4
  RSpec.describe ArtirixDataModels::DataGateway, type: :model do
4
5
  Given(:bearer) { 'MyBearerToken' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artirix_data_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eduardo Turiño
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-23 00:00:00.000000000 Z
11
+ date: 2016-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: simpleconfig
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: oj
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +108,20 @@ dependencies:
122
108
  - - "~>"
123
109
  - !ruby/object:Gem::Version
124
110
  version: '3.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simpleconfig
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: kaminari
127
127
  requirement: !ruby/object:Gem::Requirement