Sha256: 3133bc647ad7c626f5c86dc1821f2a7902c3b5635a11a73bb823f3e7b5a53645

Contents?: true

Size: 899 Bytes

Versions: 16

Compression:

Stored size: 899 Bytes

Contents

module Eco
  module Language
    module Models

      class AttributeParser

        attr_reader :attr

        def initialize(attr, dependencies: {})
          @attr = attr
          @dependencies = dependencies
        end

        def def_parser(&block)
          @parser = block
          self
        end

        def def_serializer(&block)
          @serializer = block
          self
        end

        def parse(source, dependencies: {})
          raise "There is no parser for this attribue '#{attr}'" if !@parser
          @parser.call(source, @dependencies.merge(dependencies), attr)
        end

        def serialize(object, dependencies: {})
          raise "There is no serializer for this attribue '#{attr}'" if !@serializer
          @serializer.call(object, @dependencies.merge(dependencies), attr)
        end

      end

    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
eco-helpers-0.6.17 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.16 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.15 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.13 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.12 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.11 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.9 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.8 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.7 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.6 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.5 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.4 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.3 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.2 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.1 lib/eco/language/models/attribute_parser.rb
eco-helpers-0.6.0 lib/eco/language/models/attribute_parser.rb