Skip to content

Instantly share code, notes, and snippets.

View lobo-tuerto's full-sized avatar

Víctor Adrián lobo-tuerto

View GitHub Profile
Merb::Config.use do |c|
c[:framework] = { :support => Merb.root/'app'/'support'}
# Sets up a custom session id key which is used for the session persistence
# cookie name. If not specified, defaults to '_session_id'.
c[:session_id_key] = '_sif_session_id'
# The session_secret_key is only required for the cookie session store.
c[:session_secret_key] = '2af3df4fcfd64df54fd0010701fad98f97bee959'
# There are various options here, by default Merb comes with 'cookie',
vcruz@vcruz-desktop:~/dev/sif$ merb --version
merb 0.9.9
vcruz@vcruz-desktop:~/dev/sif$ merb-gen app lolaz
Generating with app generator:
[ADDED] gems
[ADDED] Rakefile
[ADDED] .gitignore
[ADDED] public/.htaccess
[ADDED] app/models/merb/session.rb
[ADDED] app/views/exceptions/not_acceptable.html.erb
/home/vcruz/.thor/merb.thor:8: warning: already initialized constant MERB_THOR_VERSION
/home/vcruz/.thor/merb.thor:1127: warning: already initialized constant DM_STACK
/home/vcruz/.thor/merb.thor:1141: warning: already initialized constant MERB_STACK
/home/vcruz/.thor/merb.thor:1152: warning: already initialized constant MERB_BASICS
/home/vcruz/.thor/merb.thor:1173: warning: already initialized constant MERB_MORE
/home/vcruz/.thor/merb.thor:1185: warning: already initialized constant MERB_PLUGINS
/home/vcruz/.thor/merb.thor:1215: warning: already initialized constant DM_MORE
# This happens when trying to re-generate an app with merb-gen and overwrite it.
/usr/lib/ruby/1.8/fileutils.rb:814:in `read': Is a directory - /usr/lib/ruby/gems/1.8/gems/merb-gen-0.9.9/lib/generators/templates/application/merb/spec (Errno::EISDIR)
from /usr/lib/ruby/1.8/fileutils.rb:814:in `compare_stream'
from /usr/lib/ruby/1.8/fileutils.rb:796:in `identical?'
from /usr/lib/ruby/1.8/fileutils.rb:795:in `open'
from /usr/lib/ruby/1.8/fileutils.rb:795:in `identical?'
from /usr/lib/ruby/1.8/fileutils.rb:794:in `open'
from /usr/lib/ruby/1.8/fileutils.rb:794:in `identical?'
from /usr/lib/ruby/gems/1.8/gems/templater-0.3.1/lib/templater/actions/file.rb:42:in `identical?'
# Right now if you do this and run rake db:automigrate (I'm using postgresql)
# it will generate a table called authors_books with one column called entity_id
# instead of adding 2 columns to the table (book_id, author_id).
#
# I think that means it is getting and using the parent model from the STI hierarchy
# This was an attempt to patch it up, it's working but it's breaking one spec
# http://github.com/lobo-tuerto/dm-core/commit/c2103bc1789c05685fb111194635fa13f5707ea9
class Entity
include DataMapper::Resource
# De esta clase heredan todos los controladores
# aquí es un buen lugar para definir métodos que puedan ser
# invocados desde cualquier controlador
class Application < Merb::Controller
# Cuando alguna clase herede de ésta le declaramos (agregamos) las
# excepciones definidas en self.declara_excepciones
def self.inherited(subclass)
subclass.declara_excepciones
end
class Socios < Application
# Definimos el tipo de información que servirá este controlador
provides :json
def lista
begin
if params[:estatus].nil?
# Si no hay especificado un estatus, desplegamos todos los clientes
@resultado[:datos] = Cliente.all
class Sujeto
include DataMapper::Resource
# Configuración de las relaciones
# Puede tener un cliente asociado
has 1, :cliente, :child_key => [:sujeto_id]
has n, :direcciones, :child_key => [:sujeto_id]
# Puede tener muchos préstamos de socio
#has n, :prestamos, :child_key => [:sujeto_id]
#has n, :domicilios, :class_name => 'Address', :through => Resource, :child_key => [:subject_id]