Class: INatGet::Data::Parser Private
- Inherits:
-
Object
- Object
- INatGet::Data::Parser
- Includes:
- System::Context
- Defined in:
- lib/inat-get/data/parsers/base.rb,
lib/inat-get/data/parsers/defs.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Annotation, Fave, Identification, Observation, Photo, Place, Project, ProjectAdmin, Sound, Tag, Taxon, User
Defined Under Namespace
Classes: Annotation, Fave, Identification, Observation, Part, Photo, Place, Project, ProjectAdmin, Sound, Tag, Taxon, User
Parsing collapse
- #entry!(source) ⇒ Model private
- #fake(id) ⇒ Model private
- #parse!(source) ⇒ Array<Model>, Model private
Descendant Definitions collapse
- #manager ⇒ Manager private
- #model ⇒ class of Model private
Parts collapse
- .part(cls, *args, **kwargs) ⇒ void private private
- .parts ⇒ Array<Part> private
- #parts ⇒ Array<Part> private private
Methods included from System::Context
#check_shutdown!, check_shutdown!, #shutdown?, shutdown?
Class Method Details
.part(cls, *args, **kwargs) ⇒ void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
77 78 79 80 |
# File 'lib/inat-get/data/parsers/defs.rb', line 77 def part cls, *args, **kwargs @parts ||= [] @parts << cls.new(self.instance, *args, **kwargs) end |
.parts ⇒ Array<Part>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 |
# File 'lib/inat-get/data/parsers/defs.rb', line 70 def parts @parts ||= [] end |
Instance Method Details
#entry!(source) ⇒ Model
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/inat-get/data/parsers/defs.rb', line 96 def entry! source check_shutdown! { self.model.db.rollback_on_exit } fields = {} pk, rest = parts.partition { |p| p.is_a?(Part::PK) } pk.each do |a| result = a.parse source registered = result.delete :_registered return model.with_pk(registered.size == 1 ? registered.first : registered) if registered fields.merge! result end associations, attributes = rest.partition { |p| p.is_a?(Part::Assoc) } attributes.each do |a| fields.merge! a.parse(source) end record = nil model.db.transaction(isolation: :committed, mode: :immediate) do record = upsert fields end fields = {} associations.each do |a| res = a.parse(record, source) fields.merge! res if res end model.db.transaction(isolation: :committed, mode: :immediate) do record.update(fields) || record end end |
#fake(id) ⇒ Model
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 |
# File 'lib/inat-get/data/parsers/base.rb', line 22 def fake(id) = raise NotImplementedError, "Not implemented method 'fake' for abstract class", caller_locations |
#manager ⇒ Manager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
29 |
# File 'lib/inat-get/data/parsers/base.rb', line 29 def manager() = self.model.manager |
#model ⇒ class of Model
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/inat-get/data/parsers/base.rb', line 32 def model() @model ||= get_model end |
#parse!(source) ⇒ Array<Model>, Model
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 15 16 17 18 19 |
# File 'lib/inat-get/data/parsers/base.rb', line 12 def parse! source case source when Array source.map { |s| entry!(s) } else entry! source end end |
#parts ⇒ Array<Part> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 |
# File 'lib/inat-get/data/parsers/defs.rb', line 89 private def parts = self.class.parts |