Module: Marley::Plugins::OrmRestConvenience::ClassMethods

Defined in:
lib/marley/plugins/orm_rest_convenience.rb

Instance Method Summary collapse

Instance Method Details

#authorize(verb) ⇒ Object

the next 2 will have to be overridden for most applications



24
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 24

def authorize(verb); send_or_default("authorize_#{verb}",true) ; end

#controllerObject



22
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 22

def controller; Marley::ModelController.new(self); end

#foreign_key_nameObject



27
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 27

def foreign_key_name; :"#{(respond_to?(:table_name) ? table_name : resource_name).to_s.singularize}_id"; end

#list(params = {}) ⇒ Object



32
33
34
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 32

def list(params={})
  list_dataset(params).all
end

#list_dataset(params = {}) ⇒ Object



29
30
31
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 29

def list_dataset(params={})
  dataset.filter(params)
end

#reggae_instance_list(params = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 35

def reggae_instance_list(params={})
  items=list(params)
  if items.length==0
    Marley::ReggaeMessage.new(:title => 'Nothing Found')
  else
    cols=items[0].rest_cols
    Marley::ReggaeInstanceList.new(
      :name => resource_name,
      :schema => items[0].reggae_schema(true),
      :items => items.map{|i| cols.map{|c|i.send(c)}}
    )
  end
end

#requires_user?Boolean

Returns:

  • (Boolean)


25
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 25

def requires_user?; false; end

#stiObject



48
49
50
# File 'lib/marley/plugins/orm_rest_convenience.rb', line 48

def sti
  plugin :single_table_inheritance, :"#{self.to_s.sub(/.*::/,'').underscore}_type", :model_map => lambda{|v| MR.const_get(v.to_sym)}, :key_map => lambda{|klass|klass.name.sub(/.*::/,'')}
end