pure-struct 1.0.0 → 1.0.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: eace9d9756ad91444d1bf732bd2ac036e4b728a7b5fa1814f69a74cc416ae187
4
- data.tar.gz: 066df3b27a861b53aa452c43ddd7197c7472003b46399b7a6d74efe21365035a
3
+ metadata.gz: 62640381beae69f1f6332211fa9569853d48822e84c6c243b81d49312f059cb6
4
+ data.tar.gz: 70cb2eeb0153967d2864594ebdf504ee31014f6c9e7da8d733eb1f6b7a51b1b0
5
5
  SHA512:
6
- metadata.gz: ef02fadf4e5e2689a6a8821fc9decc207193ddd8173036b582c37d3e6a9d30a636ec0d1694bc7bae4d6b6887534df1939b571ce9e1e244d02fb4cb615712a8b6
7
- data.tar.gz: 43ade6064f84f4904023e571e9559762b04fa101ccad842c47e58af964cf363430d27eb1b37a509a4f719f6ed705100e4b8720eadb6d5d8f9f4dfcf5a464eab7
6
+ metadata.gz: 407a0c254b2b8178e11626d73f64f6fc7ba31b1d27ba7e4157029073d543dba3fdf98e2ccf1c3a8ed97ba278b8f77ce729c736ff90cd2fd729e1994d425ab00e
7
+ data.tar.gz: 174c6340a217b17904fa37e44747929f8d87fa1a3aac81d1da1d546aa0ad33b570eb564b7e4503dd254ba1aa2e15d47dbe94cc7921b22e4ea3dae76af1191ea5
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.0.1
4
+
5
+ - Include `Enumerable` just as in native `Struct`
6
+ - Fix issue with `Struct.new` first attribute interpreted as a class name due to Opal implementing Symbols as Strings
7
+ - Fix issue with String#hash implementation in Opal returning a String instead of an Integer
8
+
3
9
  ## 1.0.0
4
10
 
5
11
  - Pure Ruby re-implementation of Struct
data/README.md CHANGED
@@ -22,7 +22,7 @@ Run:
22
22
  Or add to [Gemfile](https://bundler.io/man/gemfile.5.html):
23
23
 
24
24
  ```ruby
25
- gem 'pure-struct', '~> 1.0.0'
25
+ gem 'pure-struct', '~> 1.0.1'
26
26
  ```
27
27
 
28
28
  And, run:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -24,6 +24,8 @@ Object.send(:remove_const, :Struct) if Object.constants.include?(:Struct)
24
24
 
25
25
  # Optional re-implmentation of Struct in Pure Ruby (to get around JS issues in Opal Struct)
26
26
  class Struct
27
+ include Enumerable
28
+
27
29
  class << self
28
30
  CLASS_DEFINITION_FOR_ATTRIBUTES = lambda do |attributes, keyword_init|
29
31
  lambda do |defined_class|
@@ -93,10 +95,17 @@ class Struct
93
95
  end
94
96
 
95
97
  def hash
96
- self.class.hash +
97
- to_a.each_with_index.map {|value, i| (i+1) * value.hash}.sum
98
+ if RUBY_ENGINE == 'opal'
99
+ # Opal doesn't implement hash as Integer everywhere, returning strings as themselves,
100
+ # so build a String everywhere for now as the safest common denominator to be consistent.
101
+ self.class.hash.to_s +
102
+ to_a.each_with_index.map {|value, i| (i+1).to_s + value.hash.to_s}.reduce(:+)
103
+ else
104
+ self.class.hash +
105
+ to_a.each_with_index.map {|value, i| i+1 * value.hash}.sum
106
+ end
98
107
  end
99
-
108
+
100
109
  if keyword_init
101
110
  def initialize(struct_class_keyword_args = {})
102
111
  members
@@ -123,18 +132,20 @@ class Struct
123
132
  end
124
133
 
125
134
  CLASS_NAME_EXTRACTION = lambda do |class_name_or_attribute|
126
- if class_name_or_attribute.is_a?(String)
135
+ if class_name_or_attribute.is_a?(String) && RUBY_ENGINE != 'opal'
127
136
  raise NameError, "identifier name needs to be constant" unless class_name_or_attribute.match(/^[A-Z]/)
128
137
  class_name_or_attribute
129
138
  end
130
139
  end
131
140
 
141
+ alias __new__ new
132
142
  def new(class_name_or_attribute, *attributes, keyword_init: false)
133
143
  raise 'Arguments cannot be nil' if ARG_VALIDATION[class_name_or_attribute, *attributes]
134
144
  class_name = CLASS_NAME_EXTRACTION[class_name_or_attribute]
135
145
  attributes.unshift(class_name_or_attribute) if class_name.nil?
136
146
  attributes = attributes.map(&:to_sym)
137
- struct_class = Class.new(&CLASS_DEFINITION_FOR_ATTRIBUTES[attributes, keyword_init])
147
+ struct_class = Class.new(self, &CLASS_DEFINITION_FOR_ATTRIBUTES[attributes, keyword_init])
148
+ struct_class.singleton_class.define_method(:new) {|*args, &block| __new__(*args, &block)}
138
149
  class_name.nil? ? struct_class : const_set(class_name, struct_class)
139
150
  end
140
151
 
@@ -0,0 +1,57 @@
1
+ # Generated by juwelier
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: pure-struct 1.0.1 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "pure-struct".freeze
9
+ s.version = "1.0.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Andy Maleh".freeze]
14
+ s.date = "2021-01-09"
15
+ s.description = "Pure Ruby re-implementation of Struct to ensure cross-Ruby functionality where needed (e.g. Opal)".freeze
16
+ s.email = "andy.am@gmail.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "CHANGELOG.md",
19
+ "LICENSE.txt",
20
+ "README.md"
21
+ ]
22
+ s.files = [
23
+ "CHANGELOG.md",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "VERSION",
27
+ "lib/pure-struct.rb",
28
+ "pure-struct.gemspec"
29
+ ]
30
+ s.homepage = "http://github.com/AndyObtiva/pure-struct".freeze
31
+ s.licenses = ["MIT".freeze]
32
+ s.rubygems_version = "3.1.4".freeze
33
+ s.summary = "Pure Ruby Re-Implementation of Struct".freeze
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 4
37
+ end
38
+
39
+ if s.respond_to? :add_runtime_dependency then
40
+ s.add_development_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
41
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
42
+ s.add_development_dependency(%q<bundler>.freeze, [">= 1.0"])
43
+ s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
44
+ s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.16.0"])
45
+ s.add_development_dependency(%q<coveralls>.freeze, [">= 0"])
46
+ s.add_development_dependency(%q<puts_debuggerer>.freeze, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<rspec>.freeze, ["~> 3.5.0"])
49
+ s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
50
+ s.add_dependency(%q<bundler>.freeze, [">= 1.0"])
51
+ s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
52
+ s.add_dependency(%q<simplecov>.freeze, ["~> 0.16.0"])
53
+ s.add_dependency(%q<coveralls>.freeze, [">= 0"])
54
+ s.add_dependency(%q<puts_debuggerer>.freeze, [">= 0"])
55
+ end
56
+ end
57
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pure-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
11
+ date: 2021-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -123,6 +123,7 @@ files:
123
123
  - README.md
124
124
  - VERSION
125
125
  - lib/pure-struct.rb
126
+ - pure-struct.gemspec
126
127
  homepage: http://github.com/AndyObtiva/pure-struct
127
128
  licenses:
128
129
  - MIT