fast_ostruct 1.0.1 → 1.1.0

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: 8e01f31074bbe28459762b9c683d411b6449a1e4ae5e229bcfb6b31f47d5c462
4
- data.tar.gz: 17871acbf4b3d78aad9e170e2029820a232ef266ad077f0f525a36b77724bbd0
3
+ metadata.gz: 46b3703a02825829511af5040efa372482bdde0ea0df6ed66e3cd547ead5db37
4
+ data.tar.gz: e172571b4121f06c48a8042f1207c76734fadf9c80d41570798eb5eae668fb38
5
5
  SHA512:
6
- metadata.gz: 6657426960492212688eb4976f0f81ab6404bb6e078d29c6b9eebe7fdbcbfe8299572f869b8df8b7dad2796b7e607a3989d12f240bb4ff82764d34e2e18a0e2d
7
- data.tar.gz: 21564c9d519e0d53faaf5b0e7b136e43fafc8364da2e1828dd7809b8325fe86ae2169a3ee5cfa575a44299f23c4eb7429d4c20b475d9bce4ae00bc83031813c9
6
+ metadata.gz: 38f59dfe9385fd2d596520255a9db8a24997b16e947c117ccc827dc2fbd2c867f264a7e1870ff2dbd92f2c11e69949bfc95bbd2962e97b819680d1defbcb2fbb
7
+ data.tar.gz: 06db7c8fa97ad0c0f8d64dc8c2576ad8cefdfcb3c3e46df48295ab1af2355046c750c55477a08882a2e3592f07f1bf553213ba6efa71c03bd45b8b1ff7c55df4
data/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.1.0] - 2023-08-16
11
+
12
+ ### Added
13
+
14
+ - Configuration file
15
+ - Changelog file
16
+ - New method `slice` to slice attributes from FastOpenStruct
17
+
18
+ ### Fixed
19
+
20
+ - Fixed bug when using `save` method with attributes (it happens when using as FactoryBot class). Thanks to [Andre Cesar Gomes](https://github.com/andrecego) for reporting this issue.
21
+
22
+ ### Changed
23
+
24
+ - Readme file updated with new features documentation
25
+
26
+ ### Removed
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
data/Gemfile CHANGED
@@ -3,4 +3,15 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in fast_open_struct.gemspec.
6
+
7
+ group :development, :test do
8
+ gem 'benchmark-ips', '>= 2'
9
+ gem 'pry', '>= 0.14'
10
+ gem 'rack-test', '~> 1.1'
11
+ gem 'rake', '~> 13.0'
12
+ gem 'rspec', '~> 3.0'
13
+ gem 'rubocop', '~> 1.25'
14
+ gem 'rubocop-performance', '~> 1.15'
15
+ end
16
+
6
17
  gemspec
data/README.md CHANGED
@@ -56,6 +56,19 @@ my_struct['lastname'] # => 'Connor'
56
56
  my_struct.dig(:age) # => 30
57
57
  ```
58
58
 
59
+ ## Configuration
60
+
61
+ Create an initializer file and add the following code:
62
+ ```ruby
63
+ FastOpenStruct.configure do |config|
64
+ # default: true | it will make a deep initialization of the attributes, converting Hash to FastOpenStruct
65
+ config.initialize_options = { deep_initialize: true }
66
+
67
+ # default: false | if true, it will symbolize the keys of the attributes
68
+ config.attributes_options = { symbolize_keys: false }
69
+ end
70
+ ```
71
+
59
72
  ## Benchmarks
60
73
  ```
61
74
  Initialization benchmark
data/fast_ostruct.gemspec CHANGED
@@ -24,14 +24,6 @@ Gem::Specification.new do |spec|
24
24
  end
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_development_dependency 'benchmark-ips', '>= 2'
28
- spec.add_development_dependency 'pry', '>= 0.14'
29
- spec.add_development_dependency 'rack-test', '~> 1.1'
30
- spec.add_development_dependency 'rake', '~> 13.0'
31
- spec.add_development_dependency 'rspec', '~> 3.0'
32
- spec.add_development_dependency 'rubocop', '~> 1.25'
33
- spec.add_development_dependency 'rubocop-performance', '~> 1.15'
34
-
35
27
  spec.add_dependency 'json', '>= 2'
36
28
 
37
29
  spec.metadata['rubygems_mfa_required'] = 'true'
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FastOpenStruct
4
+ class Config
5
+ attr_accessor :initialize_options, :attributes_options
6
+
7
+ def initialize
8
+ @initialize_options = { deep_initialize: true }
9
+ @attributes_options = { symbolize_keys: false }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FastOpenStruct
4
+ VERSION = '1.1.0'
5
+ end
data/lib/fast_ostruct.rb CHANGED
@@ -2,14 +2,25 @@
2
2
 
3
3
  require 'json'
4
4
  require 'set'
5
+ require_relative 'fast_ostruct/config'
6
+ require_relative 'fast_ostruct/version'
5
7
 
6
8
  class FastOpenStruct
7
- VERSION = '1.0.1'
9
+ class << self
10
+ def configure
11
+ yield config
12
+ end
13
+
14
+ def config
15
+ @config ||= Config.new
16
+ end
17
+ end
8
18
 
9
- INITIALIZE_OPTIONS = { deep_initialize: true }.freeze
10
- ATTRIBUTES_OPTIONS = { symbolize_keys: false }.freeze
19
+ def config
20
+ self.class.config
21
+ end
11
22
 
12
- def initialize(attributes = {}, options = INITIALIZE_OPTIONS)
23
+ def initialize(attributes = {}, options = config.initialize_options)
13
24
  if options[:deep_initialize]
14
25
  attributes.except(*options.keys).each_pair do |name, value|
15
26
  self[name] = deep_initialize(value, options)
@@ -21,7 +32,7 @@ class FastOpenStruct
21
32
  end
22
33
  end
23
34
 
24
- def attributes(options = ATTRIBUTES_OPTIONS)
35
+ def attributes(options = config.attributes_options)
25
36
  key_formatter = if options[:symbolize_keys]
26
37
  proc { |name| name.to_sym }
27
38
  else
@@ -61,6 +72,11 @@ class FastOpenStruct
61
72
  attributes(symbolize_keys: true).dig(name, *identifiers)
62
73
  end
63
74
 
75
+ def slice(*names)
76
+ names.map!(&:to_sym)
77
+ attributes(symbolize_keys: true).slice(*names)
78
+ end
79
+
64
80
  def delete_field(name)
65
81
  attribute_unset(name)
66
82
  end
@@ -79,7 +95,7 @@ class FastOpenStruct
79
95
  false
80
96
  end
81
97
 
82
- def save
98
+ def save(*)
83
99
  self
84
100
  end
85
101
 
@@ -113,7 +129,7 @@ class FastOpenStruct
113
129
  end
114
130
  end
115
131
 
116
- def deep_initialize(value, options = INITIALIZE_OPTIONS)
132
+ def deep_initialize(value, options = config.initialize_options)
117
133
  if value.is_a?(Array)
118
134
  value = value.map { |v| v.is_a?(Hash) ? self.class.new(v, options) : v }
119
135
  elsif value.is_a?(Hash)
metadata CHANGED
@@ -1,113 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_ostruct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: benchmark-ips
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '2'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '2'
27
- - !ruby/object:Gem::Dependency
28
- name: pry
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0.14'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0.14'
41
- - !ruby/object:Gem::Dependency
42
- name: rack-test
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '13.0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '13.0'
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.25'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.25'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-performance
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.15'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '1.15'
111
13
  - !ruby/object:Gem::Dependency
112
14
  name: json
113
15
  requirement: !ruby/object:Gem::Requirement
@@ -134,6 +36,7 @@ files:
134
36
  - ".rspec"
135
37
  - ".rubocop.yml"
136
38
  - ".ruby-version"
39
+ - CHANGELOG.md
137
40
  - Gemfile
138
41
  - LICENSE
139
42
  - README.md
@@ -142,6 +45,8 @@ files:
142
45
  - bin/setup
143
46
  - fast_ostruct.gemspec
144
47
  - lib/fast_ostruct.rb
48
+ - lib/fast_ostruct/config.rb
49
+ - lib/fast_ostruct/version.rb
145
50
  - lib/tasks/benchmark.rake
146
51
  homepage: https://github.com/w-osilva/fast_ostruct
147
52
  licenses: