Class: JsonReducer::Schemas

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/json_reducer/schemas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSchemas

Returns a new instance of Schemas.



10
11
12
13
# File 'lib/json_reducer/schemas.rb', line 10

def initialize
  @schemas = {}
  @base_path = nil
end

Instance Attribute Details

#base_pathObject

Returns the value of attribute base_path.



8
9
10
# File 'lib/json_reducer/schemas.rb', line 8

def base_path
  @base_path
end

Instance Method Details

#get(key) ⇒ Object



15
16
17
# File 'lib/json_reducer/schemas.rb', line 15

def get(key)
  @schemas[key]
end

#set(key, schema, file) ⇒ Object



19
20
21
22
# File 'lib/json_reducer/schemas.rb', line 19

def set(key, schema, file)
  value = file ? File.read("#{@base_path}/#{schema}") : schema
  @schemas[key] = value.is_a?(String) ? JSON.parse(value) : value
end