From d59f31a3c63c7642fe2d3eb50b785da54fdabfab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 8 Mar 2023 10:28:46 +0700 Subject: [PATCH] Make code compatible with Ruby 2.7 Not including specs etc. --- lib/nostr/client.rb | 2 +- lib/nostr/errors/invalid_key_type_error.rb | 4 +++- lib/nostr/event.rb | 22 +++++++++++++--------- lib/nostr/filter.rb | 10 +++++----- lib/nostr/key.rb | 4 +++- lib/nostr/keygen.rb | 4 ++-- lib/nostr/user.rb | 8 ++++---- nostr.gemspec | 2 +- 8 files changed, 32 insertions(+), 24 deletions(-) diff --git a/lib/nostr/client.rb b/lib/nostr/client.rb index d5aaa3e..c0c0f75 100644 --- a/lib/nostr/client.rb +++ b/lib/nostr/client.rb @@ -81,7 +81,7 @@ module Nostr # @return [Subscription] The subscription object # def subscribe(subscription_id: SecureRandom.hex, filter: Filter.new) - subscriptions[subscription_id] = Subscription.new(id: subscription_id, filter:) + subscriptions[subscription_id] = Subscription.new(id: subscription_id, filter: filter) parent_to_child_channel.push([ClientMessageType::REQ, subscription_id, filter.to_h].to_json) subscriptions[subscription_id] end diff --git a/lib/nostr/errors/invalid_key_type_error.rb b/lib/nostr/errors/invalid_key_type_error.rb index 82a2f0f..762a549 100644 --- a/lib/nostr/errors/invalid_key_type_error.rb +++ b/lib/nostr/errors/invalid_key_type_error.rb @@ -13,6 +13,8 @@ module Nostr # # @param [String] key_kind The kind of key that is invalid (public or private) # - def initialize(key_kind) = super("Invalid #{key_kind} key type") + def initialize(key_kind) + super("Invalid #{key_kind} key type") + end end end diff --git a/lib/nostr/event.rb b/lib/nostr/event.rb index 6448b52..8a0ec6c 100644 --- a/lib/nostr/event.rb +++ b/lib/nostr/event.rb @@ -149,7 +149,9 @@ module Nostr # # @return [Array] The event's updated list of tags # - def add_event_reference(event_id) = tags.push(['e', event_id]) + def add_event_reference(event_id) + tags.push(['e', event_id]) + end # Adds a reference to a pubkey as a 'p' tag # @@ -163,7 +165,9 @@ module Nostr # # @return [Array] The event's updated list of tags # - def add_pubkey_reference(pubkey) = tags.push(['p', pubkey.to_s]) + def add_pubkey_reference(pubkey) + tags.push(['p', pubkey.to_s]) + end # Signs an event with the user's private key # @@ -212,13 +216,13 @@ module Nostr # def to_h { - id:, - pubkey:, - created_at:, - kind:, - tags:, - content:, - sig: + id: id, + pubkey: pubkey, + created_at: created_at, + kind: kind, + tags: tags, + content: content, + sig: sig } end diff --git a/lib/nostr/filter.rb b/lib/nostr/filter.rb index 40f9190..9b4af50 100644 --- a/lib/nostr/filter.rb +++ b/lib/nostr/filter.rb @@ -148,14 +148,14 @@ module Nostr # def to_h { - ids:, - authors:, - kinds:, + ids: ids, + authors: authors, + kinds: kinds, '#e': e, '#p': p, - since:, + since: since, until: self.until, - limit: + limit: limit }.compact end diff --git a/lib/nostr/key.rb b/lib/nostr/key.rb index ba0946b..7a1a73a 100644 --- a/lib/nostr/key.rb +++ b/lib/nostr/key.rb @@ -79,7 +79,9 @@ module Nostr # # @return [String] The bech32 string representation of the key # - def to_bech32 = Bech32.encode(hrp: self.class.hrp, data: self) + def to_bech32 + Bech32.encode(hrp: self.class.hrp, data: self) + end protected diff --git a/lib/nostr/keygen.rb b/lib/nostr/keygen.rb index 761e5fd..92cf03a 100644 --- a/lib/nostr/keygen.rb +++ b/lib/nostr/keygen.rb @@ -33,7 +33,7 @@ module Nostr private_key = generate_private_key public_key = extract_public_key(private_key) - KeyPair.new(private_key:, public_key:) + KeyPair.new(private_key: private_key, public_key: public_key) end # Generates a private key @@ -89,7 +89,7 @@ module Nostr def get_key_pair_from_private_key(private_key) validate_private_key(private_key) public_key = extract_public_key(private_key) - KeyPair.new(private_key:, public_key:) + KeyPair.new(private_key: private_key, public_key: public_key) end private diff --git a/lib/nostr/user.rb b/lib/nostr/user.rb index 0015137..f9cb505 100644 --- a/lib/nostr/user.rb +++ b/lib/nostr/user.rb @@ -62,10 +62,10 @@ module Nostr ) event = Event.new( pubkey: keypair.public_key, - kind:, - content:, - created_at:, - tags: + kind: kind, + content: content, + created_at: created_at, + tags: tags ) event.sign(keypair.private_key) end diff --git a/nostr.gemspec b/nostr.gemspec index 6acdb6a..2c27e21 100644 --- a/nostr.gemspec +++ b/nostr.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.description = 'Client and relay implementation of the Nostr protocol.' spec.homepage = 'https://nostr-ruby.com/' spec.license = 'MIT' - spec.required_ruby_version = '>= 3.2.0' + spec.required_ruby_version = '>= 2.7.2' spec.metadata['rubygems_mfa_required'] = 'true' spec.metadata['homepage_uri'] = spec.homepage