Sha256: c77d28b70abb9429cf9de6be59012ece9f45a02c94dd55f827e261210b9b399a

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# Create an object, optionally of a type.
#

module Gloo
  module Verbs
    class Create < Gloo::Core::Verb

      KEYWORD = 'create'.freeze
      KEYWORD_SHORT = '`'.freeze
      AS = 'as'.freeze
      VAL = ':'.freeze
      NO_NAME_ERR = 'Object name is missing!'.freeze

      #
      # Run the verb.
      #
      def run
        name = @tokens.second
        type = @tokens.after_token( AS )
        value = @tokens.after_token( VAL )

        unless name
          @engine.err NO_NAME_ERR
          return
        end
        create name, type, value
      end

      #
      # Get the Verb's keyword.
      #
      def self.keyword
        return KEYWORD
      end

      #
      # Get the Verb's keyword shortcut.
      #
      def self.keyword_shortcut
        return KEYWORD_SHORT
      end

      # ---------------------------------------------------------------------
      #    Private functions
      # ---------------------------------------------------------------------

      private

      #
      # Create an object with given name of given type with
      # the given initial value.
      #
      def create( name, type, value )
        if Gloo::Expr::LString.string?( value )
          value = Gloo::Expr::LString.strip_quotes( value )
        end
        obj = @engine.factory.create( { name: name, type: type, value: value } )

        obj.add_default_children if obj&.add_children_on_create?
        @engine.heap.it.set_to value
      end

    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gloo-3.1.1 lib/gloo/verbs/create.rb
gloo-3.1.0 lib/gloo/verbs/create.rb
gloo-3.0.1 lib/gloo/verbs/create.rb
gloo-3.0.0 lib/gloo/verbs/create.rb
gloo-2.5.0 lib/gloo/verbs/create.rb
gloo-2.4.3 lib/gloo/verbs/create.rb
gloo-2.4.2 lib/gloo/verbs/create.rb
gloo-2.4.1 lib/gloo/verbs/create.rb
gloo-2.4.0 lib/gloo/verbs/create.rb
gloo-2.3.1 lib/gloo/verbs/create.rb
gloo-2.2.0 lib/gloo/verbs/create.rb
gloo-2.1.0 lib/gloo/verbs/create.rb
gloo-2.0.2 lib/gloo/verbs/create.rb
gloo-2.0.1 lib/gloo/verbs/create.rb
gloo-2.0.0 lib/gloo/verbs/create.rb