diff --git a/README.md b/README.md index 20d6a4f..69c80f6 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,7 @@ To stop Sisyphus from initializing on a form include the *with_sisyphus* option - Tests - Move away from form_tag_helper, should be able to do it all from form_helper? Script tag can go at the end anyhow. Why aren't we doing that right now? We don't seem to have access to the same variables that the regular form_for does. Also the options array gets muddied by the FormHelper form_for call -> it removes the [:html] section (we need the id of the form for sisyphus). - conflict resolution... i.e. you have an object edit form, the fields are populated from the DB but if you have local browser changes they may get overridden. We need a way to resolve conflicts between local and remote data -> could use a jquery based modal dialog to present the diff? -- Model/Object based exclusions via config or activerecord extension? -- Env. based and global on/off switches +- Model based exclusions via activerecord extension? - block based options (this would allow us to easily and neatly implement Sisyphus options) <%= form_for User.new do |f| %> diff --git a/lib/generators/sisyphus/configuration/templates/sisyphus.yml b/lib/generators/sisyphus/configuration/templates/sisyphus.yml index 55f9e17..ca116c8 100644 --- a/lib/generators/sisyphus/configuration/templates/sisyphus.yml +++ b/lib/generators/sisyphus/configuration/templates/sisyphus.yml @@ -2,9 +2,10 @@ production: # globally enable or disable sisyphus form protection sisyphus_enabled: true # models to exclude from the default enabled state - # exclude_models: User,Post + # note that lower case singular is used + # exclude_models: user,post # models to include from the default disbaled state - # include_models: User,Post + # include_models: user,post development: sisyphus_enabled: true diff --git a/lib/sisyphus-rails/engine.rb b/lib/sisyphus-rails/engine.rb index 993bfe3..650193a 100644 --- a/lib/sisyphus-rails/engine.rb +++ b/lib/sisyphus-rails/engine.rb @@ -4,7 +4,7 @@ module Sisyphus initializer "sisyphus-rails.load_config_data" do |app| Sisyphus.setup do |config| config.app_root = app.root - + #Load the configuration from the environment or a yaml file Sisyphus.config = Hash.new @@ -13,16 +13,16 @@ module Sisyphus config = YAML.load_file("#{::Rails.root}/config/sisyphus.yml") config = config[::Rails.env] - Sisyphus.config["SISYPHUS_ENABLED"] = config['organization_id'] if config['sisyphus_enabled'].present? - Sisyphus.config["EXCLUDE_MODELS"] = config['exclude_models'].split(',') if config['exclude_models'].present? - Sisyphus.config["INCLUDE_MODELS"] = config['include_models'].split(',') if config['include_models'].present? + Sisyphus.config["SISYPHUS_ENABLED"] = config['sisyphus_enabled'] if config.include?('sisyphus_enabled') + Sisyphus.config["EXCLUDE_MODELS"] = config['exclude_models'].split(',') if config.include?('exclude_models') + Sisyphus.config["INCLUDE_MODELS"] = config['include_models'].split(',') if config.include?('include_models') end #if we have ENV flags prefer them - Sisyphus.config["SISYPHUS_ENABLED"] = ENV["SISYPHUS_ENABLED"] if ENV.include? "SISYPHUS_ENABLED" - Sisyphus.config["EXCLUDE_MODELS"] = ENV["EXCLUDE_MODELS"].split(',') if ENV["EXCLUDE_MODELS"] - Sisyphus.config["INCLUDE_MODELS"] = ENV["INCLUDE_MODELS"].split(',') if ENV["INCLUDE_MODELS"] + Sisyphus.config["SISYPHUS_ENABLED"] = ENV["SISYPHUS_ENABLED"] if ENV.include?("SISYPHUS_ENABLED") + Sisyphus.config["EXCLUDE_MODELS"] = ENV["EXCLUDE_MODELS"].split(',') if ENV.include?("EXCLUDE_MODELS") + Sisyphus.config["INCLUDE_MODELS"] = ENV["INCLUDE_MODELS"].split(',') if ENV.include?("INCLUDE_MODELS") end end diff --git a/lib/sisyphus-rails/form_helper.rb b/lib/sisyphus-rails/form_helper.rb index 8a14264..f30f5f1 100644 --- a/lib/sisyphus-rails/form_helper.rb +++ b/lib/sisyphus-rails/form_helper.rb @@ -2,20 +2,27 @@ module ActionView module Helpers module FormHelper def form_for_with_sisyphus(record, options = {}, &proc) - + + case record + when String, Symbol + object_name = record + else + object = record.is_a?(Array) ? record.last : record + object_name = options[:as] || ActiveModel::Naming.param_key(object) + end + + # There is an order of precedence debugger Sisyphus::process = true - Sisyphus::process = Sisyphus::config["SISYPHUS_ENABLED"] if Sisyphus::config["SISYPHUS_ENABLED"].present? + Sisyphus::process = Sisyphus::config["SISYPHUS_ENABLED"] if Sisyphus::config.include?("SISYPHUS_ENABLED") - # if Sisyphus::config["EXCLUDE_MODELS"].present? - # Sisyphus::process = false if Sisyphus::config["EXCLUDE_MODELS"].include?(model_name_from_record_or_class(record)) - # end - - if options[:with_sisyphus] == false - Sisyphus::process = false + if Sisyphus::config["EXCLUDE_MODELS"].present? + Sisyphus::process = false if Sisyphus::config["EXCLUDE_MODELS"].include?(model_name_from_record_or_class(object_name)) end + Sisyphus::process = options[:with_sisyphus] if options.include?(:with_sisyphus) + #strip all the sisyphus options from the options hash before moving on form_for_without_sisyphus(record, options.reject{|k,v| k =~ /sisyphus(.*)/}, &proc) end diff --git a/lib/sisyphus-rails/form_tag_helper.rb b/lib/sisyphus-rails/form_tag_helper.rb index 7e8adfa..5a98156 100644 --- a/lib/sisyphus-rails/form_tag_helper.rb +++ b/lib/sisyphus-rails/form_tag_helper.rb @@ -5,8 +5,6 @@ module ActionView def form_tag_with_sisyphus(url_for_options = {}, options = {}, &block) buf = ActiveSupport::SafeBuffer.new - buf.safe_concat(Sisyphus::config.to_s) - if options.has_key?(:id) && Sisyphus::process buf.safe_concat("") end