Class: FakeRails3Routes::Mapper::Resources::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_rails3_routes/mapper.rb

Overview

:nodoc:

Direct Known Subclasses

SingletonResource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entities, options = {}) ⇒ Resource

Returns a new instance of Resource.



753
754
755
756
757
758
759
# File 'lib/fake_rails3_routes/mapper.rb', line 753

def initialize(entities, options = {})
  @name       = entities.to_s
  @path       = (options[:path] || @name).to_s
  @controller = (options[:controller] || @name).to_s
  @as         = options[:as]
  @options    = options
end

Instance Attribute Details

#controllerObject (readonly)

Returns the value of attribute controller.



751
752
753
# File 'lib/fake_rails3_routes/mapper.rb', line 751

def controller
  @controller
end

#optionsObject (readonly)

Returns the value of attribute options.



751
752
753
# File 'lib/fake_rails3_routes/mapper.rb', line 751

def options
  @options
end

#pathObject (readonly) Also known as: collection_scope

Returns the value of attribute path.



751
752
753
# File 'lib/fake_rails3_routes/mapper.rb', line 751

def path
  @path
end

Instance Method Details

#actionsObject



765
766
767
768
769
770
771
772
773
# File 'lib/fake_rails3_routes/mapper.rb', line 765

def actions
  if only = @options[:only]
    Array(only).map(&:to_sym)
  elsif except = @options[:except]
    default_actions - Array(except).map(&:to_sym)
  else
    default_actions
  end
end

#collection_nameObject

Checks for uncountable plurals, and appends “_index” if the plural and singular form are the same.



791
792
793
# File 'lib/fake_rails3_routes/mapper.rb', line 791

def collection_name
  singular == plural ? "#{plural}_index" : plural
end

#default_actionsObject



761
762
763
# File 'lib/fake_rails3_routes/mapper.rb', line 761

def default_actions
  [:index, :create, :new, :show, :update, :destroy, :edit]
end

#member_scopeObject



801
802
803
# File 'lib/fake_rails3_routes/mapper.rb', line 801

def member_scope
  "#{path}/:id"
end

#nameObject



775
776
777
# File 'lib/fake_rails3_routes/mapper.rb', line 775

def name
  @as || @name
end

#nested_scopeObject



809
810
811
# File 'lib/fake_rails3_routes/mapper.rb', line 809

def nested_scope
  "#{path}/:#{singular}_id"
end

#new_scope(new_path) ⇒ Object



805
806
807
# File 'lib/fake_rails3_routes/mapper.rb', line 805

def new_scope(new_path)
  "#{path}/#{new_path}"
end

#pluralObject



779
780
781
# File 'lib/fake_rails3_routes/mapper.rb', line 779

def plural
  @plural ||= name.to_s
end

#resource_scopeObject



795
796
797
# File 'lib/fake_rails3_routes/mapper.rb', line 795

def resource_scope
  { :controller => controller }
end

#singularObject Also known as: member_name



783
784
785
# File 'lib/fake_rails3_routes/mapper.rb', line 783

def singular
  @singular ||= name.to_s.singularize
end