Module: Qwe::Mixins::Root
- Defined in:
- lib/qwe/mixins/root.rb
Instance Method Summary collapse
- #[](id) ⇒ Object
- #commit(thing, method, *args, **keywords) ⇒ Object
- #create(klass, commit = true, **args) ⇒ Object
- #things ⇒ Object
Instance Method Details
#[](id) ⇒ Object
9 10 11 |
# File 'lib/qwe/mixins/root.rb', line 9 def [](id) @things[id] end |
#commit(thing, method, *args, **keywords) ⇒ Object
28 29 30 31 32 |
# File 'lib/qwe/mixins/root.rb', line 28 def commit(thing, method, *args, **keywords) record&.commit "#{thing.to_rb}.#{method}( " + (args.map { |a| a.to_rb }).join(", ") + (keywords.to_a.map { |a| "#{a[0]}: #{a[1].to_rb}" }).join(", ") + ")\n" end |
#create(klass, commit = true, **args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/qwe/mixins/root.rb', line 13 def create(klass, commit = true, **args) thing = (klass.is_a?(Symbol) && Object.const_get(klass) || klass).new thing.id = things.length if thing.respond_to?(:id=) thing.root = self if thing.respond_to?(:root=) if commit commit(self, :create, klass, false) thing.init if thing.respond_to?(:init) end args.each do |k, v| thing.send(:"#{k}=", v) end things.push(thing) thing end |
#things ⇒ Object
5 6 7 |
# File 'lib/qwe/mixins/root.rb', line 5 def things @things ||= [self] end |