Module: ResourceMapper::ClassMethods
- Defined in:
- lib/resource_mapper/class_methods.rb
Instance Method Summary collapse
-
#actions(*opts) ⇒ Object
Use this method in your controller to specify which actions you’d like it to respond to.
-
#after(*args, &block) ⇒ Object
TODO: After fail after success.
- #before(*args, &block) ⇒ Object
- #create_attrs(*args) ⇒ Object
- #index_attrs(*args) ⇒ Object
- #key(sym) ⇒ Object
- #read_attrs(*args) ⇒ Object
- #show_attrs(*args) ⇒ Object
- #update_attrs(*args) ⇒ Object
- #write_attrs(*args) ⇒ Object
Instance Method Details
#actions(*opts) ⇒ Object
Use this method in your controller to specify which actions you’d like it to respond to.
class PostsController < ResourceController::Base
actions :all, :except => :create
end
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/resource_mapper/class_methods.rb', line 9 def actions(*opts) config = {} config.merge!(opts.pop) if opts.last.is_a?(Hash) all_actions = (singleton? ? ResourceMapper::SINGLETON_ACTIONS : ResourceMapper::ACTIONS) actions_to_remove = [] actions_to_remove += all_actions - opts unless opts.first == :all actions_to_remove += [*config[:except]] if config[:except] actions_to_remove.uniq! actions_to_remove.each { |action| undef_method(action) if method_defined?(action) } end |
#after(*args, &block) ⇒ Object
TODO: After fail after success
40 41 42 43 44 45 46 |
# File 'lib/resource_mapper/class_methods.rb', line 40 def after(*args, &block) raise "Need to specify a block for an after set." unless block_given? args.flatten.each do |arg| self.method(arg).call.after &block end end |
#before(*args, &block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/resource_mapper/class_methods.rb', line 31 def before(*args, &block) raise "Need to specify a block for a before set." unless block_given? args.flatten.each do |arg| self.method(arg).call.before &block end end |
#create_attrs(*args) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/resource_mapper/class_methods.rb', line 88 def create_attrs(*args) class_eval <<-"end_eval", __FILE__, __LINE__ def create_attrs #{args} end end_eval end |
#index_attrs(*args) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/resource_mapper/class_methods.rb', line 60 def index_attrs(*args) class_eval <<-"end_eval", __FILE__, __LINE__ def index_attrs #{args} end end_eval end |
#key(sym) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/resource_mapper/class_methods.rb', line 23 def key(sym) class_eval <<-"end_eval", __FILE__, __LINE__ def key :#{sym} end end_eval end |
#read_attrs(*args) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/resource_mapper/class_methods.rb', line 48 def read_attrs(*args) class_eval <<-"end_eval", __FILE__, __LINE__ def index_attrs #{args} end def show_attrs #{args} end end_eval end |
#show_attrs(*args) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/resource_mapper/class_methods.rb', line 68 def show_attrs(*args) class_eval <<-"end_eval", __FILE__, __LINE__ def show_attrs #{args} end end_eval end |
#update_attrs(*args) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/resource_mapper/class_methods.rb', line 96 def update_attrs(*args) class_eval <<-"end_eval", __FILE__, __LINE__ def update_attrs #{args} end end_eval end |
#write_attrs(*args) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/resource_mapper/class_methods.rb', line 76 def write_attrs(*args) class_eval <<-"end_eval", __FILE__, __LINE__ def create_attrs #{args} end def update_attrs #{args} end end_eval end |