Module: Zcloudjp::Utils
- Included in:
- Metadata
- Defined in:
- lib/zcloudjp/utils.rb
Instance Method Summary collapse
-
#load_file(path, key_word) ⇒ Object
Loads a specified file and returns Hash including the given key.
-
#parse_params(params, key_word) ⇒ Object
Parses given params or file and returns Hash including the given key.
Instance Method Details
#load_file(path, key_word) ⇒ Object
Loads a specified file and returns Hash including the given key.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zcloudjp/utils.rb', line 14 def load_file(path, key_word) begin data = MultiJson.load(IO.read(File.(path)), symbolize_keys: true) rescue RuntimeError, Errno::ENOENT => e raise e. rescue MultiJson::LoadError => e raise e. end if data.has_key?(key_word) data[key_word].map { |k,v| data[key_word][k] = v } if data[key_word].is_a? Hash end data end |
#parse_params(params, key_word) ⇒ Object
Parses given params or file and returns Hash including the given key.
7 8 9 10 11 |
# File 'lib/zcloudjp/utils.rb', line 7 def parse_params(params, key_word) body = params.has_key?(:path) ? load_file(params[:path], key_word) : params body = { key_word => body } unless body.has_key?(key_word.to_sym) body end |