Sha256: fa6ea2bc31686fbc13b26f6aa9618495402f3de03b3fe4c0bd9982c3896e8c65

Contents?: true

Size: 1.16 KB

Versions: 18

Compression:

Stored size: 1.16 KB

Contents

module PowerStencil
  module CommandProcessors

    class Edit

      include Climatic::Script::UnimplementedProcessor
      include Climatic::Proxy
      include PowerStencil::Project::Proxy
      include PowerStencil::CommandProcessors::EntityHelper
      include PowerStencil::Utils::FileEdit

      def execute
        targets = targets_from_criteria analyse_extra_params, project.engine.root_universe
        targets.each do |target|
          project.track_action_with_git("Edited entity '#{target.as_path}'.") do
            securely_edit_file target.source_uri do |modified_path, _|
              modifications_valid? modified_path, target
            end
          end
        end
      end

      private

      def modifications_valid?(modified_path, original_entity)
        test_entity = UniverseCompiler::Entity::Persistence.load modified_path
        test_universe = project.engine.root_universe.dup
        duplicated_entity = test_universe.get_entity *(original_entity.to_composite_key)
        test_universe.replace duplicated_entity, test_entity
        test_entity.resolve_fields_references!
        test_entity.valid? raise_error: true
      end

    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
power_stencil-0.10.0 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.8 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.7 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.6 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.5 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.4 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.3 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.2 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.1 lib/power_stencil/command_processors/edit.rb
power_stencil-0.9.0 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.14 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.13 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.12 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.11 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.10 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.9 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.8 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.7 lib/power_stencil/command_processors/edit.rb