Skip to content

Commit 875a525

Browse files
committed
refactored configuration hash into openstruct
1 parent b05e2a9 commit 875a525

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/contentstack/request.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Request
88
attr_reader :endpoint
99

1010
def initialize(client, endpoint)
11+
# puts endpoint
1112
@client = client
1213
@endpoint = endpoint
1314
end

lib/contentstack/utils.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'ostruct'
2+
require 'json'
3+
4+
module Contentstack
5+
module Utils
6+
7+
module_function
8+
9+
# Simple way to turn a deeply nested hash into an openstruct
10+
# https://coderwall.com/p/74rajw/convert-a-complex-nested-hash-to-an-object
11+
def to_openstruct(hash)
12+
json = hash.to_json
13+
JSON.parse(json, object_class: OpenStruct)
14+
end
15+
16+
end
17+
end

0 commit comments

Comments
 (0)