Skip to content

Instantly share code, notes, and snippets.

@bogn
bogn / approval_workflow.rb
Last active December 15, 2015 20:19
Approval Workflow on instance level
def approval_by(role)
singleton_class_with_workflow = class << self
approval = self.class.approval_transitions_for[role]
workflow do
(approval || []).each do |state_name, events|
state state_name do
events.each do |event_name|
event event_name, transitions_to: EVENT_RESULTS[event_name]
end
end
@bogn
bogn / example.xml
Last active December 11, 2015 13:38
example.xml is the desired output, but the schema has to repeat the locales for the anyURI variant. Is there any alternative to repeating them?
<?xml version="1.0" encoding="UTF-8"?>
<application>
<title>
<text xml:lang="de"><![CDATA[]]></text>
<text xml:lang="en"><![CDATA[]]></text>
<text xml:lang="fr"><![CDATA[]]></text>
</title>
<picture>
<uri xml:lang="de">file://example1.jpg</uri>
<uri xml:lang="en">file://example2.jpg</uri>
@bogn
bogn / Tire-_type-field-corruption.rb
Created October 11, 2012 14:19
Tire: STI field _type get's corrupted by update_index callback on second call to save
require 'mongo_mapper'
MongoMapper.database = 'testing'
require 'tire'
class Thing
include MongoMapper::Document
include Tire::Model::Search
include Tire::Model::Callbacks
end
@bogn
bogn / gist:2769213
Created May 22, 2012 13:51
Ruby 1.9.3p0 hex bug
1.9.3p0 :001 > "​10FFFF".to_i 16
=> 0
1.9.3p0 :002 > exit
bogn@Mojito:~$ irb
1.9.3p0 :001 > "10FFFF".to_i(16)
=> 1114111
1.9.3p0 :002 > "10FFFF".to_i 16
=> 1114111
und noch mal mit p194
1.9.3p194 :001 > "10FFFF".to_i 16
$ gem install plist4r --verbose --backtrace --debug
Exception `NameError' at /home/bogn/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/command_manager.rb:177 - uninitialized constant Gem::Commands::InstallCommand
Exception `Gem::LoadError' at /home/bogn/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247 - Could not find psych (>= 1.2.1, ~> 1.2) amongst [RedCloth-4.2.7, aaronh-chronic-0.3.9, abstract-1.0.0, actionmailer-3.0.9, actionmailer-3.0.7, actionmailer-3.0.5, actionmailer-3.0.4, actionmailer-3.0.3, actionmailer-2.3.2, actionmailer-2.1.0, actionmailer-1.3.3, actionpack-3.0.9, actionpack-3.0.7, actionpack-3.0.5, actionpack-3.0.4, actionpack-3.0.3, actionpack-3.0.0.beta3, actionpack-2.3.2, actionpack-2.1.0, actionpack-1.13.3, actionwebservice-1.2.3, activemodel-3.0.10, activemodel-3.0.9, activemodel-3.0.7, activemodel-3.0.6, activemodel-3.0.5, activemodel-3.0.4, activemodel-3.0.3, activemodel-3.0.0.beta3, activerecord-3.0.9, activerecord-3.0.7, activerecord-3.0.5
class Page
include MongoMapper::Document
end
class ContentPage < Page
many :content_blocks #tried :as => :page as well
end
class ContentBlock
include MongoMapper::EmbeddedDocument