u-attributes 0.10.0 → 0.11.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 +4 -4
- data/.travis.yml +4 -1
- data/Gemfile +23 -1
- data/Gemfile.lock +2 -2
- data/README.md +37 -11
- data/lib/micro/attributes.rb +2 -1
- data/lib/micro/attributes/features.rb +31 -2
- data/lib/micro/attributes/features/activemodel_validations.rb +34 -0
- data/lib/micro/attributes/version.rb +1 -1
- data/run-tests.sh +22 -0
- data/u-attributes.gemspec +0 -1
- metadata +3 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72e9cbaceb087cd97c5cf3a46b705f52d3664d96018851fda83d455dc59aaa36
|
4
|
+
data.tar.gz: 36238187591d0662c2212ea7fd3e1e5192d5785c2f1f59f57731d2f704e2a78b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f00dd1f663f7364c28743e33c8812f683a8a4837c42636b2289a179ca9a11a3935f4c7a443e688d0ecd57181f970afb4d37c7b06c823100a79c481ecc6cabae4
|
7
|
+
data.tar.gz: d86e8e5b6689e524fdfb72133e1f209d946726a109574df20a2aaa92a239fd123e973636c50bb4ca45c0de72533b107ca95b197f95bcde6520afeb37deaa7e42
|
data/.travis.yml
CHANGED
@@ -3,7 +3,7 @@ sudo: false
|
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
|
-
- 2.2.
|
6
|
+
- 2.2.2
|
7
7
|
- 2.3.0
|
8
8
|
- 2.4.0
|
9
9
|
- 2.5.0
|
@@ -11,5 +11,8 @@ rvm:
|
|
11
11
|
before_install:
|
12
12
|
- gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
|
13
13
|
- gem install bundler -v '< 2'
|
14
|
+
install: bundle install --jobs=3 --retry=3
|
14
15
|
env:
|
15
16
|
- DISABLE_SIMPLECOV=true
|
17
|
+
script: ./run-tests.sh
|
18
|
+
|
data/Gemfile
CHANGED
@@ -1,6 +1,28 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
gem 'simplecov', require: false, group: :test
|
4
4
|
|
5
|
+
activemodel_version = ENV.fetch('ACTIVEMODEL_VERSION', '6.1')
|
6
|
+
|
7
|
+
activemodel = case activemodel_version
|
8
|
+
when '3.2' then '3.2.22'
|
9
|
+
when '4.0' then '4.0.13'
|
10
|
+
when '4.1' then '4.1.16'
|
11
|
+
when '4.2' then '4.2.11'
|
12
|
+
when '5.0' then '5.0.7'
|
13
|
+
when '5.1' then '5.1.7'
|
14
|
+
when '5.2' then '5.2.3'
|
15
|
+
when '6.0' then '6.0.0.rc1'
|
16
|
+
end
|
17
|
+
|
18
|
+
if activemodel_version < '6.1'
|
19
|
+
gem 'activemodel', activemodel
|
20
|
+
gem 'activesupport', activemodel
|
21
|
+
end
|
22
|
+
|
23
|
+
minitest = activemodel_version < '4.1' ? '~> 4.2' : '~> 5.0'
|
24
|
+
|
25
|
+
gem 'minitest', minitest
|
26
|
+
|
5
27
|
# Specify your gem's dependencies in u-attributes.gemspec
|
6
28
|
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
u-attributes (0.
|
4
|
+
u-attributes (0.11.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
json (2.2.0)
|
11
11
|
minitest (5.11.3)
|
12
12
|
rake (10.5.0)
|
13
|
-
simplecov (0.
|
13
|
+
simplecov (0.17.0)
|
14
14
|
docile (~> 1.1)
|
15
15
|
json (>= 1.8, < 3)
|
16
16
|
simplecov-html (~> 0.10.0)
|
data/README.md
CHANGED
@@ -270,11 +270,7 @@ You can use the method `Micro::Attributes.features()` to combine and require onl
|
|
270
270
|
|
271
271
|
Note: The method `Micro::Attributes.with()` is an alias for `Micro::Attributes.features()`.
|
272
272
|
|
273
|
-
###
|
274
|
-
|
275
|
-
Provides a way to track changes in your object attributes.
|
276
|
-
|
277
|
-
#### How to enable?
|
273
|
+
### Usage
|
278
274
|
|
279
275
|
```ruby
|
280
276
|
#----------------------------------#
|
@@ -283,17 +279,17 @@ Provides a way to track changes in your object attributes.
|
|
283
279
|
class Job
|
284
280
|
include Micro::Attributes.features(:diff)
|
285
281
|
|
286
|
-
|
282
|
+
attribute :id
|
283
|
+
attribute :state, 'sleeping'
|
287
284
|
|
288
285
|
def initialize(options)
|
289
|
-
self.
|
286
|
+
self.attributes = options
|
290
287
|
end
|
291
288
|
end
|
292
289
|
|
293
290
|
# --------------------------------------------------------------------#
|
294
291
|
# Using the .with() method alias and adding the initialize extension. #
|
295
292
|
# --------------------------------------------------------------------#
|
296
|
-
|
297
293
|
class Job
|
298
294
|
include Micro::Attributes.with(:initialize, :diff)
|
299
295
|
|
@@ -304,19 +300,49 @@ end
|
|
304
300
|
# Via Micro::Attributes.to_initialize() #
|
305
301
|
#---------------------------------------#
|
306
302
|
class Job
|
307
|
-
include Micro::Attributes.to_initialize(diff: true)
|
303
|
+
include Micro::Attributes.to_initialize(diff: false, activemodel_validations: true)
|
308
304
|
|
309
|
-
|
310
|
-
|
305
|
+
attributes :id, state: 'sleeping'
|
306
|
+
validates! :id, :state, presence: true
|
311
307
|
end
|
312
308
|
```
|
313
309
|
|
310
|
+
### ActiveModel::Validations extension
|
311
|
+
|
312
|
+
If your application uses ActiveModel as a dependency (like a regular Rails app). You will be enabled to use the `actimodel_validations` extension.
|
313
|
+
|
314
|
+
#### Usage
|
315
|
+
|
316
|
+
```ruby
|
317
|
+
class Job
|
318
|
+
# include Micro::Attributes.with(:initialize, :activemodel_validations)
|
319
|
+
# include Micro::Attributes.features(:initialize, :activemodel_validations)
|
320
|
+
include Micro::Attributes.to_initialize(activemodel_validations: true)
|
321
|
+
|
322
|
+
attributes :id, state: 'sleeping'
|
323
|
+
validates! :id, :state, presence: true
|
324
|
+
end
|
325
|
+
|
326
|
+
Job.new({}) # ActiveModel::StrictValidationFailed (Id can't be blank)
|
327
|
+
|
328
|
+
job = Job.new(id: 1)
|
329
|
+
|
330
|
+
p job.id # 1
|
331
|
+
p job.state # "sleeping"
|
332
|
+
```
|
333
|
+
|
334
|
+
### Diff extension
|
335
|
+
|
336
|
+
Provides a way to track changes in your object attributes.
|
337
|
+
|
314
338
|
#### Usage
|
315
339
|
|
316
340
|
```ruby
|
317
341
|
require 'securerandom'
|
318
342
|
|
319
343
|
class Job
|
344
|
+
# include Micro::Attributes.with(:initialize, :diff)
|
345
|
+
# include Micro::Attributes.to_initialize(diff: true)
|
320
346
|
include Micro::Attributes.features(:initialize, :diff)
|
321
347
|
|
322
348
|
attributes :id, state: 'sleeping'
|
data/lib/micro/attributes.rb
CHANGED
@@ -22,9 +22,10 @@ module Micro
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def self.to_initialize(diff: false)
|
25
|
+
def self.to_initialize(diff: false, activemodel_validations: false)
|
26
26
|
options = [:initialize]
|
27
27
|
options << :diff if diff
|
28
|
+
options << :activemodel_validations if activemodel_validations
|
28
29
|
features(*options)
|
29
30
|
end
|
30
31
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "micro/attributes/features/diff"
|
4
4
|
require "micro/attributes/features/initialize"
|
5
|
+
require "micro/attributes/features/activemodel_validations"
|
5
6
|
|
6
7
|
module Micro
|
7
8
|
module Attributes
|
@@ -13,10 +14,38 @@ module Micro
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
17
|
+
module ActiveModelValidationsAndDiff
|
18
|
+
def self.included(base)
|
19
|
+
base.send(:include, ::Micro::Attributes::Features::Diff)
|
20
|
+
base.send(:include, ::Micro::Attributes::Features::ActiveModelValidations)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ActiveModelValidationsAndInitialize
|
25
|
+
def self.included(base)
|
26
|
+
base.send(:include, ::Micro::Attributes::Features::Initialize)
|
27
|
+
base.send(:include, ::Micro::Attributes::Features::ActiveModelValidations)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module ActiveModelValidationsAndDiffAndInitialize
|
32
|
+
def self.included(base)
|
33
|
+
base.send(:include, ::Micro::Attributes::Features::Initialize)
|
34
|
+
base.send(:include, ::Micro::Attributes::Features::Diff)
|
35
|
+
base.send(:include, ::Micro::Attributes::Features::ActiveModelValidations)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
16
39
|
OPTIONS = {
|
40
|
+
# Features
|
17
41
|
'diff' => Diff,
|
18
42
|
'initialize' => Initialize,
|
19
|
-
'
|
43
|
+
'activemodel_validations' => ActiveModelValidations,
|
44
|
+
# Combinations
|
45
|
+
'diff:initialize' => InitializeAndDiff,
|
46
|
+
'activemodel_validations:diff' => ActiveModelValidationsAndDiff,
|
47
|
+
'activemodel_validations:initialize' => ActiveModelValidationsAndInitialize,
|
48
|
+
'activemodel_validations:diff:initialize' => ActiveModelValidationsAndDiffAndInitialize
|
20
49
|
}.freeze
|
21
50
|
|
22
51
|
private_constant :OPTIONS
|
@@ -24,7 +53,7 @@ module Micro
|
|
24
53
|
def self.fetch(names)
|
25
54
|
option = OPTIONS[names.map { |name| name.to_s.downcase }.sort.join(':')]
|
26
55
|
return option if option
|
27
|
-
raise ArgumentError, 'Invalid feature name! Available options: diff, initialize'
|
56
|
+
raise ArgumentError, 'Invalid feature name! Available options: diff, initialize, activemodel_validations'
|
28
57
|
end
|
29
58
|
end
|
30
59
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Micro::Attributes
|
4
|
+
module Features
|
5
|
+
module ActiveModelValidations
|
6
|
+
@@__active_model_load_error = false
|
7
|
+
@@__active_model_required = false
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
if !@@__active_model_load_error && !@@__active_model_required
|
11
|
+
begin
|
12
|
+
require 'active_model'
|
13
|
+
rescue LoadError => e
|
14
|
+
@@__active_model_load_error = true
|
15
|
+
end
|
16
|
+
@@__active_model_required = true
|
17
|
+
end
|
18
|
+
|
19
|
+
unless @@__active_model_load_error
|
20
|
+
base.send(:include, ::ActiveModel::Validations)
|
21
|
+
|
22
|
+
if ::ActiveModel::VERSION::STRING >= '3.2'
|
23
|
+
base.class_eval(<<-RUBY)
|
24
|
+
def initialize(options)
|
25
|
+
self.attributes=(options)
|
26
|
+
run_validations!
|
27
|
+
end
|
28
|
+
RUBY
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/run-tests.sh
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
ACTIVEMODEL_VERSION='3.2' bundle update
|
4
|
+
ACTIVEMODEL_VERSION='3.2' bundle exec rake test
|
5
|
+
|
6
|
+
ACTIVEMODEL_VERSION='4.0' bundle update
|
7
|
+
ACTIVEMODEL_VERSION='4.0' bundle exec rake test
|
8
|
+
|
9
|
+
ACTIVEMODEL_VERSION='4.1' bundle update
|
10
|
+
ACTIVEMODEL_VERSION='4.1' bundle exec rake test
|
11
|
+
|
12
|
+
ACTIVEMODEL_VERSION='4.2' bundle update
|
13
|
+
ACTIVEMODEL_VERSION='4.2' bundle exec rake test
|
14
|
+
|
15
|
+
ACTIVEMODEL_VERSION='5.0' bundle update
|
16
|
+
ACTIVEMODEL_VERSION='5.0' bundle exec rake test
|
17
|
+
|
18
|
+
ACTIVEMODEL_VERSION='5.1' bundle update
|
19
|
+
ACTIVEMODEL_VERSION='5.1' bundle exec rake test
|
20
|
+
|
21
|
+
ACTIVEMODEL_VERSION='5.2' bundle update
|
22
|
+
ACTIVEMODEL_VERSION='5.2' bundle exec rake test
|
data/u-attributes.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '10.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: minitest
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5.0'
|
41
27
|
description: This gem allows defining read-only attributes, that is, your objects
|
42
28
|
will have only getters to access their attributes data.
|
43
29
|
email:
|
@@ -59,11 +45,13 @@ files:
|
|
59
45
|
- lib/micro/attributes.rb
|
60
46
|
- lib/micro/attributes/attributes_utils.rb
|
61
47
|
- lib/micro/attributes/features.rb
|
48
|
+
- lib/micro/attributes/features/activemodel_validations.rb
|
62
49
|
- lib/micro/attributes/features/diff.rb
|
63
50
|
- lib/micro/attributes/features/initialize.rb
|
64
51
|
- lib/micro/attributes/macros.rb
|
65
52
|
- lib/micro/attributes/version.rb
|
66
53
|
- lib/u-attributes.rb
|
54
|
+
- run-tests.sh
|
67
55
|
- u-attributes.gemspec
|
68
56
|
homepage: https://github.com/serradura/u-attributes
|
69
57
|
licenses:
|