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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9321688bf31d81ae9ca16b4572cbaac0e1293d5d84157b26ee365f445f822264
4
- data.tar.gz: 8d69887edddd98bcc61bbf3bfb87336c9268b84a9075bd913964b9376033fbb7
3
+ metadata.gz: dd2cefe06fb5e423de23a6d2376a3a3e4cb4862018f947c92db6464a2cf2e209
4
+ data.tar.gz: 2bedcb0714fa9d66c00cc732e7f6d33698a05dba98d513075442df24c5c6053c
5
5
  SHA512:
6
- metadata.gz: 650820f1362f453e4e948bf45e24147bf089b3401d13d0e25d133028a7e8c7737de96f4f72815f7e08201576fcc863e0d6dcecaec3f8a8479ae93801c2f8b2a6
7
- data.tar.gz: d33b4adfb673dd192d5922a5d22b5ae2bad83d10e4399653d786f1e47c9342201cbad5a279c1654fea284b36abcdb6f38687786dda5341229f1e28524de37dad
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.to_hash #=> {id: 1234,text: "hocus pocus"}
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 will *yield* self as a block in case you want to perform further actions.
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.
@@ -65,22 +65,22 @@ module Binky
65
65
  include Helper
66
66
 
67
67
  def initialize(json = nil)
68
- @attributes = {}
69
- json.each do |k, v|
68
+ accessor_builder('to_h',{})
69
+ json&.each do |k, v|
70
70
  self.send("#{k}=", v)
71
- end unless json.nil?
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
- @attributes[attribute.chop] = self.class.new(args[0])
78
+ @to_h[attribute.chop] = self.class.new(args[0])
79
79
  else
80
- @attributes[attribute.chop] = args[0]
80
+ @to_h[attribute.chop] = args[0]
81
81
  end
82
82
  else
83
- @attributes[attribute]
83
+ @to_h[attribute]
84
84
  end
85
85
  end
86
86
  end
@@ -1,5 +1,5 @@
1
1
  module Binky
2
2
  module Builder
3
- VERSION = "0.5.3"
3
+ VERSION = "0.5.4"
4
4
  end
5
5
  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.3
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-05 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: