Module: Nest
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
88
89
90
|
# File 'lib/nest.rb', line 88
def method_missing( name )
self[name]
end
|
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
31
32
33
|
# File 'lib/nest.rb', line 31
def uri
@uri
end
|
Class Method Details
.included(base) ⇒ Object
27
28
29
|
# File 'lib/nest.rb', line 27
def self.included(base)
base.extend(ClassMethods)
end
|
Instance Method Details
#[](name) ⇒ Object
84
85
86
|
# File 'lib/nest.rb', line 84
def []( name )
properties[name.to_s]
end
|
#base_path ⇒ Object
39
40
41
|
# File 'lib/nest.rb', line 39
def base_path
File.join(self.class.mount_point, @uri)
end
|
#children ⇒ Object
92
93
94
|
# File 'lib/nest.rb', line 92
def children
retrieve_sub( :file, :index )
end
|
#data_path ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/nest.rb', line 65
def data_path
case node_type
when :index
index_path
when :file
file_path
else
raise 'not a data node'
end
end
|
#endpoints ⇒ Object
102
103
104
|
# File 'lib/nest.rb', line 102
def endpoints
retrieve_sub( :file )
end
|
#file_groups ⇒ Object
110
111
112
|
# File 'lib/nest.rb', line 110
def file_groups
retrieve_sub( :file_group )
end
|
#file_path ⇒ Object
47
48
49
|
# File 'lib/nest.rb', line 47
def file_path
base_path + '.yml'
end
|
#files ⇒ Object
106
107
108
|
# File 'lib/nest.rb', line 106
def files
retrieve_sub( :object )
end
|
#index_path ⇒ Object
43
44
45
|
# File 'lib/nest.rb', line 43
def index_path
File.join(base_path, 'index.yml')
end
|
#indexes ⇒ Object
Also known as:
indices
96
97
98
|
# File 'lib/nest.rb', line 96
def indexes
retrieve_sub( :index )
end
|
#initialize(uri) ⇒ Object
33
34
35
36
37
|
# File 'lib/nest.rb', line 33
def initialize( uri )
raise 'nest not mounted' unless self.class.mount_point
@uri = sanitize( uri )
raise 'invalid uri' unless valid?
end
|
#node_type ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/nest.rb', line 51
def node_type
if File.file?(index_path)
:index
elsif File.file?(file_path)
:file
elsif File.file?(base_path)
:object
elsif File.directory?(base_path)
:object_group
else
:error
end
end
|
#parent ⇒ Object
114
115
116
|
# File 'lib/nest.rb', line 114
def parent
raise 'parent not implemented'
end
|
#properties ⇒ Object
80
81
82
|
# File 'lib/nest.rb', line 80
def properties
YAML.load_file data_path
end
|
#valid? ⇒ Boolean
76
77
78
|
# File 'lib/nest.rb', line 76
def valid?
node_type != :error
end
|