This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AModel | |
include DataMapper::Mongo::Resource | |
property :id,ObjectId | |
property :unit, EmbeddedDocument, :document_class => MyUnits::Unit | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
radon# cat /etc/systemd/system/mongodb.service | |
[Unit] | |
Description=MongoDB Server | |
Wants=network.target | |
After=network.target | |
[Service] | |
Type=simple | |
ExecStart=/usr/bin/mongod --config /etc/mongodb.conf | |
User=mongodb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple evenstorm client library from brain | |
# Wo any testing, ZMQ API consultation etc | |
class Evenstorm | |
def initialize(connect_str) | |
@context = ZMQ::Context.new | |
@socket = @context.socket(::ZMQ::PUB) | |
@socket.connect(connect_str) | |
@socket.setsockopt(ZMQ::Linger,0) | |
at_exit do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a mapper I created when I was in hurry/spiking using: | |
# github.com/mbj/mapper (a stupid try-to-be-most-generic mapper implementation, to be rewritten) | |
# github.com/mbj/session (a database session/IdentityMap that can possibly work with any (document) mapper) | |
# the Session thing is more or less stable, and I like it! | |
# This code is not used anymore, it was replaced by a non generic application specific mapper to elasticsearch. | |
# Also this code never went to production. | |
# The whole point of this literal mess was to transform a tree of objects into a document that could be stored within mongo. | |
# The virtus object tree should be reconstructed 1:1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExternalValidator | |
def self.included(descendant) | |
descendant.class_eval do | |
InstanceMethods | |
end | |
end | |
module InstanceMethods | |
def initialize(object) | |
@object = object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Without any UoW session <=> mapper | |
session = DataMapper.session | |
user = session.get(User, 1) | |
user.mutate | |
session.sync(user) # Update on db happens | |
session.all(User) # => [MutatedUser, OtherUser] | |
# With UoW as middleware | |
session = DatAMapper.session | |
user = session.get(User, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ModuleWithMethod | |
def the_method | |
end | |
end | |
class ModuleWithContext < ::Module | |
def initialize(context) | |
@context = context | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
klass = Class.new # an anonymous class | |
klass.name # => "" does not have a name | |
Foo = klass # but when assigned to a constant: | |
p klass.name # => "Foo" it has a name! Magic! *happy* | |
Bar = klass # Again? | |
p klass.name # => "Foo" no magic :( | |
p Bar.name # => "Foo" still... | |
# Really like ruby outside of unavoidable edge cases! | |
# The assumption Class.new.name == nil can also be broken far far away from Class.new! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TreeWalker | |
def initialize(customer, &block) | |
@customer, @block = customer, blocj | |
end | |
def emit(resource) | |
@block.call(resource) | |
end | |
def customer(customer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo | |
def bar | |
:baz | |
end | |
end |