Module: Dope::Application
- Includes:
- Derailleur::Application
- Defined in:
- lib/dope/core/application.rb
Instance Method Summary collapse
- #get_linked_resource(link, root = '') ⇒ Object
- #get_resource(resource, root = '', ident = :default) ⇒ Object
- #get_resource_at_path(resource, path) ⇒ Object
- #get_resource_epitheting_model(resource, label, model, resources, root = '', ident = :default) ⇒ Object
- #get_resource_epitheting_model_at_path(resource, model, label, resources, path) ⇒ Object
- #get_resource_model(model, resources, root = '', ident = :default) ⇒ Object
- #get_resource_model_at_path(model, ident, resources, path) ⇒ Object
- #get_resource_nesting_model(resource, relname, model, resources, root = '', ident = :default) ⇒ Object
- #get_resource_relation(resource, relname, root = '', ident = :default) ⇒ Object
- #get_resource_relation_chain(resource, relnames = [], root = '', ident = :default) ⇒ Object
-
#get_resource_relation_tree(resource, tree = [], root = '', ident = :default) ⇒ Object
multi-level.
-
#static_dir(dir) ⇒ Object
file-system assets’ handling.
- #static_file(path, dir = '') ⇒ Object
- #unget_linked_resource(link, root = '') ⇒ Object
- #unget_resource(resource, root = '', ident = :default) ⇒ Object
- #unget_resource_model(model, root = '', ident = :default) ⇒ Object
- #unget_resource_nesting_model(resource, relname, model, root = '', ident = :default) ⇒ Object
- #unget_resource_relation(resource, relname, root = '', ident = :default) ⇒ Object
Instance Method Details
#get_linked_resource(link, root = '') ⇒ Object
25 26 27 28 29 |
# File 'lib/dope/core/application.rb', line 25 def get_linked_resource(link, root='') branch = link.to_s.sub(/^\.\//,'') path = File.join(root, branch) get_resource_at_path(link.to, path) end |
#get_resource(resource, root = '', ident = :default) ⇒ Object
15 16 17 18 |
# File 'lib/dope/core/application.rb', line 15 def get_resource(resource, root='', ident=:default) path = File.join(root, resource.path(ident)) get_resource_at_path(resource, path) end |
#get_resource_at_path(resource, path) ⇒ Object
10 11 12 13 |
# File 'lib/dope/core/application.rb', line 10 def get_resource_at_path(resource, path) puts "R: #{path}" get(path, ResourceHandler.new(resource)) end |
#get_resource_epitheting_model(resource, label, model, resources, root = '', ident = :default) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/dope/core/application.rb', line 102 def get_resource_epitheting_model(resource, label, model, resources, root='', ident=:default) epithet = resource.epithet(label) raise ArgumentError, "no epithet: #{label} for #{resource}" unless epithet branch = resource.epithets(label, "#{model.base_path}.") path = File.join(root, resource.path(ident), label.to_s, branch) get_resource_epitheting_model_at_path(resource, model, label, resources, path) end |
#get_resource_epitheting_model_at_path(resource, model, label, resources, path) ⇒ Object
110 111 112 113 |
# File 'lib/dope/core/application.rb', line 110 def get_resource_epitheting_model_at_path(resource, model, label, resources, path) puts "E: #{path}" get(path, ResourceEpithetingModelHandler.new([model, label, resources, resource])) end |
#get_resource_model(model, resources, root = '', ident = :default) ⇒ Object
76 77 78 79 |
# File 'lib/dope/core/application.rb', line 76 def get_resource_model(model, resources, root='', ident=:default) path = File.join(root, model.path_model(ident, "#{model.base_path}.")) get_resource_model_at_path(model, ident, resources, path) end |
#get_resource_model_at_path(model, ident, resources, path) ⇒ Object
71 72 73 74 |
# File 'lib/dope/core/application.rb', line 71 def get_resource_model_at_path(model, ident, resources, path) puts "M: #{path}" get(path, ResourceModelHandler.new([model, ident, resources])) end |
#get_resource_nesting_model(resource, relname, model, resources, root = '', ident = :default) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/dope/core/application.rb', line 86 def get_resource_nesting_model(resource, relname, model, resources, root='', ident=:default) nesting = resource.nesting(relname) raise ArgumentError, "no nesting: #{relname} for #{resource}" unless nesting model_ident = nesting.identifier_sym path = File.join(root, resource.path(ident)) get_resource_model(model, resources, path, model_ident) end |
#get_resource_relation(resource, relname, root = '', ident = :default) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dope/core/application.rb', line 37 def get_resource_relation(resource, relname, root='', ident=:default) rel = resource.relationship(relname) raise ArgumentError, "no relationship: #{relname} for #{resource}" unless rel link = resource.link_for_rel(rel) path = File.join(root, resource.path(ident)) case link when Welo::Link get_linked_resource(link, path) when Welo::LinksEnumerator link.each do |l| get_linked_resource(l, path) end else raise RuntimeError, "unknown kind of link: #{link}" end end |
#get_resource_relation_chain(resource, relnames = [], root = '', ident = :default) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/dope/core/application.rb', line 155 def get_resource_relation_chain(resource, relnames=[], root='', ident=:default) tree = [] last = tree relnames.each do |sym| ary = [sym] last << ary last = ary end get_resource_relation_tree(resource, tree, root, ident) end |
#get_resource_relation_tree(resource, tree = [], root = '', ident = :default) ⇒ Object
multi-level
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/dope/core/application.rb', line 117 def get_resource_relation_tree(resource, tree=[], root='', ident=:default) path = if ident File.join(root, resource.path(ident)) else root end tree.each do |node| relname, subtree = if node.is_a? Array [node.first, node[1 .. -1]] else [node, []] end rel = resource.relationship(relname) raise ArgumentError, "no relationship: #{relname} for #{resource}" unless rel link = resource.link_for_rel(rel) case link when Welo::Link get_linked_resource(link, path) unless subtree.empty? branch = link.to_s.sub(/^\.\//,'') new_root = File.join(path, branch) get_resource_relation_tree(link.to, subtree, new_root, nil) end when Welo::LinksEnumerator link.each do |l| get_linked_resource(l, path) unless subtree.empty? branch = link.to_s.sub(/^\.\//,'') new_root = File.join(path, branch) get_resource_relation_tree(link.to, subtree, new_root, nil) end end else raise RuntimeError, "unknown kind of link: #{link}" end end end |
#static_dir(dir) ⇒ Object
file-system assets’ handling
169 170 171 172 173 174 175 |
# File 'lib/dope/core/application.rb', line 169 def static_dir(dir) Find.find(dir) do |path| if File.file?(path) static_file path, dir end end end |
#static_file(path, dir = '') ⇒ Object
177 178 179 180 181 182 183 |
# File 'lib/dope/core/application.rb', line 177 def static_file(path, dir='') route = path.sub(dir,'') puts "F: #{route}" StaticFileHandler.register(route, path) get(route.sub(/\.\w+$/,''), StaticFileHandler) rescue Derailleur::RouteObjectAlreadyPresent end |
#unget_linked_resource(link, root = '') ⇒ Object
31 32 33 34 35 |
# File 'lib/dope/core/application.rb', line 31 def unget_linked_resource(link, root='') branch = link.to_s.sub(/^\.\//,'') path = File.join(root, branch) unget(path) end |
#unget_resource(resource, root = '', ident = :default) ⇒ Object
20 21 22 23 |
# File 'lib/dope/core/application.rb', line 20 def unget_resource(resource, root='', ident=:default) path = File.join(root, resource.path(ident)) unget(path) end |
#unget_resource_model(model, root = '', ident = :default) ⇒ Object
81 82 83 84 |
# File 'lib/dope/core/application.rb', line 81 def unget_resource_model(model, root='', ident=:default) path = File.join(root, model.path_model(ident, "#{model.base_path}.")) unget(path) end |
#unget_resource_nesting_model(resource, relname, model, root = '', ident = :default) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/dope/core/application.rb', line 94 def unget_resource_nesting_model(resource, relname, model, root='', ident=:default) nesting = resource.nesting(relname) raise ArgumentError, "no nesting: #{relname} for #{resource}" unless nesting model_ident = nesting.identifier_sym path = File.join(root, resource.path(ident)) unget_resource_model(model, path, model_ident) end |
#unget_resource_relation(resource, relname, root = '', ident = :default) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dope/core/application.rb', line 54 def unget_resource_relation(resource, relname, root='', ident=:default) rel = resource.relationship(relname) raise ArgumentError, "no relationship: #{relname} for #{resource}" unless rel link = resource.link_for_rel(rel) path = File.join(root, resource.path(ident)) case link when Welo::Link unget_linked_resource(link, path) when Welo::LinksEnumerator link.each do |l| unget_linked_resource(l, path) end else raise RuntimeError, "unknown kind of link: #{link}" end end |