Class: SchemaTools::Schema
- Inherits:
-
Object
- Object
- SchemaTools::Schema
- Defined in:
- lib/schema_tools/schema.rb
Overview
Internal representation of a Schema. This is basically a wrapper around a HashWithIndifferentAccess ( for historical purposes ) as well as information concerning where the Schema was loaded from in order to resolve relative paths.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#absolute_dir ⇒ Object
retrieve the base directory against which refs should be resolved.
-
#absolute_filename ⇒ Object
retrieve the filename the Schema was loaded from or nil if the Schema was constructed from a Hash.
-
#absolute_filename=(fn) ⇒ Object
set the filename the Schema was loaded from.
- #empty? ⇒ Boolean
-
#initialize(name_or_hash) ⇒ Schema
constructor
A new instance of Schema.
- #keys ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name_or_hash) ⇒ Schema
Returns a new instance of Schema.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/schema_tools/schema.rb', line 20 def initialize(name_or_hash) case name_or_hash when (::Hash) @hash = name_or_hash.with_indifferent_access when (::String) src = File.open(name_or_hash, 'r') { |f| f.read } self.absolute_filename= name_or_hash decode src end handle_extends resolve_refs end |
Instance Method Details
#==(other) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/schema_tools/schema.rb', line 56 def ==(other) case other when (::Hash) return other.with_indifferent_access == hash when (ActiveSupport::HashWithIndifferentAccess) return other == hash when (Schema) return other.hash == hash else return false end end |
#[](key) ⇒ Object
38 39 40 |
# File 'lib/schema_tools/schema.rb', line 38 def [](key) @hash[key] end |
#[]=(key, value) ⇒ Object
44 45 46 |
# File 'lib/schema_tools/schema.rb', line 44 def []=(key, value) @hash[key] = value end |
#absolute_dir ⇒ Object
retrieve the base directory against which refs should be resolved.
88 89 90 |
# File 'lib/schema_tools/schema.rb', line 88 def absolute_dir @absolute_dir || SchemaTools.schema_path end |
#absolute_filename ⇒ Object
retrieve the filename the Schema was loaded from or nil if the Schema was constructed from a Hash
83 84 85 |
# File 'lib/schema_tools/schema.rb', line 83 def absolute_filename @absolute_filename || nil end |
#absolute_filename=(fn) ⇒ Object
set the filename the Schema was loaded from
76 77 78 79 |
# File 'lib/schema_tools/schema.rb', line 76 def absolute_filename=(fn) @absolute_filename = File.absolute_path(fn) @absolute_dir = File.dirname (@absolute_filename) end |
#empty? ⇒ Boolean
48 49 50 |
# File 'lib/schema_tools/schema.rb', line 48 def empty? @hash.empty? end |
#keys ⇒ Object
52 53 54 |
# File 'lib/schema_tools/schema.rb', line 52 def keys @hash.keys end |
#to_h ⇒ Object
92 93 94 |
# File 'lib/schema_tools/schema.rb', line 92 def to_h @hash end |