From fb93632750e8927d3dcd28b06478566051845f0e Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 29 Jul 2013 16:34:52 -0400 Subject: [PATCH] add active admin and more code work --- README.md | 10 +++++++--- lib/candy_wrapper.rb | 3 +++ lib/candy_wrapper/active_admin.rb | 9 +++++++++ lib/candy_wrapper/model_wrapper.rb | 4 ++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 lib/candy_wrapper/active_admin.rb diff --git a/README.md b/README.md index fbc0251..da1dfcd 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,12 @@ class DatabaseObjectFormObject < CandyWrapper::ModelWrapper end ``` -## Coming soon! +Also, plug it into ActiveAdmin super-easily, which is where I typicallty +use it! -* Form objects that hang off of models as if they were relationships -* A better readme! +``` ruby +ActiveAdmin.register Model do + wrap_in_form_object +end +``` diff --git a/lib/candy_wrapper.rb b/lib/candy_wrapper.rb index 3a25d2c..a685eec 100644 --- a/lib/candy_wrapper.rb +++ b/lib/candy_wrapper.rb @@ -2,3 +2,6 @@ require "candy_wrapper/version" require "candy_wrapper/model_wrapper" require "candy_wrapper/inherited_resources" +if defined?(ActiveAdmin) + require 'candy_wrapper/active_admin' +end diff --git a/lib/candy_wrapper/active_admin.rb b/lib/candy_wrapper/active_admin.rb new file mode 100644 index 0000000..9c4841b --- /dev/null +++ b/lib/candy_wrapper/active_admin.rb @@ -0,0 +1,9 @@ +class ActiveAdmin::DSL + def wrap_in_form_object + controller do + include CandyWrapper::InheritedResources + + wrap_in_form_object! + end + end +end diff --git a/lib/candy_wrapper/model_wrapper.rb b/lib/candy_wrapper/model_wrapper.rb index d550167..6ab314d 100644 --- a/lib/candy_wrapper/model_wrapper.rb +++ b/lib/candy_wrapper/model_wrapper.rb @@ -55,6 +55,10 @@ module CandyWrapper end def save + if respond_to? :before_wrapped_save + before_wrapped_save @__object__ + end + self.class.before_wrapped_save.each do |before| send("#{before}=", @__object__, @__params__[before]) end