sinclair 1.14.0 → 1.14.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
  SHA256:
3
- metadata.gz: 6ee09cd280144bc873d89c0272856bf716e0a20c2ca5d3f7fe8bf11ac972c859
4
- data.tar.gz: c5107aa15ffab29f4dd14b45efd0387913c60064ad62a58c4ec85adb09d91c9c
3
+ metadata.gz: 4984ad62935fbe5a85e51b846b5124b72153b94cf9433a8a668f824c11e5eeaf
4
+ data.tar.gz: 336e7c54378ccd676f59eb92fe2a1bf32de84ff9a8bc2a91c8a6dd1e6494b46d
5
5
  SHA512:
6
- metadata.gz: 38994db2d8a69ef1b9f3827a84bcb53a0bd18e2073a4840b004a89ac00a0fe0f5d9a8a69ce231b9d6c5f2cfc51b3a96c5ee898c848ce7ba802eac1d8556a058b
7
- data.tar.gz: 4812c5a5793de217eb0cdd895c8cc94ac698af119c60fded29ea6929bddf0240b9dbcdba237dba7c1f060a3c3b8a3a173d2c7fef0509f6181d738ca0c7f0ef34
6
+ metadata.gz: f3a84c2a80644b15e31991cb99a314378453e642c29c9864080e96f28bd34234f2476735284291ba56dd48ab9d67883a5b16709a1aa67b31116ef262dd6b1df1
7
+ data.tar.gz: d1405b56826158314eb4d304b33c02dc18015e63fe58e716371f5a58c7a8f417652ea1026d5b533c844e7c5a89ffeae7990f70334e61dbf4019006f412359dfe
@@ -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
  ![sinclair](https://raw.githubusercontent.com/darthjee/sinclair/master/sinclair.jpg)
11
11
 
12
- This gem helps the creation of complex gems/concerns
13
- that enables creation of methods on the fly through class
14
- methods
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
- Current Release: [1.14.0](https://github.com/darthjee/sinclair/tree/1.14.0)
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
- [Next release](https://github.com/darthjee/sinclair/compare/1.14.0...master)
18
+ Current Release: [1.14.1](https://github.com/darthjee/sinclair/tree/1.14.1)
19
+
20
+ [Next release](https://github.com/darthjee/sinclair/compare/1.14.1...master)
19
21
 
20
22
  Yard Documentation
21
23
  -------------------
22
- [https://www.rubydoc.info/gems/sinclair/1.14.0](https://www.rubydoc.info/gems/sinclair/1.14.0)
24
+ [https://www.rubydoc.info/gems/sinclair/1.14.1](https://www.rubydoc.info/gems/sinclair/1.14.1)
23
25
 
24
26
  Installation
25
27
  ---------------
@@ -524,8 +526,16 @@ Client.config.url # returns 'http://interstella.com:8080'
524
526
 
525
527
  ### Sinclair::EnvSettable
526
528
 
527
- Settable allows classes to extract configuration from environments through
528
- a simple meta-programable way
529
+ EnvSettable is a convenient utility that allows you to read environment
530
+ variables using Ruby class methods.
531
+
532
+ With this tool, you can define the usage of environment variables for your application in a single location
533
+ allowing the use of prefixes to isolate groups of variables.
534
+
535
+ This not only makes your code more readable and maintainable but also adds layer of security by ensuring
536
+ that sensitive information like API keys and passwords are not exposed in your source code.
537
+
538
+ EnvSettable allows accessing those variables thorugh a simple meta-programable way
529
539
 
530
540
  <details>
531
541
  <summary>Using env settable example</summary>
@@ -645,7 +655,8 @@ human1 == human2 # returns true
645
655
  <summary>Example with options</summary>
646
656
 
647
657
  ```ruby
648
- class Tv < Sinclair::Model.for(:model, writter: false, comparable: false)
658
+ class Tv < Sinclair::Model
659
+ initialize_with :model, writter: false, comparable: false
649
660
  end
650
661
 
651
662
  tv1 = Tv.new(model: 'Sans Sunga Xt')
@@ -7,4 +7,5 @@ ignore:
7
7
  - lib/sinclair/matchers/base.rb
8
8
  - lib/sinclair/matchers/change_method_on.rb
9
9
  - lib/sinclair/matchers/method_to.rb
10
+ - lib/sinclair/model/builder_options.rb
10
11
  - lib/sinclair/version.rb
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
@@ -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: false)
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, writter: true, comparable: true)
29
+ def initialize(klass, *attributes, **options)
30
30
  super(klass)
31
31
  @attributes = attributes.flatten
32
- @writter = writter
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, :writter, :comparable
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
- code = attributes_names.map do |attr|
130
+ lines = attributes_names.map do |attr|
122
131
  "@#{attr} = #{attr}"
123
- end.join("\n")
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
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Sinclair
4
+ class Model
5
+ # @api private
6
+ # @author Darthjee
7
+ #
8
+ # Options for building model class
9
+ class BuilderOptions < Sinclair::Options
10
+ with_options writter: true, comparable: true
11
+ end
12
+ end
13
+ end
@@ -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, 'sinclair/model/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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Sinclair
4
- VERSION = '1.14.0'
4
+ VERSION = '1.14.1'
5
5
  end
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'
@@ -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)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Tv < Sinclair::Model.for(:model, writter: false, comparable: false)
3
+ class Tv < Sinclair::Model
4
+ initialize_with :model, writter: false, comparable: false
4
5
  end
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.0
4
+ version: 1.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DarthJee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-16 00:00:00.000000000 Z
11
+ date: 2023-04-25 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
@@ -316,6 +317,7 @@ files:
316
317
  - lib/sinclair/method_definitions.rb
317
318
  - lib/sinclair/model.rb
318
319
  - lib/sinclair/model/builder.rb
320
+ - lib/sinclair/model/builder_options.rb
319
321
  - lib/sinclair/options.rb
320
322
  - lib/sinclair/options/builder.rb
321
323
  - lib/sinclair/options/class_methods.rb
@@ -468,7 +470,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
468
470
  - !ruby/object:Gem::Version
469
471
  version: '0'
470
472
  requirements: []
471
- rubygems_version: 3.3.25
473
+ rubygems_version: 3.1.2
472
474
  signing_key:
473
475
  specification_version: 4
474
476
  summary: Gem for easy concern creation