Module: Strobe::Resource::Base::ClassMethods

Defined in:
lib/strobe/resource/base.rb

Instance Method Summary collapse

Instance Method Details

#associationsObject



49
50
51
# File 'lib/strobe/resource/base.rb', line 49

def associations
  @associations ||= {}
end

#base_const_nameObject



53
54
55
# File 'lib/strobe/resource/base.rb', line 53

def base_const_name
  name.gsub(/^Strobe::Resources::/, '')
end

#filter(*params) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/strobe/resource/base.rb', line 41

def filter(*params)
  @filter ||= []

  return @filter if params.empty?

  @filter |= params.map { |p| p.to_s }
end

#has(cardinality, name, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/strobe/resource/base.rb', line 28

def has(cardinality, name, options = {})
  assoc = Association.new(self, cardinality, name, options)

  class_eval(assoc.reader)
  class_eval(assoc.writer)

  if assoc.nested?
    validates_with AssociationValidator, :attributes => [name]
  end

  associations[assoc.name] = assoc
end

#include_query_stringObject



75
76
77
78
79
80
81
82
83
# File 'lib/strobe/resource/base.rb', line 75

def include_query_string
  to_include = associations.map do |n, assoc|
    assoc.target_pluralized if assoc.include?
  end.compact

  if to_include.any?
    "include=#{to_include.join(',')}"
  end
end

#nObject



24
25
26
# File 'lib/strobe/resource/base.rb', line 24

def n
  :n
end

#resource_nameObject

Raises:

  • (NotImplementedError)


57
58
59
# File 'lib/strobe/resource/base.rb', line 57

def resource_name
  raise NotImplementedError, 'Implemented in a subclass'
end

#root(root = nil) ⇒ Object



69
70
71
72
73
# File 'lib/strobe/resource/base.rb', line 69

def root(root = nil)
  @root ||= singular_resource_name
  @root = root if root
  @root
end

#singular_resource_nameObject

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/strobe/resource/base.rb', line 61

def singular_resource_name
  raise NotImplementedError, 'Implemented in a subclass'
end

#uri_prefixObject



65
66
67
# File 'lib/strobe/resource/base.rb', line 65

def uri_prefix
  @uri_prefix ||= "/#{resource_name}"
end