Class: Jei::Path
- Inherits:
-
Object
- Object
- Jei::Path
- Defined in:
- lib/jei/path.rb
Defined Under Namespace
Classes: NameError
Constant Summary collapse
- PATH_SEPARATOR =
','.freeze
- NAME_SEPARATOR =
'.'.freeze
Instance Attribute Summary collapse
- #names ⇒ Array<Symbol> readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(names) ⇒ Path
constructor
A new instance of Path.
- #walk(serializer, serializers, level = 0) ⇒ Object
Constructor Details
#initialize(names) ⇒ Path
Returns a new instance of Path.
29 30 31 |
# File 'lib/jei/path.rb', line 29 def initialize(names) @names = names end |
Instance Attribute Details
#names ⇒ Array<Symbol> (readonly)
9 10 11 |
# File 'lib/jei/path.rb', line 9 def names @names end |
Class Method Details
.find(paths, serializer, serializers) ⇒ Object
22 23 24 25 26 |
# File 'lib/jei/path.rb', line 22 def self.find(paths, serializer, serializers) paths.each do |path| path.walk(serializer, serializers) end end |
.parse(paths) ⇒ Array<Path>
13 14 15 16 17 |
# File 'lib/jei/path.rb', line 13 def self.parse(paths) paths.split(PATH_SEPARATOR).map do |path| new(path.split(NAME_SEPARATOR).map(&:to_sym)) end end |
Instance Method Details
#walk(serializer, serializers, level = 0) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jei/path.rb', line 36 def walk(serializer, serializers, level = 0) return if level >= @names.length name = @names[level] relationship = serializer.relationships[name] raise NameError, "invalid relationship name `#{name}'" unless relationship unless relationship.[:data] serializer.[:linkages] = Set.new unless serializer.[:linkages] serializer.[:linkages] << name end resources = [*relationship.evaluate(serializer)] resources.each do |resource| serializer = Serializer.factory(resource, relationship.[:serializer]) serializers << serializer walk(serializer, serializers, level + 1) end end |