Class: JsonReducer::Schemas
- Inherits:
-
Object
- Object
- JsonReducer::Schemas
- Includes:
- Singleton
- Defined in:
- lib/json_reducer/schemas.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
Returns the value of attribute base_path.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize ⇒ Schemas
constructor
A new instance of Schemas.
- #set(key, schema, file) ⇒ Object
Constructor Details
#initialize ⇒ Schemas
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_path ⇒ Object
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 |