sinclair 1.14.0 → 1.14.2
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/Dockerfile.circleci +28 -0
- data/README.md +46 -16
- data/config/check_specs.yml +1 -0
- data/config/yardstick.yml +1 -1
- data/docker-compose.yml +11 -0
- data/lib/sinclair/class_methods.rb +41 -0
- data/lib/sinclair/method_definition/parameter_helper.rb +14 -3
- data/lib/sinclair/model/builder.rb +20 -7
- data/lib/sinclair/model/builder_options.rb +13 -0
- data/lib/sinclair/model.rb +2 -1
- data/lib/sinclair/version.rb +1 -1
- data/lib/sinclair.rb +16 -0
- data/sinclair.gemspec +1 -1
- data/spec/integration/yard/sinclair/class_methods/build_spec.rb +23 -0
- data/spec/integration/yard/sinclair_spec.rb +1 -1
- data/spec/lib/sinclair/class_methods_spec.rb +38 -0
- data/spec/lib/sinclair/method_definition/parameter_helper_spec.rb +22 -0
- data/spec/lib/sinclair/model_spec.rb +31 -0
- data/spec/support/models/http_json_model.rb +4 -6
- data/spec/support/models/tv.rb +2 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6bd1d9896437c341e52648bac78c70d453a773c92a2fba06111d88d12be06a3
|
4
|
+
data.tar.gz: 5cb2ba761532e3db60ffc8a09b821509c1355949071c5346cef962b0d43dfe9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf2fd682ae8e6c57a8a173a5f78492bf6c7011dfef7734fd9c0c2d3d4d73fa599bac72a9317920dd0ebf5bb6c98f0f2f511c0fcc9fe5b683f766b5624359ccf3
|
7
|
+
data.tar.gz: db83a68fd9b11d0a227afca422f5a6e8e33bc64e3624a55c0d8f3b87d49235d8e17b1393c44b6ac2a67c8b9869e58d5780a3a06aad4f76429a4c4b0c48247f43
|
data/Dockerfile.circleci
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
FROM darthjee/scripts:0.3.1 as scripts
|
2
|
+
|
3
|
+
FROM darthjee/circleci_ruby_270:1.2.0 as base
|
4
|
+
|
5
|
+
COPY --chown=app:app ./ /home/circleci/project/
|
6
|
+
|
7
|
+
######################################
|
8
|
+
|
9
|
+
FROM base as builder
|
10
|
+
|
11
|
+
COPY --chown=circleci:circleci --from=scripts /home/scripts/builder/bundle_builder.sh /usr/local/sbin/bundle_builder.sh
|
12
|
+
|
13
|
+
ENV PROJECT sinclair
|
14
|
+
ENV HOME_DIR /home/circleci
|
15
|
+
RUN bundle_builder.sh
|
16
|
+
|
17
|
+
#######################
|
18
|
+
#FINAL IMAGE
|
19
|
+
FROM base
|
20
|
+
|
21
|
+
COPY --chown=circleci:circleci --from=builder /home/circleci/bundle/ /home/circleci/.rubygems/
|
22
|
+
|
23
|
+
COPY --chown=circleci:circleci --from=scripts /home/scripts/sbin/rubycritic.sh /usr/local/sbin/
|
24
|
+
COPY --chown=circleci:circleci --from=scripts /home/scripts/sbin/check_specs /usr/local/sbin/
|
25
|
+
COPY --chown=circleci:circleci --from=scripts /home/scripts/sbin/check_readme.sh /usr/local/sbin/
|
26
|
+
COPY --chown=circleci:circleci --from=scripts /home/scripts/sbin/build_gem.sh /usr/local/sbin/
|
27
|
+
|
28
|
+
RUN bundle install
|
data/README.md
CHANGED
@@ -9,17 +9,19 @@ Sinclair
|
|
9
9
|
|
10
10
|

|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
Sinclair is a Ruby gem that provides developers with a variety of utility modules and classes
|
13
|
+
to simplify common tasks, reusability and avoid boilerplate code. Whether you need to class methods to create methods on the fly,
|
14
|
+
create custom comparators, configure your application, create powerfull options, Sinclair has got you covered.
|
15
15
|
|
16
|
-
|
16
|
+
Employing Sinclair in your applications helps you streamline your development workflow and enhance your development process through more efficient, cleaner code
|
17
17
|
|
18
|
-
[
|
18
|
+
Current Release: [1.14.2](https://github.com/darthjee/sinclair/tree/1.14.2)
|
19
|
+
|
20
|
+
[Next release](https://github.com/darthjee/sinclair/compare/1.14.2...master)
|
19
21
|
|
20
22
|
Yard Documentation
|
21
23
|
-------------------
|
22
|
-
[https://www.rubydoc.info/gems/sinclair/1.14.
|
24
|
+
[https://www.rubydoc.info/gems/sinclair/1.14.2](https://www.rubydoc.info/gems/sinclair/1.14.2)
|
23
25
|
|
24
26
|
Installation
|
25
27
|
---------------
|
@@ -77,20 +79,20 @@ puts "One Hundred => #{Clazz.one_hundred_twenty}" # One Hundred Twenty => 120
|
|
77
79
|
<summary>Builder in class method</summary>
|
78
80
|
|
79
81
|
```ruby
|
82
|
+
# http_json_model.rb
|
83
|
+
|
80
84
|
class HttpJsonModel
|
81
85
|
attr_reader :json
|
82
86
|
|
83
87
|
class << self
|
84
88
|
def parse(attribute, path: [])
|
85
|
-
builder = Sinclair.new(self)
|
86
|
-
|
87
89
|
keys = (path + [attribute]).map(&:to_s)
|
88
90
|
|
89
|
-
|
90
|
-
|
91
|
+
Sinclair.build(self) do
|
92
|
+
add_method(attribute) do
|
93
|
+
keys.inject(hash) { |h, key| h[key] }
|
94
|
+
end
|
91
95
|
end
|
92
|
-
|
93
|
-
builder.build
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -102,6 +104,10 @@ class HttpJsonModel
|
|
102
104
|
@hash ||= JSON.parse(json)
|
103
105
|
end
|
104
106
|
end
|
107
|
+
```
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
# http_person.rb
|
105
111
|
|
106
112
|
class HttpPerson < HttpJsonModel
|
107
113
|
parse :uid
|
@@ -110,7 +116,9 @@ class HttpPerson < HttpJsonModel
|
|
110
116
|
parse :username, path: [:digital_information]
|
111
117
|
parse :email, path: [:digital_information]
|
112
118
|
end
|
119
|
+
```
|
113
120
|
|
121
|
+
```ruby
|
114
122
|
json = <<-JSON
|
115
123
|
{
|
116
124
|
"uid": "12sof511",
|
@@ -524,8 +532,16 @@ Client.config.url # returns 'http://interstella.com:8080'
|
|
524
532
|
|
525
533
|
### Sinclair::EnvSettable
|
526
534
|
|
527
|
-
|
528
|
-
|
535
|
+
EnvSettable is a convenient utility that allows you to read environment
|
536
|
+
variables using Ruby class methods.
|
537
|
+
|
538
|
+
With this tool, you can define the usage of environment variables for your application in a single location
|
539
|
+
allowing the use of prefixes to isolate groups of variables.
|
540
|
+
|
541
|
+
This not only makes your code more readable and maintainable but also adds layer of security by ensuring
|
542
|
+
that sensitive information like API keys and passwords are not exposed in your source code.
|
543
|
+
|
544
|
+
EnvSettable allows accessing those variables thorugh a simple meta-programable way
|
529
545
|
|
530
546
|
<details>
|
531
547
|
<summary>Using env settable example</summary>
|
@@ -645,7 +661,8 @@ human1 == human2 # returns true
|
|
645
661
|
<summary>Example with options</summary>
|
646
662
|
|
647
663
|
```ruby
|
648
|
-
class Tv < Sinclair::Model
|
664
|
+
class Tv < Sinclair::Model
|
665
|
+
initialize_with :model, writter: false, comparable: false
|
649
666
|
end
|
650
667
|
|
651
668
|
tv1 = Tv.new(model: 'Sans Sunga Xt')
|
@@ -664,6 +681,15 @@ You can use the provided matcher to check that your builder is adding a method c
|
|
664
681
|
<summary>Sample of specs over adding methods</summary>
|
665
682
|
|
666
683
|
```ruby
|
684
|
+
# spec_helper.rb
|
685
|
+
|
686
|
+
RSpec.configure do |config|
|
687
|
+
config.include Sinclair::Matchers
|
688
|
+
end
|
689
|
+
```
|
690
|
+
|
691
|
+
```ruby
|
692
|
+
# default_value.rb
|
667
693
|
class DefaultValue
|
668
694
|
delegate :build, to: :builder
|
669
695
|
attr_reader :klass, :method, :value, :class_method
|
@@ -687,8 +713,12 @@ class DefaultValue
|
|
687
713
|
end
|
688
714
|
end
|
689
715
|
end
|
716
|
+
```
|
717
|
+
|
718
|
+
```ruby
|
719
|
+
# default_value_spec.rb
|
690
720
|
|
691
|
-
RSpec.describe
|
721
|
+
RSpec.describe DefaultValue do
|
692
722
|
subject(:builder_class) { DefaultValue }
|
693
723
|
|
694
724
|
let(:klass) { Class.new }
|
data/config/check_specs.yml
CHANGED
data/config/yardstick.yml
CHANGED
data/docker-compose.yml
CHANGED
@@ -21,3 +21,14 @@ services:
|
|
21
21
|
<<: *base
|
22
22
|
depends_on: [base_build]
|
23
23
|
command: /bin/bash -c 'rspec && yard && rake yardstick_measure && rake verify_measurements'
|
24
|
+
|
25
|
+
sinclair_circleci:
|
26
|
+
<<: *base
|
27
|
+
image: sinclair_circleci
|
28
|
+
container_name: sinclair_circleci
|
29
|
+
volumes:
|
30
|
+
- .:/home/circleci/project
|
31
|
+
working_dir: /home/circleci/project
|
32
|
+
command: /bin/bash
|
33
|
+
build:
|
34
|
+
dockerfile: Dockerfile.circleci
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Sinclair
|
4
|
+
# @author darthjee
|
5
|
+
# @api public
|
6
|
+
#
|
7
|
+
# Class methods for {Sinclair}
|
8
|
+
module ClassMethods
|
9
|
+
# Runs build using a block for adding the methods
|
10
|
+
#
|
11
|
+
# The block is executed adding the methods and after the builder
|
12
|
+
# runs build building all the methods
|
13
|
+
#
|
14
|
+
# @param (see Sinclair#initialize)
|
15
|
+
# @param block [Proc] block to be executed by the builder
|
16
|
+
# in order to add the methods before running build
|
17
|
+
#
|
18
|
+
# @yield an instance of a builder ({Sinclair})
|
19
|
+
#
|
20
|
+
# @return (see Sinclair#build)
|
21
|
+
#
|
22
|
+
# @example Simple usage
|
23
|
+
# class MyPerson
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# Sinclair.build(model_class) do
|
27
|
+
# add_method(:random_name, cached: true) do
|
28
|
+
# "John #{Random.rand(1000)} Doe"
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# model = MyPerson.new
|
33
|
+
#
|
34
|
+
# model.random_name # returns 'John 803 Doe'
|
35
|
+
def build(klass, options = {}, &block)
|
36
|
+
new(klass, options).tap do |builder|
|
37
|
+
builder.instance_eval(&block)
|
38
|
+
end.build
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -26,7 +26,7 @@ class Sinclair
|
|
26
26
|
# @param parameters_list [Array<Object>] list of parameters and defaults
|
27
27
|
# @param named [TrueClass,FalseClass] Flag informing if the parameters are
|
28
28
|
# named parameters
|
29
|
-
def initialize(parameters_list, named:
|
29
|
+
def initialize(parameters_list, named: nil)
|
30
30
|
@parameters_list = parameters_list
|
31
31
|
@named = named
|
32
32
|
end
|
@@ -40,7 +40,7 @@ class Sinclair
|
|
40
40
|
def strings
|
41
41
|
return [] unless parameters_list
|
42
42
|
|
43
|
-
parameters_strings + defaults_strings
|
43
|
+
parameters_strings + defaults_strings + wild_card_parameters
|
44
44
|
end
|
45
45
|
|
46
46
|
private
|
@@ -81,7 +81,18 @@ class Sinclair
|
|
81
81
|
# @return [Array<Symbol>]
|
82
82
|
def parameters
|
83
83
|
parameters_list.reject do |param|
|
84
|
-
param.is_a?(Hash)
|
84
|
+
param.is_a?(Hash) || param.to_s.match?(/^\*/)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Returns the named parameters that have not been defined
|
89
|
+
#
|
90
|
+
# THis is usually extra options
|
91
|
+
#
|
92
|
+
# @return [Array<String>]
|
93
|
+
def wild_card_parameters
|
94
|
+
parameters_list.reject do |param|
|
95
|
+
param.is_a?(Hash) || !param.to_s.match?(/^\*/)
|
85
96
|
end
|
86
97
|
end
|
87
98
|
|
@@ -26,11 +26,10 @@ class Sinclair
|
|
26
26
|
# method should be added
|
27
27
|
# @param comparable [TrueClass,FalseClass] flag to make the class {Comparable}
|
28
28
|
# by the fields
|
29
|
-
def initialize(klass, *attributes,
|
29
|
+
def initialize(klass, *attributes, **options)
|
30
30
|
super(klass)
|
31
31
|
@attributes = attributes.flatten
|
32
|
-
@
|
33
|
-
@comparable = comparable
|
32
|
+
@options = BuilderOptions.new(**options)
|
34
33
|
|
35
34
|
add_methods
|
36
35
|
change_equals
|
@@ -39,7 +38,9 @@ class Sinclair
|
|
39
38
|
|
40
39
|
private
|
41
40
|
|
42
|
-
attr_reader :attributes, :
|
41
|
+
attr_reader :attributes, :options
|
42
|
+
|
43
|
+
delegate :writter, :comparable, to: :options
|
43
44
|
alias writter? writter
|
44
45
|
alias comparable? comparable
|
45
46
|
|
@@ -54,6 +55,14 @@ class Sinclair
|
|
54
55
|
#
|
55
56
|
# @return [Array<Symbol,Hash>]
|
56
57
|
|
58
|
+
# @!method options
|
59
|
+
# @api private
|
60
|
+
# @private
|
61
|
+
#
|
62
|
+
# Class building options
|
63
|
+
#
|
64
|
+
# @return [BuilderOptions]
|
65
|
+
|
57
66
|
# @!method writter
|
58
67
|
# @api private
|
59
68
|
# @private
|
@@ -118,11 +127,15 @@ class Sinclair
|
|
118
127
|
#
|
119
128
|
# @return [Array<MethodDefinition>]
|
120
129
|
def change_initializer
|
121
|
-
|
130
|
+
lines = attributes_names.map do |attr|
|
122
131
|
"@#{attr} = #{attr}"
|
123
|
-
end
|
132
|
+
end
|
133
|
+
|
134
|
+
lines << 'super(**attributes)'
|
135
|
+
|
136
|
+
code = lines.join("\n")
|
124
137
|
|
125
|
-
add_method(:initialize, code, named_parameters: attributes)
|
138
|
+
add_method(:initialize, code, named_parameters: attributes + ['**attributes'])
|
126
139
|
end
|
127
140
|
|
128
141
|
# @private
|
data/lib/sinclair/model.rb
CHANGED
@@ -6,7 +6,8 @@ class Sinclair
|
|
6
6
|
#
|
7
7
|
# Basic model to be used when defining new classes quickly
|
8
8
|
class Model
|
9
|
-
autoload :Builder,
|
9
|
+
autoload :Builder, 'sinclair/model/builder'
|
10
|
+
autoload :BuilderOptions, 'sinclair/model/builder_options'
|
10
11
|
|
11
12
|
class << self
|
12
13
|
# Returns a new class that inherits from model
|
data/lib/sinclair/version.rb
CHANGED
data/lib/sinclair.rb
CHANGED
@@ -83,6 +83,7 @@ class Sinclair
|
|
83
83
|
require 'sinclair/options_parser'
|
84
84
|
|
85
85
|
autoload :VERSION, 'sinclair/version'
|
86
|
+
autoload :ClassMethods, 'sinclair/class_methods'
|
86
87
|
autoload :Config, 'sinclair/config'
|
87
88
|
autoload :ConfigBuilder, 'sinclair/config_builder'
|
88
89
|
autoload :ConfigClass, 'sinclair/config_class'
|
@@ -100,6 +101,21 @@ class Sinclair
|
|
100
101
|
autoload :Options, 'sinclair/options'
|
101
102
|
|
102
103
|
include OptionsParser
|
104
|
+
extend ClassMethods
|
105
|
+
|
106
|
+
# @method self.build(klass, options = {}, &block)
|
107
|
+
# Runs build using a block for adding the methods
|
108
|
+
#
|
109
|
+
# The block is executed adding the methods and after the builder
|
110
|
+
# runs build building all the methods
|
111
|
+
#
|
112
|
+
# @see Sinclair::ClassMethods#build
|
113
|
+
#
|
114
|
+
# @param (see Sinclair::ClassMethods#build)
|
115
|
+
# @return (see Sinclair::ClassMethods#build)
|
116
|
+
# @yield (see Sinclair::ClassMethods#build)
|
117
|
+
#
|
118
|
+
# @example (see Sinclair::ClassMethods#build)
|
103
119
|
|
104
120
|
# Returns a new instance of Sinclair
|
105
121
|
#
|
data/sinclair.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |gem|
|
|
21
21
|
|
22
22
|
gem.add_runtime_dependency 'activesupport', '~> 5.2.0'
|
23
23
|
|
24
|
-
gem.add_development_dependency 'bundler', '2.3.25'
|
24
|
+
gem.add_development_dependency 'bundler', '>= 2.3.25'
|
25
25
|
gem.add_development_dependency 'pry', '0.14.1'
|
26
26
|
gem.add_development_dependency 'pry-nav', '1.0.0'
|
27
27
|
gem.add_development_dependency 'rake', '13.0.1'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: false
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Sinclair::ClassMethods do
|
6
|
+
describe 'yard for .build' do
|
7
|
+
before { allow(Random).to receive(:rand).and_return(803) }
|
8
|
+
|
9
|
+
it 'Simple usage' do
|
10
|
+
model_class = Class.new
|
11
|
+
|
12
|
+
Sinclair.build(model_class) do
|
13
|
+
add_method(:random_name, cached: true) do
|
14
|
+
"John #{Random.rand(1000)} Doe"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
model = model_class.new
|
19
|
+
|
20
|
+
expect(model.random_name).to eq('John 803 Doe')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Sinclair::ClassMethods do
|
6
|
+
subject(:builder) { builder_class.new(dummy_class, options) }
|
7
|
+
|
8
|
+
let(:options) { {} }
|
9
|
+
let(:instance) { dummy_class.new }
|
10
|
+
let(:dummy_class) { Class.new }
|
11
|
+
let(:builder_class) { Sinclair }
|
12
|
+
|
13
|
+
describe '#build' do
|
14
|
+
let(:block) do
|
15
|
+
method_name = :some_method
|
16
|
+
value = 1
|
17
|
+
|
18
|
+
proc do
|
19
|
+
add_method(method_name) { value }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'executes the block and builds' do
|
24
|
+
expect { builder_class.build(dummy_class, options, &block) }
|
25
|
+
.to add_method(:some_method).to(dummy_class)
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'when the method is built and called' do
|
29
|
+
before do
|
30
|
+
builder_class.build(dummy_class, options, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the value' do
|
34
|
+
expect(instance.some_method).to eq(1)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -22,6 +22,17 @@ describe Sinclair::MethodDefinition::ParameterHelper do
|
|
22
22
|
.to eq(['a = 10', 'b = "word"', 'c = true', 'd = false', 'e = nil', 'f = :symbol'])
|
23
23
|
end
|
24
24
|
end
|
25
|
+
|
26
|
+
context 'when the parameter is an undefined parameter' do
|
27
|
+
let(:parameters) do
|
28
|
+
[:a, :b, '*args', { c: 10, d: 'word' }]
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns a list of parameters' do
|
32
|
+
expect(described_class.parameters_from(parameters))
|
33
|
+
.to eq(['a', 'b', 'c = 10', 'd = "word"', '*args'])
|
34
|
+
end
|
35
|
+
end
|
25
36
|
end
|
26
37
|
|
27
38
|
context 'when parameters are named' do
|
@@ -42,6 +53,17 @@ describe Sinclair::MethodDefinition::ParameterHelper do
|
|
42
53
|
.to eq(['a: 10', 'b: "word"', 'c: true', 'd: false', 'e: nil', 'f: :symbol'])
|
43
54
|
end
|
44
55
|
end
|
56
|
+
|
57
|
+
context 'when the parameter is an undefined parameter' do
|
58
|
+
let(:parameters) do
|
59
|
+
[:a, :b, '**opts', { c: 10, d: 'word' }]
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'returns a list of parameters' do
|
63
|
+
expect(described_class.parameters_from(parameters, named: true))
|
64
|
+
.to eq(['a:', 'b:', 'c: 10', 'd: "word"', '**opts'])
|
65
|
+
end
|
66
|
+
end
|
45
67
|
end
|
46
68
|
end
|
47
69
|
end
|
@@ -54,6 +54,37 @@ describe Sinclair::Model do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
context 'when class is subclass of another model' do
|
58
|
+
subject(:model) { klass.new(name: name, age: age) }
|
59
|
+
|
60
|
+
let(:age) { Random.rand(10..20) }
|
61
|
+
|
62
|
+
let(:superclass) do
|
63
|
+
Class.new(described_class) do
|
64
|
+
initialize_with(:age)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
let(:klass) do
|
69
|
+
Class.new(superclass) do
|
70
|
+
initialize_with(:name)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'is initialized with both attributes' do
|
75
|
+
expect { klass.new(name: name, age: age) }
|
76
|
+
.not_to raise_error
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'is initializes new attributes' do
|
80
|
+
expect(model.name).to eq(name)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'is initializes old attributes' do
|
84
|
+
expect(model.age).to eq(age)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
57
88
|
context 'when the build is done' do
|
58
89
|
before do
|
59
90
|
klass.initialize_with(*attributes, **options)
|
@@ -5,15 +5,13 @@ class HttpJsonModel
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def parse(attribute, path: [])
|
8
|
-
builder = Sinclair.new(self)
|
9
|
-
|
10
8
|
keys = (path + [attribute]).map(&:to_s)
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
Sinclair.build(self) do
|
11
|
+
add_method(attribute) do
|
12
|
+
keys.inject(hash) { |h, key| h[key] }
|
13
|
+
end
|
14
14
|
end
|
15
|
-
|
16
|
-
builder.build
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
data/spec/support/models/tv.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinclair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.14.
|
4
|
+
version: 1.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DarthJee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,14 +28,14 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 2.3.25
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.3.25
|
41
41
|
- !ruby/object:Gem::Dependency
|
@@ -261,6 +261,7 @@ files:
|
|
261
261
|
- ".rubocop.yml"
|
262
262
|
- ".rubocop_todo.yml"
|
263
263
|
- Dockerfile
|
264
|
+
- Dockerfile.circleci
|
264
265
|
- Gemfile
|
265
266
|
- LICENSE
|
266
267
|
- README.md
|
@@ -272,6 +273,7 @@ files:
|
|
272
273
|
- config/yardstick.yml
|
273
274
|
- docker-compose.yml
|
274
275
|
- lib/sinclair.rb
|
276
|
+
- lib/sinclair/class_methods.rb
|
275
277
|
- lib/sinclair/comparable.rb
|
276
278
|
- lib/sinclair/comparable/class_methods.rb
|
277
279
|
- lib/sinclair/config.rb
|
@@ -316,6 +318,7 @@ files:
|
|
316
318
|
- lib/sinclair/method_definitions.rb
|
317
319
|
- lib/sinclair/model.rb
|
318
320
|
- lib/sinclair/model/builder.rb
|
321
|
+
- lib/sinclair/model/builder_options.rb
|
319
322
|
- lib/sinclair/options.rb
|
320
323
|
- lib/sinclair/options/builder.rb
|
321
324
|
- lib/sinclair/options/class_methods.rb
|
@@ -336,6 +339,7 @@ files:
|
|
336
339
|
- spec/integration/yard/my_builder_spec.rb
|
337
340
|
- spec/integration/yard/sinclair/add_class_method_spec.rb
|
338
341
|
- spec/integration/yard/sinclair/add_method_spec.rb
|
342
|
+
- spec/integration/yard/sinclair/class_methods/build_spec.rb
|
339
343
|
- spec/integration/yard/sinclair/comparable_spec.rb
|
340
344
|
- spec/integration/yard/sinclair/config_builder_spec.rb
|
341
345
|
- spec/integration/yard/sinclair/config_class_spec.rb
|
@@ -357,6 +361,7 @@ files:
|
|
357
361
|
- spec/integration/yard/sinclair/options_parser_spec.rb
|
358
362
|
- spec/integration/yard/sinclair/options_spec.rb
|
359
363
|
- spec/integration/yard/sinclair_spec.rb
|
364
|
+
- spec/lib/sinclair/class_methods_spec.rb
|
360
365
|
- spec/lib/sinclair/comparable_spec.rb
|
361
366
|
- spec/lib/sinclair/config/methods_builder_spec.rb
|
362
367
|
- spec/lib/sinclair/config_builder_spec.rb
|
@@ -468,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
468
473
|
- !ruby/object:Gem::Version
|
469
474
|
version: '0'
|
470
475
|
requirements: []
|
471
|
-
rubygems_version: 3.
|
476
|
+
rubygems_version: 3.1.2
|
472
477
|
signing_key:
|
473
478
|
specification_version: 4
|
474
479
|
summary: Gem for easy concern creation
|