ryo.rb 0.5.3 → 0.5.5
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/.github/workflows/specs.yml +2 -2
- data/README.md +6 -7
- data/Rakefile.rb +13 -0
- data/lib/ryo/reflect.rb +2 -2
- data/lib/ryo/version.rb +1 -1
- data/lib/ryo/yaml.rb +45 -0
- data/ryo.rb.gemspec +1 -0
- data/spec/ryo_json_spec.rb +31 -13
- data/spec/ryo_yaml_spec.rb +44 -0
- metadata +6 -4
- data/.gitlab-ci.yml +0 -9
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c611c0e990fe0cdfd09ede551e1b457e93af7765de379d64b5dbdf6495e2b766
         | 
| 4 | 
            +
              data.tar.gz: 24406b552991b2459da63847ff4b65071eb2e03cd846956e4a030f506fd5b908
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 28dca6bc48b5aab85c3e08698a60e460142114623b3f914db25bbe83fa767cdd70bcb8bb4bf68d07188cc884840d696cbba81b96683d10a690d939979e0f5dfc
         | 
| 7 | 
            +
              data.tar.gz: 325e58af48dc0cc6e85344ecedc006b6b331a2011432bc76069c374288bd676d2d918eee9807ee0194e8d2e31c0fe1dcbeda38b9c6a0f8982a1ea26ca0588457
         | 
    
        data/.github/workflows/specs.yml
    CHANGED
    
    | @@ -12,7 +12,7 @@ jobs: | |
| 12 12 | 
             
                  fail-fast: false
         | 
| 13 13 | 
             
                  matrix:
         | 
| 14 14 | 
             
                    os: [ubuntu-latest]
         | 
| 15 | 
            -
                    ruby: [3. | 
| 15 | 
            +
                    ruby: [3.2, 3.3]
         | 
| 16 16 | 
             
                runs-on: ${{ matrix.os }}
         | 
| 17 17 | 
             
                steps:
         | 
| 18 18 | 
             
                - uses: actions/checkout@v2
         | 
| @@ -20,4 +20,4 @@ jobs: | |
| 20 20 | 
             
                  with:
         | 
| 21 21 | 
             
                    ruby-version: ${{ matrix.ruby }}
         | 
| 22 22 | 
             
                - run: bundle install
         | 
| 23 | 
            -
                - run:  | 
| 23 | 
            +
                - run: rake ci
         | 
    
        data/README.md
    CHANGED
    
    | @@ -301,17 +301,16 @@ p ryo.then { 34 } # => 34 | |
| 301 301 | 
             
            #### Duck typing
         | 
| 302 302 |  | 
| 303 303 | 
             
            The documentation has used simple terms to describe the objects that Ryo works
         | 
| 304 | 
            -
            with: Hash and Array objects. But  | 
| 305 | 
            -
            that implements `#each_pair`  | 
| 306 | 
            -
            implements `#each`  | 
| 304 | 
            +
            with: Hash and Array objects. But that doesn't quite capture the fact that Ryo
         | 
| 305 | 
            +
            uses duck typing: any object that implements `#each_pair` is similar to a Hash,
         | 
| 306 | 
            +
            and any object that implements `#each` is similar to an Array. Note that only
         | 
| 307 307 | 
             
            [Ryo.from](https://0x1eef.github.io/x/ryo.rb/Ryo.html#from-class_method),
         | 
| 308 308 | 
             
            [Ryo::Object.from](https://0x1eef.github.io/x/ryo.rb/Ryo/Object.html#from-class_method)
         | 
| 309 309 | 
             
            and
         | 
| 310 310 | 
             
            [Ryo::BasicObject.from](https://0x1eef.github.io/x/ryo.rb/Ryo/BasicObject.html#from-class_method)
         | 
| 311 | 
            -
            can handle Array | 
| 311 | 
            +
            can handle Array-like objects.
         | 
| 312 312 |  | 
| 313 | 
            -
             | 
| 314 | 
            -
            `#each_pair`, into a Ryo object:
         | 
| 313 | 
            +
            The following example implements `#each_pair`:
         | 
| 315 314 |  | 
| 316 315 | 
             
            ``` ruby
         | 
| 317 316 | 
             
            require "ryo"
         | 
| @@ -353,7 +352,7 @@ Ryo can be installed via rubygems.org: | |
| 353 352 |  | 
| 354 353 | 
             
            Thanks to
         | 
| 355 354 | 
             
            [@awfulcooking (mooff)](https://github.com/awfulcooking)
         | 
| 356 | 
            -
            for the helpful discussions | 
| 355 | 
            +
            for the helpful discussions
         | 
| 357 356 |  | 
| 358 357 | 
             
            ## License
         | 
| 359 358 |  | 
    
        data/Rakefile.rb
    ADDED
    
    
    
        data/lib/ryo/reflect.rb
    CHANGED
    
    | @@ -220,9 +220,9 @@ module Ryo::Reflect | |
| 220 220 | 
             
              #
         | 
| 221 221 | 
             
              # @return [::Object, ::BasicObject]
         | 
| 222 222 | 
             
              #  Returns the return value of the method call.
         | 
| 223 | 
            -
              def call_method(ryo, method,  | 
| 223 | 
            +
              def call_method(ryo, method, *, &b)
         | 
| 224 224 | 
             
                kernel(:__send__)
         | 
| 225 | 
            -
                  .bind_call(ryo, method,  | 
| 225 | 
            +
                  .bind_call(ryo, method, *, &b)
         | 
| 226 226 | 
             
              end
         | 
| 227 227 |  | 
| 228 228 | 
             
              ##
         | 
    
        data/lib/ryo/version.rb
    CHANGED
    
    
    
        data/lib/ryo/yaml.rb
    ADDED
    
    | @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            ##
         | 
| 4 | 
            +
            # The {Ryo::YAML Ryo::YAML} module provides a number of methods
         | 
| 5 | 
            +
            # for coercing YAML data into a Ryo object. It must be required
         | 
| 6 | 
            +
            # separately to Ryo (ie: require "ryo/yaml"), and the methods of
         | 
| 7 | 
            +
            # this module are then available on the {Ryo Ryo} module.
         | 
| 8 | 
            +
            module Ryo::YAML
         | 
| 9 | 
            +
              require "yaml"
         | 
| 10 | 
            +
              extend self
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              ##
         | 
| 13 | 
            +
              # @example
         | 
| 14 | 
            +
              #   Ryo.from_yaml(path: "/foo/bar/baz.yaml")
         | 
| 15 | 
            +
              #   Ryo.from_yaml(string: "---\nfoo: bar\n")
         | 
| 16 | 
            +
              #
         | 
| 17 | 
            +
              # @param [String] path
         | 
| 18 | 
            +
              #  The path to a YAML file
         | 
| 19 | 
            +
              #
         | 
| 20 | 
            +
              # @param [String] string
         | 
| 21 | 
            +
              #  A blob of YAML
         | 
| 22 | 
            +
              #
         | 
| 23 | 
            +
              # @param [Ryo] object
         | 
| 24 | 
            +
              #  {Ryo::Object Ryo::Object}, or {Ryo::BasicObject Ryo::BasicObject}
         | 
| 25 | 
            +
              #  Defaults to {Ryo::Object Ryo::Object}
         | 
| 26 | 
            +
              #
         | 
| 27 | 
            +
              # @raise [SystemCallError]
         | 
| 28 | 
            +
              #  Might raise a number of Errno exceptions
         | 
| 29 | 
            +
              #
         | 
| 30 | 
            +
              # @return [Ryo::Object, Ryo::BasicObject]
         | 
| 31 | 
            +
              #  Returns a Ryo object
         | 
| 32 | 
            +
              def from_yaml(path: nil, string: nil, object: Ryo::Object)
         | 
| 33 | 
            +
                if path && string
         | 
| 34 | 
            +
                  raise ArgumentError, "Provide a path or string but not both"
         | 
| 35 | 
            +
                elsif path
         | 
| 36 | 
            +
                  object.from YAML.load_file(path)
         | 
| 37 | 
            +
                elsif string
         | 
| 38 | 
            +
                  object.from YAML.load(string)
         | 
| 39 | 
            +
                else
         | 
| 40 | 
            +
                  raise ArgumentError, "No path or string provided"
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              Ryo.extend(self)
         | 
| 45 | 
            +
            end
         | 
    
        data/ryo.rb.gemspec
    CHANGED
    
    | @@ -12,6 +12,7 @@ Gem::Specification.new do |gem| | |
| 12 12 | 
             
              gem.require_paths = ["lib"]
         | 
| 13 13 | 
             
              gem.description = "Ryo implements prototype-based inheritance, in Ruby"
         | 
| 14 14 | 
             
              gem.summary = gem.description
         | 
| 15 | 
            +
              gem.required_ruby_version = ">= 3.2"
         | 
| 15 16 | 
             
              gem.add_development_dependency "yard", "~> 0.9"
         | 
| 16 17 | 
             
              gem.add_development_dependency "redcarpet", "~> 3.5"
         | 
| 17 18 | 
             
              gem.add_development_dependency "rspec", "~> 3.10"
         | 
    
        data/spec/ryo_json_spec.rb
    CHANGED
    
    | @@ -5,22 +5,40 @@ require "ryo/json" | |
| 5 5 | 
             
            require "fileutils"
         | 
| 6 6 |  | 
| 7 7 | 
             
            RSpec.describe Ryo::JSON do
         | 
| 8 | 
            -
              describe ". | 
| 9 | 
            -
                 | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 8 | 
            +
              describe ".from_json" do
         | 
| 9 | 
            +
                context "with a path" do
         | 
| 10 | 
            +
                  subject(:ryo) { described_class.from_json(path:, object:) }
         | 
| 11 | 
            +
                  before { File.binwrite path, JSON.dump(x: 20, y: 40) }
         | 
| 12 | 
            +
                  after { FileUtils.rm(path) }
         | 
| 13 | 
            +
                  let(:path) { File.join(__dir__, "test.json") }
         | 
| 13 14 |  | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 15 | 
            +
                  context "with Ryo::Object" do
         | 
| 16 | 
            +
                    let(:object) { Ryo::Object }
         | 
| 17 | 
            +
                    it { is_expected.to be_instance_of(Ryo::Object) }
         | 
| 18 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  context "with Ryo::BasicObject" do
         | 
| 22 | 
            +
                    let(:object) { Ryo::BasicObject }
         | 
| 23 | 
            +
                    it { expect(Ryo::BasicObject === ryo).to be(true) }
         | 
| 24 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 25 | 
            +
                  end
         | 
| 18 26 | 
             
                end
         | 
| 19 27 |  | 
| 20 | 
            -
                context "with  | 
| 21 | 
            -
                   | 
| 22 | 
            -
             | 
| 23 | 
            -
                   | 
| 28 | 
            +
                context "with a string" do
         | 
| 29 | 
            +
                  subject(:ryo) { described_class.from_json(string: "{\"x\": 20, \"y\": 40}", object:) }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  context "with Ryo::Object" do
         | 
| 32 | 
            +
                    let(:object) { Ryo::Object }
         | 
| 33 | 
            +
                    it { is_expected.to be_instance_of(Ryo::Object) }
         | 
| 34 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  context "with Ryo::BasicObject" do
         | 
| 38 | 
            +
                    let(:object) { Ryo::BasicObject }
         | 
| 39 | 
            +
                    it { expect(Ryo::BasicObject === ryo).to be(true) }
         | 
| 40 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 41 | 
            +
                  end
         | 
| 24 42 | 
             
                end
         | 
| 25 43 | 
             
              end
         | 
| 26 44 | 
             
            end
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require_relative "setup"
         | 
| 4 | 
            +
            require "ryo/yaml"
         | 
| 5 | 
            +
            require "fileutils"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            RSpec.describe Ryo::YAML do
         | 
| 8 | 
            +
              describe ".from_yaml" do
         | 
| 9 | 
            +
                context "with a path" do
         | 
| 10 | 
            +
                  subject(:ryo) { described_class.from_yaml(path:, object:) }
         | 
| 11 | 
            +
                  before { File.binwrite path, YAML.dump(x: 20, y: 40) }
         | 
| 12 | 
            +
                  after { FileUtils.rm(path) }
         | 
| 13 | 
            +
                  let(:path) { File.join(__dir__, "test.yaml") }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  context "with Ryo::Object" do
         | 
| 16 | 
            +
                    let(:object) { Ryo::Object }
         | 
| 17 | 
            +
                    it { is_expected.to be_instance_of(Ryo::Object) }
         | 
| 18 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  context "with Ryo::BasicObject" do
         | 
| 22 | 
            +
                    let(:object) { Ryo::BasicObject }
         | 
| 23 | 
            +
                    it { expect(Ryo::BasicObject === ryo).to be(true) }
         | 
| 24 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                context "with a string" do
         | 
| 29 | 
            +
                  subject(:ryo) { described_class.from_yaml(string: "---\nx: 20\ny: 40\n", object:) }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  context "with Ryo::Object" do
         | 
| 32 | 
            +
                    let(:object) { Ryo::Object }
         | 
| 33 | 
            +
                    it { is_expected.to be_instance_of(Ryo::Object) }
         | 
| 34 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  context "with Ryo::BasicObject" do
         | 
| 38 | 
            +
                    let(:object) { Ryo::BasicObject }
         | 
| 39 | 
            +
                    it { expect(Ryo::BasicObject === ryo).to be(true) }
         | 
| 40 | 
            +
                    it { is_expected.to eq("x" => 20, "y" => 40) }
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ryo.rb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.5. | 
| 4 | 
            +
              version: 0.5.5
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - '0x1eef'
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024-06- | 
| 11 | 
            +
            date: 2024-06-20 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: yard
         | 
| @@ -104,13 +104,13 @@ files: | |
| 104 104 | 
             
            - ".bundle/config"
         | 
| 105 105 | 
             
            - ".github/workflows/specs.yml"
         | 
| 106 106 | 
             
            - ".gitignore"
         | 
| 107 | 
            -
            - ".gitlab-ci.yml"
         | 
| 108 107 | 
             
            - ".projectile"
         | 
| 109 108 | 
             
            - ".rubocop.yml"
         | 
| 110 109 | 
             
            - ".yardopts"
         | 
| 111 110 | 
             
            - Gemfile
         | 
| 112 111 | 
             
            - LICENSE
         | 
| 113 112 | 
             
            - README.md
         | 
| 113 | 
            +
            - Rakefile.rb
         | 
| 114 114 | 
             
            - lib/ryo.rb
         | 
| 115 115 | 
             
            - lib/ryo/basic_object.rb
         | 
| 116 116 | 
             
            - lib/ryo/builder.rb
         | 
| @@ -122,6 +122,7 @@ files: | |
| 122 122 | 
             
            - lib/ryo/object.rb
         | 
| 123 123 | 
             
            - lib/ryo/reflect.rb
         | 
| 124 124 | 
             
            - lib/ryo/version.rb
         | 
| 125 | 
            +
            - lib/ryo/yaml.rb
         | 
| 125 126 | 
             
            - ryo.rb.gemspec
         | 
| 126 127 | 
             
            - share/ryo.rb/examples/1.0_prototypes_point_object.rb
         | 
| 127 128 | 
             
            - share/ryo.rb/examples/1.1_prototypes_ryo_fn.rb
         | 
| @@ -146,6 +147,7 @@ files: | |
| 146 147 | 
             
            - spec/ryo_prototypes_spec.rb
         | 
| 147 148 | 
             
            - spec/ryo_reflect_spec.rb
         | 
| 148 149 | 
             
            - spec/ryo_spec.rb
         | 
| 150 | 
            +
            - spec/ryo_yaml_spec.rb
         | 
| 149 151 | 
             
            - spec/setup.rb
         | 
| 150 152 | 
             
            homepage: https://github.com/0x1eef/ryo.rb#readme
         | 
| 151 153 | 
             
            licenses:
         | 
| @@ -159,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 159 161 | 
             
              requirements:
         | 
| 160 162 | 
             
              - - ">="
         | 
| 161 163 | 
             
                - !ruby/object:Gem::Version
         | 
| 162 | 
            -
                  version: ' | 
| 164 | 
            +
                  version: '3.2'
         | 
| 163 165 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 164 166 | 
             
              requirements:
         | 
| 165 167 | 
             
              - - ">="
         |