README.md in sinclair-1.14.1 vs README.md in sinclair-1.14.2
- old
+ new
@@ -13,17 +13,17 @@
to simplify common tasks, reusability and avoid boilerplate code. Whether you need to class methods to create methods on the fly,
create custom comparators, configure your application, create powerfull options, Sinclair has got you covered.
Employing Sinclair in your applications helps you streamline your development workflow and enhance your development process through more efficient, cleaner code
-Current Release: [1.14.1](https://github.com/darthjee/sinclair/tree/1.14.1)
+Current Release: [1.14.2](https://github.com/darthjee/sinclair/tree/1.14.2)
-[Next release](https://github.com/darthjee/sinclair/compare/1.14.1...master)
+[Next release](https://github.com/darthjee/sinclair/compare/1.14.2...master)
Yard Documentation
-------------------
-[https://www.rubydoc.info/gems/sinclair/1.14.1](https://www.rubydoc.info/gems/sinclair/1.14.1)
+[https://www.rubydoc.info/gems/sinclair/1.14.2](https://www.rubydoc.info/gems/sinclair/1.14.2)
Installation
---------------
- Install it
@@ -77,24 +77,24 @@
<details>
<summary>Builder in class method</summary>
```ruby
+# http_json_model.rb
+
class HttpJsonModel
attr_reader :json
class << self
def parse(attribute, path: [])
- builder = Sinclair.new(self)
-
keys = (path + [attribute]).map(&:to_s)
- builder.add_method(attribute) do
- keys.inject(hash) { |h, key| h[key] }
+ Sinclair.build(self) do
+ add_method(attribute) do
+ keys.inject(hash) { |h, key| h[key] }
+ end
end
-
- builder.build
end
end
def initialize(json)
@json = json
@@ -102,19 +102,25 @@
def hash
@hash ||= JSON.parse(json)
end
end
+```
+```ruby
+# http_person.rb
+
class HttpPerson < HttpJsonModel
parse :uid
parse :name, path: [:personal_information]
parse :age, path: [:personal_information]
parse :username, path: [:digital_information]
parse :email, path: [:digital_information]
end
+```
+```ruby
json = <<-JSON
{
"uid": "12sof511",
"personal_information":{
"name":"Bob",
@@ -673,10 +679,19 @@
<details>
<summary>Sample of specs over adding methods</summary>
```ruby
+# spec_helper.rb
+
+RSpec.configure do |config|
+ config.include Sinclair::Matchers
+end
+```
+
+```ruby
+# default_value.rb
class DefaultValue
delegate :build, to: :builder
attr_reader :klass, :method, :value, :class_method
def initialize(klass, method, value, class_method: false)
@@ -696,11 +711,15 @@
b.add_method(method) { value }
end
end
end
end
+```
-RSpec.describe Sinclair::Matchers do
+```ruby
+# default_value_spec.rb
+
+RSpec.describe DefaultValue do
subject(:builder_class) { DefaultValue }
let(:klass) { Class.new }
let(:method) { :the_method }
let(:value) { Random.rand(100) }