Module: Resourcelogic::Base::ClassMethods

Defined in:
lib/resourcelogic/base.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_resourceObject



11
12
13
14
15
# File 'lib/resourcelogic/base.rb', line 11

def acts_as_resource
  resourceful(true)
  acts_as_resource_modules.each { |mod| include mod }
  init_default_actions
end

#add_acts_as_resource_module(mod, action = :append) ⇒ Object

Since this part of Resourcelogic deals with another class, ActionController, we can’t just start including things in ActionController itself. A lot of these module includes need to be triggered by the acts_as_resource method call. For example, you don’t want to start adding in email validations and what not into a controller that has nothing to do with Resourcelogic.

That being said, this is your tool for extending Resourcelogic and “hooking” into the acts_as_resource call.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/resourcelogic/base.rb', line 51

def add_acts_as_resource_module(mod, action = :append)
  modules = acts_as_resource_modules
  case action
  when :append
    modules << mod
  when :prepend
    modules = [mod] + modules
  end
  modules.uniq!
  write_inheritable_attribute(:acts_as_resource_modules, modules)
end

#init_default_actionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/resourcelogic/base.rb', line 17

def init_default_actions
  index.wants.html
  edit.wants.html
  new_action.wants.html
  
  show do
    wants.html
    failure.wants.html { render :text => "#{model_name.to_s.singularize.humanize} not found." }
  end
  
  create do
    flash { "#{model_name.to_s.singularize.humanize} successfully created!" }
    wants.html { redirect_to object_url }
    failure.wants.html { render :action => "new" }
  end
  
  update do
    flash { "#{model_name.to_s.singularize.humanize} successfully updated!" }
    wants.html { redirect_to object_url }
    failure.wants.html { render :action => "edit" }
  end
  
  destroy do
    flash { "#{model_name.to_s.singularize.humanize} successfully removed!" }
    wants.html { redirect_to collection_url }
  end
end

#remove_acts_as_resource_module(mod) ⇒ Object

This is the same as add_acts_as_resource_module, except that it removes the module from the list.



64
65
66
67
# File 'lib/resourcelogic/base.rb', line 64

def remove_acts_as_resource_module(mod)
  write_inheritable_attribute(:acts_as_resource_modules, acts_as_resource_modules - [mod])
  acts_as_resource_modules
end

#resourceful(value = nil) ⇒ Object



69
70
71
# File 'lib/resourcelogic/base.rb', line 69

def resourceful(value = nil)
  rw_config(:resourceful, value, false)
end

#resourceful?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/resourcelogic/base.rb', line 73

def resourceful?
  resourceful == true
end