jenga 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c5cccb7a63c6e4aa010829aad4f62559aaa11eac
4
+ data.tar.gz: 5be313bdfc42a7dfe893fb854def9c7c79aa9cdf
5
+ SHA512:
6
+ metadata.gz: 4820d415da486e94f0ff38b072267c506c85abd3486868fa03840fe83c5065c554ff2ff9dffb428108460e96c7c01dacb3e5fbb90d6e6c092e7a5537406b4ae4
7
+ data.tar.gz: 87611883975f89c3fde0024cb4502c0c268bbe789005d024e65ff604ddc6ad695816736d77b978cda9172881bb7968bed00df2d114543dda05e1ac8998ef7aa1
@@ -0,0 +1,2 @@
1
+ .ruby-*
2
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jenga.gemspec
4
+ gemspec
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jenga (0.1.0)
5
+ bson_ext
6
+ mongo (~> 2.1)
7
+ redis
8
+ serialport (~> 1.3)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ bson (3.2.6)
14
+ bson_ext (1.5.1)
15
+ diff-lcs (1.2.5)
16
+ mongo (2.1.2)
17
+ bson (~> 3.0)
18
+ rake (10.5.0)
19
+ redis (3.3.1)
20
+ rspec (3.5.0)
21
+ rspec-core (~> 3.5.0)
22
+ rspec-expectations (~> 3.5.0)
23
+ rspec-mocks (~> 3.5.0)
24
+ rspec-core (3.5.3)
25
+ rspec-support (~> 3.5.0)
26
+ rspec-expectations (3.5.0)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.5.0)
29
+ rspec-mocks (3.5.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.5.0)
32
+ rspec-support (3.5.0)
33
+ serialport (1.3.1)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ bundler (~> 1.12)
40
+ jenga!
41
+ rake (~> 10.0)
42
+ rspec (~> 3.0)
43
+ rspec-expectations
44
+
45
+ BUNDLED WITH
46
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ricardo Carrasco Cursach
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Jenga
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jenga`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'jenga'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install jenga
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jenga.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jenga"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jenga/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jenga"
8
+ spec.version = Jenga::VERSION
9
+ spec.authors = ["Ricardo Carrasco Cursach"]
10
+ spec.email = ["rccursach@gmail.com"]
11
+ spec.licenses = ['MIT']
12
+ spec.summary = "Jenga is a tool for building applications based on XBee radio devices and the internet"
13
+ spec.description = "Useful for receiving data from small WSNs based on XBee/ZigBee devices and enable them to access the internet"
14
+ spec.homepage = "https://github.com/rccursach/jenga"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_runtime_dependency "serialport", "~> 1.3"
30
+ spec.add_runtime_dependency "mongo", "~> 2.1"
31
+ spec.add_runtime_dependency "bson_ext"
32
+ spec.add_runtime_dependency "redis"
33
+ spec.add_development_dependency "bundler", "~> 1.12"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "rspec-expectations"
37
+ end
@@ -0,0 +1,12 @@
1
+ require "jenga/version"
2
+ require "jenga/front"
3
+
4
+ # need to require the rest of the gang through a config file
5
+ # but only the ones that are required to do the job
6
+ # as specified in the config file
7
+ #
8
+ # but.. where is that config file anyways??
9
+
10
+ module Jenga
11
+ @front = SamFront::Front.new [1,2,3]
12
+ end
@@ -0,0 +1,36 @@
1
+
2
+ module SamFront
3
+
4
+ class Base
5
+ @forward = false
6
+ @name = nil
7
+ @next = nil
8
+
9
+ def initialize
10
+ @name = self.class.to_s
11
+ end
12
+
13
+ def forward _next
14
+ @next = _next
15
+ @forward = true
16
+ end
17
+
18
+ def set_config conf
19
+ raise "Not a valid conf for #{@name}" unless conf.is_a? Hash
20
+ end
21
+
22
+ def task data
23
+ end
24
+
25
+ def run_task data
26
+ data = task(data)
27
+ #@next.run_task(data) if @forward
28
+ if @forward
29
+ puts "Running next: #{@next.class.to_s}"
30
+ @next.run_task(data)
31
+ end
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,64 @@
1
+
2
+ ##
3
+ # Load components
4
+ # see http://stackoverflow.com/questions/1849699
5
+ # TODO: decide between load or require!!
6
+ Dir["#{File.dirname(__FILE__)}/components/**/*.rb"].each { |f| load(f) }
7
+
8
+ module SamFront
9
+
10
+ class Boostraper
11
+
12
+ @hash = nil
13
+ @first = nil
14
+
15
+ def initialize arr
16
+ @hash = arr
17
+ not_a_hash if not arr.is_a? Array
18
+ end
19
+
20
+ def get_first
21
+ set_chain
22
+ end
23
+
24
+ private
25
+
26
+ def self.not_a_hash
27
+ msg = "Boostraper received #{@hash.class}, expected Hash"
28
+ raise msg
29
+ end
30
+
31
+ ##
32
+ # check:
33
+ # http://stackoverflow.com/questions/5924495
34
+ def set_chain
35
+ components = []
36
+ #load each component
37
+ @hash.each do |c|
38
+ # Get component class
39
+ clazz = nil
40
+ if c[:class].include? "::"
41
+ clazz = c[:class].split('::').inject(Object) {|o,c| o.const_get c}
42
+ else
43
+ clazz = Object.const_get(c[:class])
44
+ end
45
+
46
+ # Instantiate components
47
+ comp = clazz.new
48
+ comp.set_config c[:config]
49
+
50
+ # Add component to list
51
+ components << comp
52
+ end
53
+
54
+ # Set chain sequence
55
+ last = components.length - 1
56
+ components.each_with_index do |c, idx|
57
+ c.forward components[idx+1] unless idx == last
58
+ end
59
+ # return the first on the chain
60
+ return components.first
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ require 'jenga/base'
2
+
3
+ module SamFront
4
+ class ComponentOne < Base
5
+
6
+ def task data
7
+ data += 1
8
+ puts "#{@name}: Data is now #{data}"
9
+ return data
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'jenga/base'
2
+
3
+ module SamFront
4
+ class ComponentThree < Base
5
+
6
+ def task data
7
+ data = "Number #{data}"
8
+ puts "#{@name}: Data is now #{data}"
9
+ return data
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'jenga/base'
2
+
3
+ module SamFront
4
+ class ComponentTwo < Base
5
+
6
+ def task data
7
+ data = data.to_s
8
+ puts "#{@name}: Data is now #{data}"
9
+ return data
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require 'jenga/boostraper'
2
+
3
+ module SamFront
4
+
5
+ class Front
6
+
7
+ def initialize env
8
+ hash = [
9
+ { class: 'SamFront::ComponentOne', config: {} },
10
+ { class: 'SamFront::ComponentTwo', config: {} },
11
+ { class: 'SamFront::ComponentThree', config: {} }
12
+ ]
13
+ b = SamFront::Boostraper.new(hash)
14
+ entry_point = b.get_first
15
+ entry_point.run_task 1
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'jenga/parsers/parser'
2
+
3
+ module SamFront
4
+ module Parsers
5
+
6
+ class Parse_kv_text < SamFront::Parsers::Parser
7
+
8
+ def initialize
9
+ super
10
+ puts 'parser of key:values loaded!'
11
+ end
12
+
13
+ def call env
14
+ return env
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module SamFront
2
+ module Parsers
3
+
4
+ class Parser
5
+
6
+ def initialize
7
+ puts 'Parser child initialized:'
8
+ end
9
+
10
+ def call env
11
+ return env
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module SamFront
2
+ module SerialAdapters
3
+
4
+ class Serial
5
+
6
+ @observer
7
+
8
+ def initialize
9
+ # heat the serial engines, then go for a run.
10
+ # but first tell someone to watch this race!
11
+ # hint: with #observe_me
12
+ end
13
+
14
+
15
+ def run
16
+ # just silly stuff
17
+ sleep 8
18
+ observer.notify "msg:this is text;should:be parsed;"
19
+ end
20
+
21
+ ##
22
+ # Registers an observer who will be notified
23
+ # everytime we will have data to send
24
+ def observe_me observer
25
+ @observer = observer
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'jenga/serial_adapters/serial'
2
+
3
+ module SamFront
4
+ module SerialAdapters
5
+
6
+ class SerialGetS < SamFront::SerialAdapters::Serial
7
+
8
+ def initialize
9
+ super
10
+ end
11
+
12
+ def run
13
+ # need to inject a block here or something??
14
+ super.run
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Jenga
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,51 @@
1
+
2
+ -- This project is currently a draft --
3
+ # Jenga
4
+
5
+ Copyright (c) 2016 Ricardo Carrasco Cursach.
6
+ Under MIT Licence, See [LICENCE](https://github.com/rccursach/sam_serial_front/blob/master/LICENSE)
7
+
8
+ ## Jenga is a tool for building applications based on XBee radio devices
9
+
10
+ ### Its use is intended for receiving data from small WSNs based on XBee/ZigBee devices and enable them to access the internet
11
+
12
+ (It's kind of a "rack" for serial)
13
+
14
+ The following Asumptions/Escenarios will be taken in care:
15
+
16
+ As from source:
17
+
18
+ * Serial data comes in form of "Packages"
19
+ * Packages can come from:
20
+ * Raw serial as bytes
21
+ * Strings from serial as lines
22
+ * XBee/ZigBee plain text from datagram's body/payload
23
+ * XBee/ZigBee binary data from datagram's payload
24
+
25
+ As for format:
26
+
27
+ * Package might contain key:value pairs array
28
+ * Package might contain an only values array
29
+ * as text delimited by token
30
+ * as binary string to be decoded
31
+ * Only-values packages needs a parser
32
+ * Package can be an array of packages, we call it a Stream
33
+
34
+ As for other middleware:
35
+
36
+ * More middleware components can be added, some examples could be:
37
+ * Database storage
38
+ * Pub/Sub services
39
+ * Caching data
40
+ * logging
41
+ * Validate/Discard Packages
42
+ * Middleware components should not block:
43
+ * For example: Storage should be preceded by caching/queuing in some way.
44
+
45
+ As for configuration:
46
+
47
+ * An instance will need to know what kind of source will be received.
48
+ * Also will need to know serial configuration data as port, speed, etc. (This behaviour will be inherited from its abstract parent interface)
49
+ * An instance will need to know the number, names and order of filters for package format
50
+ * An instance will need to know the number, names and order of other middleware components
51
+ * An instance will need a list of components to be injected as dependencies
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jenga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ricardo Carrasco Cursach
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: serialport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongo
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bson_ext
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redis
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-expectations
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Useful for receiving data from small WSNs based on XBee/ZigBee devices
126
+ and enable them to access the internet
127
+ email:
128
+ - rccursach@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - LICENSE
137
+ - README_gem.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - jenga.gemspec
142
+ - lib/jenga.rb
143
+ - lib/jenga/base.rb
144
+ - lib/jenga/boostraper.rb
145
+ - lib/jenga/components/component_one.rb
146
+ - lib/jenga/components/component_three.rb
147
+ - lib/jenga/components/component_two.rb
148
+ - lib/jenga/front.rb
149
+ - lib/jenga/parsers/parse_kv_text.rb
150
+ - lib/jenga/parsers/parser.rb
151
+ - lib/jenga/serial_adapters/serial.rb
152
+ - lib/jenga/serial_adapters/serial_gets.rb
153
+ - lib/jenga/version.rb
154
+ - readme.md
155
+ homepage: https://github.com/rccursach/jenga
156
+ licenses:
157
+ - MIT
158
+ metadata:
159
+ allowed_push_host: https://rubygems.org
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.4.8
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Jenga is a tool for building applications based on XBee radio devices and
180
+ the internet
181
+ test_files: []