lib/itamae/resource/service.rb in itamae-1.0.0.beta33 vs lib/itamae/resource/service.rb in itamae-1.0.0.beta34

- old
+ new

@@ -4,25 +4,25 @@ module Resource class Service < Base define_attribute :action, default: :nothing define_attribute :name, type: String, default_name: true - def set_current_attributes - @current_attributes[:running?] = run_specinfra(:check_service_is_running, name) - @current_attributes[:enabled?] = run_specinfra(:check_service_is_enabled, name) - - actions = [action].flatten - if actions.include?(:start) || actions.include?(:restart) + def pre_action + case @current_action + when :start, :restart @attributes[:running?] = true - elsif actions.include?(:stop) + when :stop @attributes[:running?] = false - end - - if actions.include?(:enable) + when :enable @attributes[:enabled?] = true - elsif actions.include?(:disable) + when :disable @attributes[:enabled?] = false end + end + + def set_current_attributes + @current_attributes[:running?] = run_specinfra(:check_service_is_running, name) + @current_attributes[:enabled?] = run_specinfra(:check_service_is_enabled, name) end def start_action(options) run_specinfra(:start_service, name) end