Sha256: 6a1e1c478c4448e7ce721584ce0332561b699ab7af4b3cb1cac57d6922c8a6e4

Contents?: true

Size: 1.45 KB

Versions: 5

Compression:

Stored size: 1.45 KB

Contents

#
#       ActiveFacts Generator Expression List Traits
#
# Each expression is a string which, evaluated in some context (usu. SQL),
# yields a single value of the specified type (perhaps an array value!)
#
# Copyright (c) 2017 Clifford Heath. Read the LICENSE file.
#
require 'activefacts/metamodel'
require 'activefacts/metamodel/datatypes'
require 'activefacts/generator'

module ActiveFacts
  module Generators
    class Expression
    private
      MM = ActiveFacts::Metamodel unless const_defined?(:MM)
    public
      attr_reader :type_num       # ActiveFacts::Metamodel::DataType number
      attr_reader :value          # String representation of the expression
      attr_reader :is_mandatory   # false if nullable
                  # This doesn't handle Postgres expressions, which can include a sub-table (e.g. via unnest)
      attr_reader :is_array       # the expression returns an array of the specified type

      # Construct an expression that addresses a field from a Metamodel::Component
      def initialize value, type_num, is_mandatory, is_array = false
        @type_num = type_num
        @value = value
        @is_mandatory = is_mandatory
        @is_array = is_array
      end

      def to_s
        value
      end

      def inspect
        "Expression(#{value.inspect}, #{@type_num ? ActiveFacts::Metamodel::DataType::TypeNames[@type_num] : 'unknown'}, #{@is_mandatory ? 'mandatory' : 'nullable'}#{@is_array ? ', array' : ''})"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activefacts-compositions-1.9.23 lib/activefacts/generator/traits/expr.rb
activefacts-compositions-1.9.22 lib/activefacts/generator/traits/expr.rb
activefacts-compositions-1.9.21 lib/activefacts/generator/traits/expr.rb
activefacts-compositions-1.9.20 lib/activefacts/generator/traits/expr.rb
activefacts-compositions-1.9.19 lib/activefacts/generator/traits/expr.rb