Sha256: c3d289d336e6e25f64929bc4509917dbb90eff6d1c462ed607d732676cfe1439

Contents?: true

Size: 1.96 KB

Versions: 27

Compression:

Stored size: 1.96 KB

Contents

module PowerStencil
  module Dsl

    module Entities

      def available_entity_types(force_rescan: false)
        PowerStencil.project.engine.available_entity_types force_rescan: force_rescan
      end

      def build_target
        type, name = main_entry_point.split('/')
        e = entity type, name
        e.nil? ? entity(type.to_sym, name) : e
      end

      def project_config
        entity :project_config, 'Project Config'
      end

      def entity(type_or_path, name = nil)
        type, name = if name.nil?
                       md = type_or_path.match /^(?<type>[^\/]+)\/(?<name>.*)$/
                       if md
                         [md['type'].to_sym, md['name']]
                       else
                         raise PowerStencil::Error, "Invalid entity id: '#{type_or_path}'"
                       end
                     else
                       [type_or_path, name]
                     end
        PowerStencil.project.engine.entity type, name, @universe
      end

      def entities(criterion: nil, value: nil, &filter_block)
        PowerStencil.project.engine.entities @universe, criterion: criterion, value: value, &filter_block
      end

      def delete_entity(entity, delete_files: false)
        PowerStencil.project.engine.delete_entity @universe, entity.type, entity.name, delete_files: delete_files
      end

      def method_missing(method_name, *arguments, &block)
        if method_name.to_s =~ /^user_new_(.*)/
          PowerStencil.project.engine.new_entity @universe, $1, fields: Hash[*arguments], user: true, &block
        elsif method_name.to_s =~ /^new_(.*)$/
          PowerStencil.project.engine.new_entity @universe, $1, fields: Hash[*arguments], &block
        else
          PowerStencil.logger.warn "Invalid DSL method: '#{method_name}'"
          super
        end
      end

      def respond_to_missing?(method_name, include_private = false)
        method_name.to_s.start_with?('new_') || super
      end

    end

  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
power_stencil-0.9.6 lib/power_stencil/dsl/entities.rb
power_stencil-0.9.5 lib/power_stencil/dsl/entities.rb
power_stencil-0.9.4 lib/power_stencil/dsl/entities.rb
power_stencil-0.9.3 lib/power_stencil/dsl/entities.rb
power_stencil-0.9.2 lib/power_stencil/dsl/entities.rb
power_stencil-0.9.1 lib/power_stencil/dsl/entities.rb
power_stencil-0.9.0 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.14 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.13 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.12 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.11 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.10 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.9 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.8 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.7 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.6 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.5 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.4 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.3 lib/power_stencil/dsl/entities.rb
power_stencil-0.8.2 lib/power_stencil/dsl/entities.rb