mushin 0.25.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/generator.rb +168 -0
- data/exe/mushin +45 -51
- data/lib/mushin/builtin/ssd/ssd.rb +50 -0
- data/lib/mushin/{main.rb → domain.rb} +14 -73
- data/lib/mushin/logger.rb +15 -15
- data/lib/mushin/service.rb +18 -0
- data/lib/mushin/store.rb +16 -0
- data/lib/mushin/version.rb +1 -1
- data/lib/mushin.rb +2 -2
- data/mushin.gemspec +1 -1
- data/showcases/gamification_showcase/README.md +9 -0
- data/showcases/gamification_showcase/gameon/lib/gameon/builtin/badges.rb +0 -0
- data/showcases/gamification_showcase/gameon/lib/gameon/version.rb +0 -0
- data/showcases/gamification_showcase/gameon/lib/gameon.rb +9 -0
- data/showcases/gamification_showcase/points/points.rb +1 -0
- data/showcases/gamification_showcase/sample_app/app.rb +0 -0
- data/showcases/gamification_showcase/sample_app/ext/levels/levels.rb +0 -0
- data/{samples → showcases}/sample3.rb +6 -3
- data/showcases/torrents_showcase/README.md +6 -0
- metadata +33 -15
- data/hacks/bot.rb +0 -236
- data/hacks/cqrs/command.rb +0 -123
- data/hacks/cqrs/query.rb +0 -200
- data/hacks/domain.rb +0 -35
- data/hacks/dsl.rb +0 -39
- data/hacks/dsl_builder.rb +0 -29
- data/hacks/es/event.rb +0 -18
- data/hacks/es/event_stream.rb +0 -33
- data/hacks/generator.rb +0 -68
- /data/{samples → showcases}/sample1.rb +0 -0
- /data/{samples → showcases}/sample2.rb +0 -0
File without changes
|
@@ -43,7 +43,10 @@ module Sample
|
|
43
43
|
class Mongodb < Mushin::Test::Sample::Ext; end
|
44
44
|
|
45
45
|
class Domain
|
46
|
+
include Mushin::Domain
|
47
|
+
#extend Mushin::Domain
|
46
48
|
using Mushin::Domain
|
49
|
+
#extend Mushin::Main
|
47
50
|
|
48
51
|
context "torrent_bots" do
|
49
52
|
construct "tpb" do
|
@@ -74,13 +77,13 @@ module Sample
|
|
74
77
|
params[:secret] = "8888"
|
75
78
|
|
76
79
|
torrent_bots do
|
77
|
-
tpb search_result_max: "20", storage_path:"crazypath_here"
|
80
|
+
tpb search_result_max: "20", storage_path:"crazypath_here", store: "ssd"
|
78
81
|
rutracker search_result_max: params[:secret]
|
79
82
|
end
|
80
83
|
|
81
84
|
query do
|
82
|
-
torrentsA path_valueA: "this is a torrentsA pathvalueA", seeders_valueA: "30torrentA", path_valueB: "this is torrentsA pathvalueB",
|
83
|
-
torrentsB
|
85
|
+
torrentsA path_valueA: "this is a torrentsA pathvalueA", seeders_valueA: "30torrentA", path_valueB: "this is torrentsA pathvalueB", seeders_valueB: "30torrentB"
|
86
|
+
torrentsB path_valueA: "this is a torrentsB pathvalue", path_valueB: "koko", seeders_valueA: "30torrentA", seeders_valueB: "anna"
|
84
87
|
#torrentsB keyword: "torrentsB nononononon", seeders: "30"
|
85
88
|
end
|
86
89
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
This directory contains:
|
2
|
+
|
3
|
+
- FetchTorrentz: a sample mushin domain-specific framework for searching torrent websites
|
4
|
+
- TPB: a sample built-in mushin extenstion for FetchTorrentz to search ThePirateBay
|
5
|
+
- RUTracker: a sample standalone mushin extenstion for FetchTorrentz
|
6
|
+
- SampleApp: a sample application using FetchTorrentz framework
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mushin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.26.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zotherstupidguy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,10 +108,25 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ssd
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: mushin allows you to generate domain-specific frameworks and domain extenstions.
|
112
126
|
email:
|
113
127
|
- zotherstupidguy@gmail.com
|
114
128
|
executables:
|
129
|
+
- generator.rb
|
115
130
|
- mushin
|
116
131
|
extensions: []
|
117
132
|
extra_rdoc_files: []
|
@@ -126,27 +141,30 @@ files:
|
|
126
141
|
- about.md
|
127
142
|
- bin/console
|
128
143
|
- bin/setup
|
144
|
+
- exe/generator.rb
|
129
145
|
- exe/mushin
|
130
|
-
- hacks/bot.rb
|
131
|
-
- hacks/cqrs/command.rb
|
132
|
-
- hacks/cqrs/query.rb
|
133
|
-
- hacks/domain.rb
|
134
|
-
- hacks/dsl.rb
|
135
|
-
- hacks/dsl_builder.rb
|
136
|
-
- hacks/es/event.rb
|
137
|
-
- hacks/es/event_stream.rb
|
138
|
-
- hacks/generator.rb
|
139
146
|
- lib/mushin.rb
|
147
|
+
- lib/mushin/builtin/ssd/ssd.rb
|
148
|
+
- lib/mushin/domain.rb
|
140
149
|
- lib/mushin/ext.rb
|
141
150
|
- lib/mushin/logger.rb
|
142
|
-
- lib/mushin/
|
151
|
+
- lib/mushin/service.rb
|
143
152
|
- lib/mushin/stack.rb
|
153
|
+
- lib/mushin/store.rb
|
144
154
|
- lib/mushin/test_helper.rb
|
145
155
|
- lib/mushin/version.rb
|
146
156
|
- mushin.gemspec
|
147
|
-
-
|
148
|
-
-
|
149
|
-
-
|
157
|
+
- showcases/gamification_showcase/README.md
|
158
|
+
- showcases/gamification_showcase/gameon/lib/gameon.rb
|
159
|
+
- showcases/gamification_showcase/gameon/lib/gameon/builtin/badges.rb
|
160
|
+
- showcases/gamification_showcase/gameon/lib/gameon/version.rb
|
161
|
+
- showcases/gamification_showcase/points/points.rb
|
162
|
+
- showcases/gamification_showcase/sample_app/app.rb
|
163
|
+
- showcases/gamification_showcase/sample_app/ext/levels/levels.rb
|
164
|
+
- showcases/sample1.rb
|
165
|
+
- showcases/sample2.rb
|
166
|
+
- showcases/sample3.rb
|
167
|
+
- showcases/torrents_showcase/README.md
|
150
168
|
homepage: http://mushin-rb.github.io/
|
151
169
|
licenses:
|
152
170
|
- MIT
|
data/hacks/bot.rb
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
require 'rss'
|
3
|
-
require 'cinch'
|
4
|
-
require 'singleton'
|
5
|
-
|
6
|
-
module Mushin
|
7
|
-
# Mushin speaks via eventsourcing, Mushin::Bot allows Mushin to be heard on IRC, RSS, etc.!
|
8
|
-
module Bot
|
9
|
-
|
10
|
-
# def self.config irc_server: nil, irc_channel: nil
|
11
|
-
# self.irc_server = irc_server
|
12
|
-
# self.irc_channel = irc_channel
|
13
|
-
# end
|
14
|
-
|
15
|
-
# class << self
|
16
|
-
# attr_accessor :irc_server
|
17
|
-
# attr_accessor :irc_channel
|
18
|
-
# end
|
19
|
-
|
20
|
-
#def initialize &block
|
21
|
-
# instance_eval &block
|
22
|
-
#end
|
23
|
-
|
24
|
-
# def irc message: nil, &block
|
25
|
-
# IRC.new(message).instance_eval &block
|
26
|
-
# end
|
27
|
-
|
28
|
-
# C&C and allows communication among a number of microservies over a number of context specific #channels
|
29
|
-
# A Distrubted Rule-based system where each node has its rules-engine and post on a channel and get conditions from the channel, continously adopting to the most recent state of the system.
|
30
|
-
class IRC
|
31
|
-
include Singleton
|
32
|
-
|
33
|
-
attr_accessor :bot, :server, :channels, :nick
|
34
|
-
|
35
|
-
def initialize
|
36
|
-
@bot = Cinch::Bot.new
|
37
|
-
@server = ""
|
38
|
-
@channels = []
|
39
|
-
@nick = "mushin_botapp_name"
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.config &block
|
43
|
-
end
|
44
|
-
|
45
|
-
def log message: nil
|
46
|
-
@bot.configure do |c|
|
47
|
-
c.server = @server #Mushin::Bot.irc_server #"irc.freenode.org"
|
48
|
-
c.channels = @channels #[Mushin::Bot.irc_channel] #["#cinch-bots"]
|
49
|
-
end
|
50
|
-
|
51
|
-
@bot.on :connect do |m|
|
52
|
-
|
53
|
-
end
|
54
|
-
|
55
|
-
@bot.on :join do |m|
|
56
|
-
m.reply "Hello, #{message}"
|
57
|
-
end
|
58
|
-
|
59
|
-
@bot.on :message, "hello" do |m|
|
60
|
-
m.reply "Hello, #{m.user.nick}"
|
61
|
-
end
|
62
|
-
|
63
|
-
@bot.on :exit do |m|
|
64
|
-
m.reply "goodbye, #{m.user.nick}"
|
65
|
-
end
|
66
|
-
|
67
|
-
@bot.start
|
68
|
-
Thread.new do
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
#TODO from console `mushin publish /path/to/event/stream`
|
75
|
-
class RSS
|
76
|
-
def initialize path: nil, key: nil, url: "/", port: 9999
|
77
|
-
rss url: url, port: port
|
78
|
-
@data = SSD.dump path, key unless path.nil? || key.nil?
|
79
|
-
end
|
80
|
-
def rss url: "/", port: "9494"
|
81
|
-
server = Class.new(Sinatra::Base) do
|
82
|
-
set :port, port
|
83
|
-
get "#{url}" do
|
84
|
-
"yay"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
server.run!
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
#stream = Mushin::EventStream.new
|
95
|
-
#stream.rss url: "/eventstream", port: 9999
|
96
|
-
|
97
|
-
=begin
|
98
|
-
x = "crazy"
|
99
|
-
get "/" do
|
100
|
-
rss = RSS::Maker.make("atom") do |maker|
|
101
|
-
maker.channel.author = "matz"
|
102
|
-
maker.channel.updated = Time.now.to_s
|
103
|
-
maker.channel.about = "http://www.ruby-lang.org/en/feeds/news.rss"
|
104
|
-
maker.channel.title = "upjoystream::v1::bots"
|
105
|
-
maker.channel.description = "upjoystream::v1::bots logsdfssfdasfasfasfasdfasdflasdfsafasfasf"
|
106
|
-
|
107
|
-
maker.items.new_item do |item|
|
108
|
-
item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
|
109
|
-
item.title = "ass"
|
110
|
-
item.updated = Time.now.to_s
|
111
|
-
end
|
112
|
-
|
113
|
-
maker.items.image_item do |item|
|
114
|
-
item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
|
115
|
-
item.title = "shitssssssssss"
|
116
|
-
item.updated = Time.now.to_s
|
117
|
-
p item.methods
|
118
|
-
item.link = "/home/zotherstupidguy/Pictures/10923261.jpg"
|
119
|
-
#item.image_item = "/home/zotherstupidguy/Pictures/10923261.jpg"
|
120
|
-
item.description = "this is a json turned into xml to be viewed here like shit or maybe stayed as json upjoystream::v1::bots logsdfssfdasfasfasfasdfasdflasdfsafasfasf"
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
p rss.methods
|
125
|
-
return rss.to_s
|
126
|
-
end
|
127
|
-
require 'date'
|
128
|
-
require 'logger'
|
129
|
-
require 'rss'
|
130
|
-
require 'open-uri'
|
131
|
-
|
132
|
-
# UNKNOWN: An unknown message that should always be logged.
|
133
|
-
# FATAL: An unhandleable error that results in a program crash.
|
134
|
-
# ERROR: A handleable error condition.
|
135
|
-
# WARN: A warning.
|
136
|
-
# INFO: Generic (useful) information about system operation.
|
137
|
-
# DEBUG: Low-level information for developers.
|
138
|
-
def self.logger(shift_age: 'daily',
|
139
|
-
datetime_format: '%Y-%m-%d %H:%M:%S',
|
140
|
-
log_dir: 'logs'
|
141
|
-
)
|
142
|
-
Dir.mkdir(log_dir) unless File.exists?(log_dir)
|
143
|
-
logger_file = "#{log_dir}/#{DateTime.now.strftime('%m_%d_%Y')}.log"
|
144
|
-
file = File.open(logger_file, File::WRONLY | File::APPEND | File::CREAT)
|
145
|
-
@log = Logger.new("| tee " + file.path, shift_age)
|
146
|
-
@log.datetime_format = datetime_format
|
147
|
-
@log.info "Utter Log Levels: DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN"
|
148
|
-
return @log
|
149
|
-
end
|
150
|
-
|
151
|
-
rss = RSS::Maker.make("atom") do |maker|
|
152
|
-
maker.channel.author = "matz"
|
153
|
-
maker.channel.updated = Time.now.to_s
|
154
|
-
maker.channel.about = "http://www.ruby-lang.org/en/feeds/news.rss"
|
155
|
-
maker.channel.title = "Example Feed"
|
156
|
-
|
157
|
-
maker.items.new_item do |item|
|
158
|
-
item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
|
159
|
-
item.title = "Ruby 1.9.2-p136 is released"
|
160
|
-
item.updated = Time.now.to_s
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
puts rss
|
165
|
-
|
166
|
-
$log = logger
|
167
|
-
class Domain
|
168
|
-
attr :store
|
169
|
-
attr :query
|
170
|
-
attr :log
|
171
|
-
def initialize id
|
172
|
-
p id
|
173
|
-
end
|
174
|
-
def query params={}
|
175
|
-
end
|
176
|
-
def log params={}
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
d = Domain.new 'id' do
|
181
|
-
store = "sss"
|
182
|
-
end
|
183
|
-
p $log
|
184
|
-
$log.info d
|
185
|
-
|
186
|
-
#===========
|
187
|
-
id = "all the kings men"
|
188
|
-
d = Domain.new do
|
189
|
-
end
|
190
|
-
|
191
|
-
class Domain
|
192
|
-
def initialize
|
193
|
-
end
|
194
|
-
|
195
|
-
def command
|
196
|
-
torrent_bots do
|
197
|
-
tpb query: id
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def query 'id'
|
202
|
-
mongodb path: "xx"
|
203
|
-
ssd
|
204
|
-
redis
|
205
|
-
end
|
206
|
-
|
207
|
-
def log
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
Domain.log.publish("url")
|
212
|
-
#===========
|
213
|
-
|
214
|
-
#p d.to_xml
|
215
|
-
# In mushin, event sourcing is to capture all changes to an a domain state as a sequence of events."
|
216
|
-
# Mushin separates business logic(domain logic) into Commands and Queries
|
217
|
-
# state transitions are important part of our problem space and should be modeled within our domain.
|
218
|
-
|
219
|
-
# Event Sourcing persists each domain object as a sequence of events, which are replayed to reconstruct the current state.
|
220
|
-
#
|
221
|
-
#
|
222
|
-
# ideaA
|
223
|
-
result = d.store # returns the a complete hash thing from what was stored via the command domain object process
|
224
|
-
result = d.query tpb: "ss" # returns a selection from the whole thing of the store
|
225
|
-
|
226
|
-
# seperate microservice for read, and seperate microservice for writes and both communicate via the log regardless of the databases they use.
|
227
|
-
#
|
228
|
-
result = d.log #
|
229
|
-
result = d.log tpb: "ss" # returns the latest log state
|
230
|
-
|
231
|
-
# ideaB
|
232
|
-
#result = Domain.query torrent_bots: "ss"
|
233
|
-
#result = Domain.query tpb: "ss"
|
234
|
-
#result = Domain.query context: "torrent_bots"
|
235
|
-
#result = Domain.query construct: "tpb"
|
236
|
-
=end
|
data/hacks/cqrs/command.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
module Mushin
|
2
|
-
module DSLBuilder
|
3
|
-
module CQRS
|
4
|
-
|
5
|
-
class Command
|
6
|
-
|
7
|
-
# attr for a dsl context constructor class
|
8
|
-
attr_accessor :app_dsl_context_klass
|
9
|
-
attr_accessor :constructs
|
10
|
-
|
11
|
-
def initialize context_keyword, &block
|
12
|
-
dsl_module = Module.new do
|
13
|
-
end
|
14
|
-
Mushin.const_set(:DSL, dsl_module)
|
15
|
-
Mushin::Domain.send :include, Mushin::DSL
|
16
|
-
|
17
|
-
@constructs = []
|
18
|
-
#@app_dsl_context_klass = app_dsl_context_access_method_and_klass(context_keyword, dsl_module)
|
19
|
-
@app_dsl_context_klass = app_dsl_context_access_method_and_klass(context_keyword, Mushin::DSL)
|
20
|
-
instance_eval &block
|
21
|
-
end
|
22
|
-
|
23
|
-
def construct construct_keyword, &block
|
24
|
-
@constructs << Construct.new(construct_keyword, @app_dsl_context_klass, &block)
|
25
|
-
end
|
26
|
-
|
27
|
-
def app_dsl_context_access_method_and_klass(context_keyword, parent_klass)
|
28
|
-
$log.debug "dynamically building app dsl context access method for: #{context_keyword}, inside: #{parent_klass}" #.reverse_color
|
29
|
-
|
30
|
-
parent_klass.class_eval do
|
31
|
-
define_method(context_keyword) do |&block|
|
32
|
-
parent_klass.const_get(context_keyword.capitalize).new &block #if block_given?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
k = Class.new do
|
37
|
-
def initialize &block
|
38
|
-
instance_eval &block
|
39
|
-
end
|
40
|
-
end
|
41
|
-
# check if the const is already defined to avoid warnings
|
42
|
-
parent_klass.const_set(context_keyword.capitalize, k) unless parent_klass.const_defined?(context_keyword.capitalize)
|
43
|
-
|
44
|
-
return parent_klass.const_get(context_keyword.capitalize)
|
45
|
-
end
|
46
|
-
|
47
|
-
class Construct
|
48
|
-
attr_accessor :context_klass, :construct_klass
|
49
|
-
attr_accessor :ext_set
|
50
|
-
|
51
|
-
def initialize construct_keyword, context_klass, &block
|
52
|
-
@construct_keyword = construct_keyword
|
53
|
-
@context_klass = context_klass
|
54
|
-
$log.debug "@ext_set inside #{self} equals []"
|
55
|
-
@ext_set = []
|
56
|
-
|
57
|
-
instance_eval &block
|
58
|
-
|
59
|
-
$log.debug "@ext_set inside #{self} equals #{@ext_set}"
|
60
|
-
@construct_klass = dsl_construct_access_method_and_klass(@construct_keyword, @ext_set, @context_klass)
|
61
|
-
end
|
62
|
-
|
63
|
-
def use args = {}
|
64
|
-
@ext_set << args
|
65
|
-
end
|
66
|
-
|
67
|
-
def dsl_construct_access_method_and_klass(construct_keyword, ext_set, parent_klass)
|
68
|
-
$log.debug "dynamically building app dsl construct access method for: #{construct_keyword}, inside: #{parent_klass}"
|
69
|
-
ext_set.reverse!
|
70
|
-
|
71
|
-
$log.debug "ext_set reserved inside #{self} equals #{ext_set}"
|
72
|
-
|
73
|
-
parent_klass.class_eval do
|
74
|
-
define_method(construct_keyword) do |args = {}|
|
75
|
-
ext_set.each do |ext|
|
76
|
-
ext[:params].each do |key, value|
|
77
|
-
args.each do |env_key, env_value|
|
78
|
-
if env_key.to_sym == value then
|
79
|
-
ext[:params][key] = env_value
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end unless ext[:params].nil?
|
83
|
-
|
84
|
-
ext[:opts].each do |key, value|
|
85
|
-
args.each do |env_key, env_value|
|
86
|
-
if env_key.to_sym == value then
|
87
|
-
ext[:opts][key] = env_value
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end unless ext[:opts].nil?
|
91
|
-
$log.debug ext
|
92
|
-
end
|
93
|
-
|
94
|
-
parent_klass.const_get(construct_keyword.capitalize).new args, ext_set
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
k = Class.new do
|
99
|
-
attr_accessor :stack
|
100
|
-
def initialize args={}, ext_set
|
101
|
-
$log.debug "hahahaha"
|
102
|
-
$log.debug ext_set
|
103
|
-
@stack = Mushin::Stack.new
|
104
|
-
|
105
|
-
ext_set.each do |ext|
|
106
|
-
@stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
|
107
|
-
#@stack.insert_after_each (Mushin::ES::EventStream)
|
108
|
-
end
|
109
|
-
|
110
|
-
@stack.call
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# check if the const is already defined to avoid warnings
|
115
|
-
parent_klass.const_set(construct_keyword.capitalize, k) unless parent_klass.const_defined?(construct_keyword.capitalize)
|
116
|
-
|
117
|
-
return parent_klass.const_get(construct_keyword.capitalize)
|
118
|
-
end
|
119
|
-
end # end of Construct klass
|
120
|
-
end # end of Command klass (Context klass)
|
121
|
-
end # end of CQRS module
|
122
|
-
end # end of DSLBuilder module
|
123
|
-
end # end of Mushin module
|
data/hacks/cqrs/query.rb
DELETED
@@ -1,200 +0,0 @@
|
|
1
|
-
module Mushin
|
2
|
-
module DSLBuilder
|
3
|
-
module CQRS
|
4
|
-
class Query
|
5
|
-
|
6
|
-
def initialize &block
|
7
|
-
@app_dsl_query_klass = app_dsl_query_access_method_and_klass("query", Mushin::DSL)
|
8
|
-
instance_eval &block
|
9
|
-
end
|
10
|
-
|
11
|
-
def construct construct_keyword, &block
|
12
|
-
Construct.new construct_keyword, @app_dsl_query_klass, &block
|
13
|
-
end
|
14
|
-
|
15
|
-
def app_dsl_query_access_method_and_klass(query_keyword, parent_klass)
|
16
|
-
$log.info "Query for: #{query_keyword}, inside: #{parent_klass}"
|
17
|
-
|
18
|
-
parent_klass.class_eval do
|
19
|
-
define_method(query_keyword) do |&block|
|
20
|
-
parent_klass.const_get(query_keyword.capitalize).new &block #if block_given?
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
k = Class.new do
|
25
|
-
def initialize &block
|
26
|
-
instance_eval &block
|
27
|
-
end
|
28
|
-
end
|
29
|
-
parent_klass.const_set(query_keyword.capitalize, k) unless parent_klass.const_defined?(query_keyword.capitalize)
|
30
|
-
return parent_klass.const_get(query_keyword.capitalize)
|
31
|
-
end
|
32
|
-
|
33
|
-
class Construct
|
34
|
-
attr_accessor :context_klass, :construct_klass, :ext_set
|
35
|
-
|
36
|
-
def initialize construct_keyword, context_klass, &block
|
37
|
-
|
38
|
-
|
39
|
-
@construct_keyword = construct_keyword
|
40
|
-
@context_klass = context_klass
|
41
|
-
@ext_set = []
|
42
|
-
|
43
|
-
instance_eval &block
|
44
|
-
|
45
|
-
@construct_klass = dsl_construct_access_method_and_klass(@construct_keyword, @ext_set, @context_klass)
|
46
|
-
end
|
47
|
-
|
48
|
-
def use args = {}
|
49
|
-
@ext_set << args
|
50
|
-
end
|
51
|
-
|
52
|
-
def dsl_construct_access_method_and_klass(construct_keyword, ext_set, parent_klass)
|
53
|
-
|
54
|
-
|
55
|
-
$log.info "Query for: #{construct_keyword}, inside: #{parent_klass}"
|
56
|
-
ext_set.reverse!
|
57
|
-
parent_klass.class_eval do
|
58
|
-
define_method(construct_keyword) do |args = {}|
|
59
|
-
|
60
|
-
|
61
|
-
ext_set.each do |ext|
|
62
|
-
ext[:params].each do |key, value|
|
63
|
-
args.each do |env_key, env_value|
|
64
|
-
if env_key.to_sym == value then
|
65
|
-
ext[:params][key] = env_value
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end unless ext[:params].nil?
|
69
|
-
|
70
|
-
ext[:opts].each do |key, value|
|
71
|
-
args.each do |env_key, env_value|
|
72
|
-
if env_key.to_sym == value then
|
73
|
-
ext[:opts][key] = env_value
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end unless ext[:opts].nil?
|
77
|
-
$log.info ext
|
78
|
-
end
|
79
|
-
|
80
|
-
obj = parent_klass.const_get(construct_keyword.capitalize).new args, ext_set
|
81
|
-
|
82
|
-
Mushin::DSL.class_eval do
|
83
|
-
define_method(construct_keyword) do |&block|
|
84
|
-
#p "need to get this #{construct_keyword} and create a method of it inside Mushin::DSL, with the value of obj: #{obj.stack.call}"
|
85
|
-
#$log.info "Query for: #{construct_keyword}, inside: #{parent_klass}"
|
86
|
-
#return "get the value from @stack.call, some freakin how!!!"
|
87
|
-
return obj.stack.call
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
k = Class.new do
|
95
|
-
attr_accessor :stack
|
96
|
-
def initialize args={}, ext_set
|
97
|
-
p ext_set
|
98
|
-
@stack = Mushin::Stack.new
|
99
|
-
|
100
|
-
ext_set.each do |ext|
|
101
|
-
@stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
|
102
|
-
end
|
103
|
-
$log.debug "printing the stack value #{@stack.call}"
|
104
|
-
return @stack.call
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
parent_klass.const_set(construct_keyword.capitalize, k) unless parent_klass.const_defined?(construct_keyword.capitalize)
|
109
|
-
|
110
|
-
return parent_klass.const_get(construct_keyword.capitalize)
|
111
|
-
end
|
112
|
-
end # end of Construct klass
|
113
|
-
end # end of Query klass
|
114
|
-
end # end of CQRS module
|
115
|
-
end # end of DSLBuilder module
|
116
|
-
end # end of Mushin module
|
117
|
-
|
118
|
-
#self.class.send :attr_accessor, construct_key
|
119
|
-
#instance_eval("@#{construct_key} = 'koko'")
|
120
|
-
#send :instance_variable_set, "@#{construct_key}", 'koko'
|
121
|
-
#self.singleton_class.send(:attr_accessor, construct_key)
|
122
|
-
#self.singleton_class.send :instance_variable_set, "@#{construct_key}", "koko"
|
123
|
-
#
|
124
|
-
|
125
|
-
=begin
|
126
|
-
# CQRS query
|
127
|
-
def query &query_block
|
128
|
-
@@dsl_tree.each do |context_set|
|
129
|
-
|
130
|
-
context_set.each do |context_key, context_value|
|
131
|
-
p "context_key #{context_key} | context_value #{context_value}"
|
132
|
-
self.singleton_class.send :define_method, context_key do |&context_block|
|
133
|
-
context_value.each do |c|
|
134
|
-
c.each do |construct_key, construct_value|
|
135
|
-
p "construct_key #{construct_key} | construct_value #{construct_value}"
|
136
|
-
self.singleton_class.send :define_method, construct_key do |data = Hash.new|
|
137
|
-
p "------data-------"
|
138
|
-
p data
|
139
|
-
p data.class
|
140
|
-
data.each do |k, v|
|
141
|
-
p k
|
142
|
-
p v
|
143
|
-
end
|
144
|
-
p "------data-------"
|
145
|
-
p construct_value.class
|
146
|
-
|
147
|
-
@stack = Mushin::Stack.new
|
148
|
-
construct_value.each do |ext|
|
149
|
-
#p ext_hash
|
150
|
-
#p ext_hash.keys
|
151
|
-
##p ext_hash.values
|
152
|
-
p ext
|
153
|
-
p ext[:params]
|
154
|
-
ext[:params].each do |ext_key, ext_value|
|
155
|
-
p data
|
156
|
-
data.each do |data_key, data_value|
|
157
|
-
if data_key.to_sym == ext_value then
|
158
|
-
p data_value
|
159
|
-
ext[:params][ext_key] = data_value
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end unless ext[:params].nil?
|
163
|
-
|
164
|
-
ext[:opts].each do |key, value|
|
165
|
-
data.each do |data_key, data_value|
|
166
|
-
if data_key.to_sym == value then
|
167
|
-
ext[:opts][key] = data_value
|
168
|
-
end
|
169
|
-
end
|
170
|
-
end unless ext[:opts].nil?
|
171
|
-
p "insert_before 0 into stack: #{ext[:ext]}, #{ext[:opts]}, #{ext[:params]}"
|
172
|
-
@stack.insert_before 0, ext[:ext], ext[:opts], ext[:params]
|
173
|
-
end
|
174
|
-
@stack.call
|
175
|
-
end
|
176
|
-
#instance_eval("undef :#{construct_key}")
|
177
|
-
end
|
178
|
-
end
|
179
|
-
instance_eval &context_block
|
180
|
-
|
181
|
-
|
182
|
-
context_set[context_key].each do |construct_hash|
|
183
|
-
p "xxxxxx"
|
184
|
-
construct_hash.keys.each do |method_key|
|
185
|
-
p method_key
|
186
|
-
instance_eval("undef :#{method_key}")
|
187
|
-
end
|
188
|
-
p "construct_key #{context_key} is undef-ed"
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
if !query_block.nil? then
|
195
|
-
instance_eval &query_block
|
196
|
-
else
|
197
|
-
fail "a query_block is required"
|
198
|
-
end
|
199
|
-
end
|
200
|
-
=end
|