nutella_lib 0.4.27 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b11c022814995ed25e82654c006f3e5a81c84ee2d48ad86f3710135fba31fa63
4
- data.tar.gz: 46152efd052e5734e1d0687c9cb18d11c461e15167ce0dcd128768edcfad3bd6
3
+ metadata.gz: aa7384c4726a3e52f18381983e8b022f01a13039642e4eeb66c0f83950c8481a
4
+ data.tar.gz: a660ef5d63f9d768a089a557d501367fdabf4630891933a4cb09840e30d151ad
5
5
  SHA512:
6
- metadata.gz: ebd24e14b6ba9742016caa2e88bac98761eea356d4c866fd6528878f3db7ee631a6f193289e93925e6cd71bf652a636d8548cf98dd7e2db7f28717b9192eaa9d
7
- data.tar.gz: da02fd9b215b7045cc9fdb9cab0ba34d1be5bc6fcf1dc4ba708a1d848cfc88c7bf6ca4eef284ab9ba7c733d5c67feb19a754f2ba20111eece2a376149b4dc82c
6
+ metadata.gz: 7f8461b3850835943925f23adf6fe69fc0ec9a05cd8785e31681679a3dbb87e17957d118003a6426fd2963641596e735cc84652eada6f257aeaba8e476c5f308
7
+ data.tar.gz: bb06eea03b236e50aa179bda90c04fe390f8485e8a3a8155584caeb1921c002361c46020a1f1a916ad381ad9f3847d2c7819082ff27260194530988f97f8670f
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --format Fuubar
3
+ --color
data/.travis.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.1
3
+ - 2.6.3
4
+ before_install:
5
+ - gem update --system
6
+ - gem install bundler
4
7
  notifications:
5
8
  email: false
data/Gemfile CHANGED
@@ -1,19 +1,18 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'mqtt', '~> 0.3', '>= 0.3.1'
4
- gem 'ansi', '~> 1.5', '>= 1.4'
5
- gem 'mongo','~> 2.0.0'
3
+ gem 'mqtt', '~> 0.5', '>= 0.5'
4
+ gem 'ansi', '~> 1.5', '>= 1.5'
5
+ gem 'mongo','~> 2.0'
6
6
 
7
7
  group :development do
8
- gem 'shoulda', '~> 3', '>= 3'
9
- gem 'minitest', '~> 5.4', '>= 5'
10
- gem 'yard', '~> 0.8', '>= 0.8.7'
11
- gem 'rdoc', '~> 4.0', '>= 4.0'
12
- gem 'bundler', '~> 1.0', '>= 1.0'
13
- gem 'jeweler', '~> 2.0', '>= 2.0.1'
14
- gem 'simplecov', '~> 0', '>= 0'
8
+ gem 'bundler', '~> 2.0'
9
+ gem 'jeweler', '~> 2.3'
10
+ gem 'yard', '>= 0.9.12'
11
+ gem 'simplecov', '>= 0.17'
15
12
  end
16
13
 
17
14
  group :test do
18
15
  gem 'rake'
19
- end
16
+ gem "rspec", '~> 3.8'
17
+ gem 'fuubar', '~> 2.4'
18
+ end
data/README.md CHANGED
@@ -2,11 +2,18 @@
2
2
  [![Build Status](https://travis-ci.org/nutella-framework/nutella_lib.rb.svg)](https://travis-ci.org/nutella-framework/nutella_lib.rb)
3
3
 
4
4
  # nutella_lib.rb
5
- nutella library for Ruby. Used mostly to create bots in Ruby.
5
+ nutella library for Ruby
6
6
 
7
- # Getting started
7
+ ## Getting started
8
8
  Take a look at [basic-ruby-bot](https://github.com/nutella-framework/basic-ruby-bot) to see how to use nutella_lib to build a bot.
9
9
 
10
- # Docs
10
+ ## Docs
11
11
  Check out the docs at [http://www.rubydoc.info/gems/nutella_lib](http://www.rubydoc.info/gems/nutella_lib)
12
12
 
13
+ # Contributing
14
+ 1. Clone repo
15
+ 1. Bundle (`bundle`)
16
+ 1. Run tests (`rake`)
17
+ 1. Make changes
18
+ 1. Run tests (`rake test`)
19
+ 1. Open a PR
data/Rakefile CHANGED
@@ -17,28 +17,20 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "nutella_lib"
18
18
  gem.homepage = "https://github.com/nutella-framework/nutella_lib.rb"
19
19
  gem.license = "MIT"
20
- gem.summary = %Q{nutella protocol library for ruby}
21
- gem.description = %Q{Implements the nutella protocol and exposes it natively to ruby developers}
20
+ gem.summary = %Q{nutella library for ruby}
21
+ gem.description = %Q{Implements the nutella protocol and exposes it natively}
22
22
  gem.email = "tebemis@gmail.com"
23
23
  gem.authors = ["Alessandro Gnoli"]
24
24
  # dependencies defined in Gemfile
25
25
  end
26
26
  Jeweler::RubygemsDotOrgTasks.new
27
27
 
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
28
+ require 'rspec/core/rake_task'
29
+ RSpec::Core::RakeTask.new(:spec) do |spec|
30
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
31
  end
34
32
 
35
- desc "Code coverage detail"
36
- task :simplecov do
37
- ENV['COVERAGE'] = "true"
38
- Rake::Task['test'].execute
39
- end
40
-
41
- task :default => :test
42
-
43
33
  require 'yard'
44
34
  YARD::Rake::YardocTask.new
35
+
36
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.27
1
+ 0.5.0
@@ -1,9 +1,10 @@
1
1
  module Nutella
2
-
2
+ # App-level APIs sub-module
3
3
  module App
4
4
 
5
5
  # Initializes this component as an application component
6
6
  # @param [String] broker_hostname
7
+ # @param [String] app_id
7
8
  # @param [String] component_id
8
9
  def self.init( broker_hostname, app_id, component_id )
9
10
  Nutella.app_id = app_id
@@ -12,6 +13,7 @@ module Nutella
12
13
  Nutella.resource_id = nil
13
14
  Nutella.mongo_host = broker_hostname
14
15
  Nutella.mqtt = SimpleMQTTClient.new broker_hostname
16
+
15
17
  # Start pinging
16
18
  Nutella.net.start_pinging
17
19
  # Fetch the `run_id`s list for this application and subscribe to its updates
@@ -1,10 +1,10 @@
1
1
  # This module is the wrapper around the whole nutella library.
2
2
  module Nutella
3
3
 
4
-
5
4
  # Initializes this component as a run component
6
- # @param [String] run_id
7
5
  # @param [String] broker_hostname
6
+ # @param [String] app_id
7
+ # @param [String] run_id
8
8
  # @param [String] component_id
9
9
  def self.init( broker_hostname, app_id, run_id, component_id )
10
10
  @app_id = app_id
@@ -17,7 +17,6 @@ module Nutella
17
17
  Nutella.net.start_pinging
18
18
  end
19
19
 
20
-
21
20
  # Variables accessors
22
21
  def self.app_id; @app_id end
23
22
  def self.run_id; @run_id end
@@ -45,16 +44,16 @@ module Nutella
45
44
  def self.mqtt=(val); @mqtt=val; end
46
45
  def self.ping_thread=(val); @ping_thread=val; end
47
46
 
48
-
49
- # Accessors for sub-modules
47
+ # Accessors for app and framework sub-modules
50
48
  def self.app; Nutella::App; end
49
+ def self.f; Nutella::Framework; end
50
+ # Accessors run-level sub-modules
51
51
  def self.net; Nutella::Net; end
52
52
  def self.log; Nutella::Log; end
53
53
  def self.persist; Nutella::Persist; end
54
54
 
55
55
 
56
- # Utility functions
57
-
56
+ # Utility methods
58
57
 
59
58
  # Parse command line arguments for run level components
60
59
  #
@@ -85,8 +84,4 @@ module Nutella
85
84
  @resource_id = resource_id
86
85
  end
87
86
 
88
- end
89
-
90
-
91
-
92
-
87
+ end
@@ -0,0 +1,47 @@
1
+ module Nutella
2
+ # Framework-level APIs sub-module
3
+ module Framework
4
+
5
+ # Initializes this component as a framework component
6
+ # @param [String] broker_hostname
7
+ # @param [String] component_id
8
+ def self.init( broker_hostname, component_id )
9
+ Nutella.app_id = nil
10
+ Nutella.run_id = nil
11
+ Nutella.component_id = component_id
12
+ Nutella.resource_id = nil
13
+ Nutella.mongo_host = broker_hostname
14
+ Nutella.mqtt = SimpleMQTTClient.new broker_hostname
15
+ # Start pinging
16
+ Nutella.net.start_pinging
17
+ # Fetch the `run_id`s list for this application and subscribe to its updates
18
+ net.async_request('app_runs_list', lambda { |res| Nutella.app.app_runs_list = res })
19
+ self.net.subscribe('app_runs_list', lambda {|message, _| Nutella.app.app_runs_list = message })
20
+ end
21
+
22
+ # Accessors for sub-modules
23
+ def self.net; Nutella::Framework::Net; end
24
+ def self.log; Nutella::Framework::Log; end
25
+ def self.persist; Nutella::Framework::Persist; end
26
+
27
+
28
+ # Utility functions
29
+
30
+ # Extracts the component name from the folder where the code for this component is located
31
+ #
32
+ # @return [String] the component name
33
+ def self.extract_component_id
34
+ Nutella.extract_component_id
35
+ end
36
+
37
+ # Sets the resource id
38
+ #
39
+ # @param [String] resource_id the resource id (i.e. the particular instance of this component)
40
+ def self.set_resource_id( resource_id )
41
+ Nutella.set_resource_id resource_id
42
+ end
43
+
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,49 @@
1
+ require 'ansi'
2
+
3
+ module Nutella
4
+
5
+ module Framework
6
+
7
+ module Log
8
+
9
+ def self.debug(message, code=nil)
10
+ puts( ANSI.cyan + message + ANSI.reset )
11
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
12
+ code
13
+ end
14
+
15
+ def self.info(message, code=nil)
16
+ puts( message )
17
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
18
+ code
19
+ end
20
+
21
+ def self.success(message, code=nil)
22
+ puts( ANSI.green + message + ANSI.reset )
23
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
24
+ code
25
+ end
26
+
27
+ def self.warn(message, code=nil)
28
+ puts( ANSI.yellow + message + ANSI.reset )
29
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
30
+ code
31
+ end
32
+
33
+ def self.error(message, code=nil)
34
+ puts( ANSI.red + message + ANSI.reset )
35
+ Nutella.f.net.publish( 'logging', log_to_json(message, code, __method__) )
36
+ code
37
+ end
38
+
39
+ private
40
+
41
+ def self.log_to_json( message, code, level)
42
+ code.nil? ? {level: level, message: message} : {level: level, message: message, code: code}
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+
49
+ end