binky-builder 0.5.3 → 0.5.4
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/README.md +7 -3
- data/lib/binky/builder.rb +6 -6
- data/lib/binky/builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd2cefe06fb5e423de23a6d2376a3a3e4cb4862018f947c92db6464a2cf2e209
|
4
|
+
data.tar.gz: 2bedcb0714fa9d66c00cc732e7f6d33698a05dba98d513075442df24c5c6053c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f70aa041590d893b634eea622f64ed4891fad4fc7219f2d485f6684fbafbf8c3c09ef661c0b7e1bc90a32458b0c486e985dbebb8dc4fc6adb54f73f5a8700a5
|
7
|
+
data.tar.gz: 53cdb61a0b3a1e417facbf55b7074fdcc75ab26282e371428b8911c7cc0949f2bec957e540ee225a2776a66af965e84320cf4344e4cc0456c364720cccb40c51
|
data/README.md
CHANGED
@@ -46,19 +46,23 @@ In case not using column names but an array of method names, new accessors would
|
|
46
46
|
|
47
47
|
issue = Issue.new.build_by_keys({id: 1234,text: "hocus pocus"},Issue.column_names) # => Issue.column_names = id:
|
48
48
|
issue.as_json # => {id: 1234}
|
49
|
+
issue.to_h # => nil
|
49
50
|
|
50
51
|
issue = Issue.new.build_by_keys({id: 1234,text: "hocus pocus"}) # => Issue.column_names = id:
|
51
52
|
issue.id # => {id: 1234}
|
52
53
|
issue.text # => {text: "hocus pocus"}
|
53
|
-
issue.
|
54
|
+
issue.as_json #=> {id: 1234,text: "hocus pocus"}
|
55
|
+
issue.to_h # => nil
|
54
56
|
```
|
55
57
|
|
58
|
+
|
56
59
|
Call *build_by_keys* method once the model has been initialized passing a json message,
|
57
|
-
it
|
58
|
-
This method will also create an instance variable called *@to_hash* contains a pair-value hash as a result.
|
60
|
+
it would *yield* itself as a block in case you want to perform further actions.
|
59
61
|
```ruby
|
60
62
|
build_by_keys(json = {},keys = nil)
|
61
63
|
```
|
64
|
+
This method would also create an instance variable called *@to_h* contains a pair-value hash as a result.
|
65
|
+
*@to_h* instance variable won't be available if the class inherits from *ActiveRecord::Base*
|
62
66
|
|
63
67
|
### Auxiliary methods
|
64
68
|
Binky-Builder comes with two extra methods to search and create instance variable and methods.
|
data/lib/binky/builder.rb
CHANGED
@@ -65,22 +65,22 @@ module Binky
|
|
65
65
|
include Helper
|
66
66
|
|
67
67
|
def initialize(json = nil)
|
68
|
-
|
69
|
-
json
|
68
|
+
accessor_builder('to_h',{})
|
69
|
+
json&.each do |k, v|
|
70
70
|
self.send("#{k}=", v)
|
71
|
-
end
|
71
|
+
end
|
72
72
|
end
|
73
73
|
|
74
74
|
def method_missing(name, *args)
|
75
75
|
attribute = name.to_s.start_with?(/\d/) ? "_#{name.to_s}" : name.to_s
|
76
76
|
if attribute =~ /=$/
|
77
77
|
if args[0].respond_to?(:key?) || args[0].is_a?(Hash)
|
78
|
-
@
|
78
|
+
@to_h[attribute.chop] = self.class.new(args[0])
|
79
79
|
else
|
80
|
-
@
|
80
|
+
@to_h[attribute.chop] = args[0]
|
81
81
|
end
|
82
82
|
else
|
83
|
-
@
|
83
|
+
@to_h[attribute]
|
84
84
|
end
|
85
85
|
end
|
86
86
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binky-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduard Garcia Castello
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|