Class: Eco::API::Common::Loaders::Parser
- Defined in:
- lib/eco/api/common/loaders/parser.rb
Direct Known Subclasses
People::DefaultParsers::ArchivedParser, People::DefaultParsers::BooleanParser, People::DefaultParsers::CSVParser, People::DefaultParsers::DateParser, People::DefaultParsers::FreemiumParser, People::DefaultParsers::JsonParser, People::DefaultParsers::LoginProvidersParser, People::DefaultParsers::MultiParser, People::DefaultParsers::NumericParser, People::DefaultParsers::PolicyGroupsParser, People::DefaultParsers::SelectParser, People::DefaultParsers::SendInvitesParser, People::DefaultParsers::XLSParser, Eco::API::Custom::Parser
Defined Under Namespace
Classes: RequiredAttrs
Class Attribute Summary collapse
-
.active_when ⇒ Object
readonly
Returns the value of attribute active_when.
Attributes included from Language::AuxiliarLogger
Class Method Summary collapse
-
.active_when_all(*attrs) ⇒ Object
Helper to build the
active_whencondition. -
.active_when_any(*attrs) ⇒ Object
Helper to build the
active_whencondition. -
.attribute(value = nil) ⇒ String
The
typeof usecase (i.e.:sync,:transform,:import,:other). -
.dependencies(**value) ⇒ Object
Some parsers require dependencies to do their job.
-
.parsing_phase(phase = nil) ⇒ Object
Define or get the
phasethat theparserkicks in. -
.serializing_phase(phase = nil) ⇒ Object
Define or get the
phasethat theserializerkicks in.
Instance Method Summary collapse
-
#attribute ⇒ String, Symbol
The field/attribute or type this parser is linked to.
-
#initialize(person_parser) ⇒ Parser
constructor
rubocop:disable Lint/MissingSuper.
- #parser(_data, _deps) ⇒ Object
Methods inherited from CaseBase
#name, name_only_once!, original_name
Methods inherited from Base
<=>, created_at, set_created_at!
Methods included from Language::Klass::InheritableClassVars
#inheritable_attrs, #inheritable_class_vars, #inherited
Methods included from Language::Klass::Naming
#instance_variable_name, #to_constant
Methods included from Language::Klass::Hierarchy
Methods included from Language::Klass::Builder
Methods included from Language::Klass::Uid
Methods included from Language::Klass::Resolver
#class_resolver, #resolve_class
Methods included from Language::Klass::Const
#if_const, #redef_without_warning
Methods included from Language::AuxiliarLogger
Constructor Details
#initialize(person_parser) ⇒ Parser
rubocop:disable Lint/MissingSuper
121 122 123 124 125 126 127 128 129 |
# File 'lib/eco/api/common/loaders/parser.rb', line 121 def initialize(person_parser) # rubocop:disable Lint/MissingSuper msg = "Expected Eco::API::Common::People::PersonParser. Given #{person_parser.class}" raise msg unless person_parser.is_a?(Eco::API::Common::People::PersonParser) person_parser.define_attribute(attribute, dependencies: self.class.dependencies) do |attr_parser| _define_parser(attr_parser) _define_serializer(attr_parser) end end |
Class Attribute Details
.active_when ⇒ Object (readonly)
Returns the value of attribute active_when.
31 32 33 |
# File 'lib/eco/api/common/loaders/parser.rb', line 31 def active_when @active_when end |
Class Method Details
.active_when_all(*attrs) ⇒ Object
Helper to build the active_when condition.
92 93 94 95 96 97 98 99 |
# File 'lib/eco/api/common/loaders/parser.rb', line 92 def active_when_all(*attrs) @active_when_attrs = RequiredAttrs.new(attribute, :all, attrs) @active_when = proc do |source_data| keys = data_keys(source_data) attrs.all? {|key| keys.include?(key)} end end |
.active_when_any(*attrs) ⇒ Object
Helper to build the active_when condition.
83 84 85 86 87 88 89 |
# File 'lib/eco/api/common/loaders/parser.rb', line 83 def active_when_any(*attrs) @active_when_attrs = RequiredAttrs.new(attribute, :any, attrs) @active_when = proc do |source_data| keys = data_keys(source_data) attrs.any? {|key| keys.include?(key)} end end |
.attribute(value = nil) ⇒ String
Returns the type of usecase (i.e. :sync, :transform, :import, :other).
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/eco/api/common/loaders/parser.rb', line 37 def attribute(value = nil) unless value msg = "You should specify the 'attribute' this parser/serializer, " msg << "#{self.class}, is linked to" return @attribute || (raise msg) end name value @attribute = value end |
.dependencies(**value) ⇒ Object
Some parsers require dependencies to do their job.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eco/api/common/loaders/parser.rb', line 49 def dependencies(**value) @dependencies ||= {} if value.empty? return @dependencies.merge({ required_attrs: @active_when_attrs }) end raise "Expected Hash. Given: '#{value.class}'" unless value.is_a?(Hash) @dependencies.merge!(value) end |
.parsing_phase(phase = nil) ⇒ Object
Define or get the phase that the parser kicks in.
65 66 67 68 69 70 |
# File 'lib/eco/api/common/loaders/parser.rb', line 65 def parsing_phase(phase = nil) @parsing_phase ||= :internal return @parsing_phase unless phase @parsing_phase = phase end |
.serializing_phase(phase = nil) ⇒ Object
Define or get the phase that the serializer kicks in.
75 76 77 78 79 80 |
# File 'lib/eco/api/common/loaders/parser.rb', line 75 def serializing_phase(phase = nil) @serializing_phase ||= :person return @serializing_phase unless phase @serializing_phase = phase end |
Instance Method Details
#attribute ⇒ String, Symbol
Returns the field/attribute or type this parser is linked to.
152 153 154 |
# File 'lib/eco/api/common/loaders/parser.rb', line 152 def attribute self.class.attribute end |
#parser(_data, _deps) ⇒ Object
137 138 139 |
# File 'lib/eco/api/common/loaders/parser.rb', line 137 def parser(_data, _deps) raise 'You should implement this method' end |