onde 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/onde.rb +109 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 077c5f52be54d21896bc4e3e693616b88ea6867d
4
+ data.tar.gz: 62fae1575adcb0b0fde88a46eaa5d67ca76db42c
5
+ SHA512:
6
+ metadata.gz: b05c350b6148a9af674add6a9bd71ec6f7b7d3fee2d00fde44cbff0d4ffae80b9b3ac775aa56eb34c2ce603155f4ff50c406da34d4ac9dbb94b20f210e1cd52f
7
+ data.tar.gz: 4cc1327db8d6316b6b65aa7f732c2f08d6376f8cbad79a90e6e0564d20b14ff9cf7f2e3f3f3e5f99fc0bf4c42e36fafd51cee618cc444b81792a53db55fff39c
data/lib/onde.rb ADDED
@@ -0,0 +1,109 @@
1
+ require 'yaml'
2
+ require 'set'
3
+
4
+
5
+ class Onde
6
+ class ArgumentsError < StandardError; end
7
+ class ConfigurationError < StandardError; end
8
+
9
+ class << self
10
+ def onde_file_path=(path)
11
+ @@onde_file_path = path
12
+ end
13
+
14
+ def onde_file_path
15
+ @@onde_file_path ||= '.onde.yml'
16
+ end
17
+
18
+ def path(path_alias, kwargs={})
19
+ _path = paths[path_alias.to_sym]
20
+
21
+ escape = kwargs.delete(:escape)
22
+ escape = true if escape.nil?
23
+
24
+ if kwargs
25
+ kwargs.each do |variable, value|
26
+ _path = _path.gsub(/<#{variable}>/, value)
27
+ end
28
+ end
29
+
30
+ if !!(_path =~ /<.*?>/)
31
+ raise Onde::ArgumentsError
32
+ end
33
+
34
+ _path = _path.gsub(/ /, '\ ') if escape
35
+
36
+ _path
37
+ end
38
+
39
+ def aliases
40
+ Set.new(paths.keys)
41
+ end
42
+
43
+ def paths
44
+ @@expanded_paths ||= Onde::DirectoryStructure.paths(YAML.load_file(onde_file_path))
45
+ end
46
+
47
+ end
48
+ end
49
+
50
+
51
+ class Onde::DirectoryStructure
52
+ def self.paths(data)
53
+ self.new(data).to_hash
54
+ end
55
+
56
+ def initialize(data)
57
+ @expanded_paths = {}
58
+ data.map do |node_data|
59
+ node = Onde::Node.new(node_data)
60
+ expand_node(node)
61
+ end
62
+ end
63
+
64
+ def to_hash
65
+ @expanded_paths
66
+ end
67
+
68
+ private def expand_node(node)
69
+ if node.alias
70
+ node_alias = node.alias.to_sym
71
+ if @expanded_paths[node_alias]
72
+ raise Onde::ConfigurationError.new('More than one path is tagged with the same alias.')
73
+ end
74
+ @expanded_paths[node_alias] = node.path
75
+ end
76
+
77
+ node.children.each do |child_node|
78
+ expand_node(child_node)
79
+ end
80
+ end
81
+ end
82
+
83
+
84
+ class Onde::Node
85
+ attr_reader :alias, :path, :children
86
+
87
+ def initialize(data, parent_path=nil)
88
+ unless data.is_a? Array
89
+ raise Onde::ConfigurationError.new("Node #{data} is not properly formed")
90
+ end
91
+ node_data, child_data = data
92
+ if node_data.is_a? Hash
93
+ @alias = node_data.keys()[0]
94
+ path_part = node_data[@alias]
95
+ elsif node_data.is_a? String
96
+ @alias = nil
97
+ path_part = node_data
98
+ else
99
+ raise Onde::ConfigurationError.new("Node #{data} is not properly formed")
100
+ end
101
+
102
+ @path = parent_path.nil? ? path_part : File.join(parent_path, path_part)
103
+
104
+ child_data ||= []
105
+ @children = child_data.map do |child_data|
106
+ Onde::Node.new(child_data, @path)
107
+ end
108
+ end
109
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: onde
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Knight
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A tool for managing file and directory paths in your code
14
+ email: iamaaronknight@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/onde.rb
20
+ homepage: http://rubygems.org/gems/onde
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.11
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Onde
44
+ test_files: []