Module: Strobe::Resource::Base::ClassMethods
- Defined in:
- lib/strobe/resource/base.rb
Instance Method Summary collapse
- #associations ⇒ Object
- #base_const_name ⇒ Object
- #filter(*params) ⇒ Object
- #has(cardinality, name, options = {}) ⇒ Object
- #include_query_string ⇒ Object
- #n ⇒ Object
- #resource_name ⇒ Object
- #root(root = nil) ⇒ Object
- #singular_resource_name ⇒ Object
- #uri_prefix ⇒ Object
Instance Method Details
#associations ⇒ Object
49 50 51 |
# File 'lib/strobe/resource/base.rb', line 49 def associations @associations ||= {} end |
#base_const_name ⇒ Object
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, = {}) assoc = Association.new(self, cardinality, name, ) class_eval(assoc.reader) class_eval(assoc.writer) if assoc.nested? validates_with AssociationValidator, :attributes => [name] end associations[assoc.name] = assoc end |
#include_query_string ⇒ Object
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 |
#n ⇒ Object
24 25 26 |
# File 'lib/strobe/resource/base.rb', line 24 def n :n end |
#resource_name ⇒ Object
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_name ⇒ Object
61 62 63 |
# File 'lib/strobe/resource/base.rb', line 61 def singular_resource_name raise NotImplementedError, 'Implemented in a subclass' end |
#uri_prefix ⇒ Object
65 66 67 |
# File 'lib/strobe/resource/base.rb', line 65 def uri_prefix @uri_prefix ||= "/#{resource_name}" end |