Class: MerbResourceScope::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-resource-scope/specification.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association_method, options = {}) ⇒ Specification

Returns a new instance of Specification.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/merb-resource-scope/specification.rb', line 16

def initialize(association_method, options = {})
  @association_method = options[:association_method] && options[:association_method].to_s || association_method.to_s 
  @resource_name = options[:resource_name] && options[:resource_name].to_s || Extlib::Inflection.singularize(@association_method) 
  @singleton = options[:singleton] || false 
  @klass_name = options[:class_name] || Extlib::Inflection.classify(@resource_name) 
  @klass = Object.full_const_get(@klass_name) rescue nil
  @find_method = options[:find_method] 
  @scope_depth = options[:scope_depth] 
  @permalink = options[:permalink] || :id 
  @name_prefix = options[:name_prefix] 
  @foreign_key = options[:foreign_key] || @permalink == :id ? Extlib::Inflection.foreign_key(@resource_name).to_sym : @permalink 
end

Instance Attribute Details

#association_methodObject

Returns the value of attribute association_method.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def association_method
  @association_method
end

#find_methodObject

Returns the value of attribute find_method.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def find_method
  @find_method
end

#foreign_keyObject

Returns the value of attribute foreign_key.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def foreign_key
  @foreign_key
end

#klassObject

Returns the value of attribute klass.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def klass
  @klass
end

#klass_nameObject

Returns the value of attribute klass_name.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def klass_name
  @klass_name
end

#name_prefixObject

Returns the value of attribute name_prefix.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def name_prefix
  @name_prefix
end

Returns the value of attribute permalink.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def permalink
  @permalink
end

#resource_nameObject

Returns the value of attribute resource_name.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def resource_name
  @resource_name
end

#scope_depthObject

Returns the value of attribute scope_depth.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def scope_depth
  @scope_depth
end

#singletonObject

Returns the value of attribute singleton.



14
15
16
# File 'lib/merb-resource-scope/specification.rb', line 14

def singleton
  @singleton
end

Class Method Details

.create(association_method, options = {}) ⇒ Specification

create a specification instance

Returns:



31
32
33
34
# File 'lib/merb-resource-scope/specification.rb', line 31

def self.create(association_method, options = {})
  options = options.only(:association_method, :class_name, :singleton, :find_method, :resource_name, :foreign_key, :scope_depth, :permalink, :name_prefix)
  new(association_method, options)
end