Module: Zobi::InstanceMethods

Defined in:
lib/zobi.rb

Instance Method Summary collapse

Instance Method Details

#collectionObject



45
46
47
48
49
50
51
52
53
# File 'lib/zobi.rb', line 45

def collection
  return @collection if @collection
  c = zobi_resource_class
  BEHAVIORS.each do |behavior|
    next unless self.class.behavior_included?(behavior)
    c = send :"#{behavior}_collection", c
  end
  @collection = (c.is_a?(Class) ? c.all : c)
end

#collection_pathObject



55
56
57
# File 'lib/zobi.rb', line 55

def collection_path
  url_for controller: zobi_resource_key.pluralize, action: :index
end

#edit_resource_path(r) ⇒ Object



63
64
65
# File 'lib/zobi.rb', line 63

def edit_resource_path r
  url_for controller: zobi_resource_key.pluralize, action: :edit, id: r.id
end

#new_resource_pathObject



59
60
61
# File 'lib/zobi.rb', line 59

def new_resource_path
  url_for controller: zobi_resource_key.pluralize, action: :new
end

#resource_path(r) ⇒ Object



67
68
69
# File 'lib/zobi.rb', line 67

def resource_path r
  url_for controller: zobi_resource_key.pluralize, action: :show, id: r.id
end

#zobi_resource_classObject Also known as: resource_class



30
31
32
# File 'lib/zobi.rb', line 30

def zobi_resource_class
  @_zobi_resource_class ||= zobi_resource_name.classify.constantize
end

#zobi_resource_keyObject Also known as: resource_key



40
41
42
# File 'lib/zobi.rb', line 40

def zobi_resource_key
  @_zobi_resource_key ||= zobi_resource_name.underscore
end

#zobi_resource_nameObject Also known as: resource_name



35
36
37
# File 'lib/zobi.rb', line 35

def zobi_resource_name
  @_zobi_resource_name ||= self.class.to_s.demodulize.gsub(/Controller$/, '').singularize
end