class ContextExposer::Page::Resource

Attributes

controller[RW]
name[RW]
type[RW]

Public Class Methods

new(name = nil, type = nil) click to toggle source
# File lib/context_exposer/page/resource.rb, line 6
def initialize name = nil, type = nil        
  self.name = name
  self.type = type if type
end

Public Instance Methods

name=(name) click to toggle source
# File lib/context_exposer/page/resource.rb, line 16
def name= name    
  @name = name.to_s    
  unless @type
    @type = calc_type 
  end
end
type=(type) click to toggle source
# File lib/context_exposer/page/resource.rb, line 11
def type= type
  validate_type! type
  @type = type.to_sym
end

Protected Instance Methods

calc_type() click to toggle source
# File lib/context_exposer/page/resource.rb, line 29
def calc_type
  return nil if name.blank?
  name.to_s.plural? ? :list : :item
end
page_context() click to toggle source
# File lib/context_exposer/page/resource.rb, line 25
def page_context
  ContextExposer::PageContext.instance
end
valid_type?(type) click to toggle source
# File lib/context_exposer/page/resource.rb, line 40
def valid_type? type
  valid_types.include? type.to_sym
end
valid_types() click to toggle source
# File lib/context_exposer/page/resource.rb, line 44
def valid_types
  [:list, :item]
end
validate_type!(type) click to toggle source
# File lib/context_exposer/page/resource.rb, line 34
def validate_type! type
  unless valid_type? type
    raise ArgumentError, "type must be one of: #{valid_types}, was: #{type}"
  end
end