Sha256: 7b9bbf5af36f269e86d48a24b42c01b6e63969eb141251c821728dada47f80a8

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 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_entity.valid?
      rescue => e
        logger.debug PowerStencil::Error.report_error(e)
        logger.debug "Modifications applied to '#{original_entity.as_path}' are invalid !"
        false
      end

    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
power_stencil-0.8.5 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.4 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.3 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.2 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.1 lib/power_stencil/command_processors/edit.rb
power_stencil-0.8.0 lib/power_stencil/command_processors/edit.rb
power_stencil-0.7.4 lib/power_stencil/command_processors/edit.rb
power_stencil-0.7.3 lib/power_stencil/command_processors/edit.rb
power_stencil-0.7.2 lib/power_stencil/command_processors/edit.rb
power_stencil-0.7.1 lib/power_stencil/command_processors/edit.rb
power_stencil-0.7.0 lib/power_stencil/command_processors/edit.rb