Class: Actory::Receiver::Plugin
- Defined in:
- lib/actory/receiver/plugin/auth.rb,
lib/actory/receiver/plugin/reload.rb,
lib/actory/receiver/plugin/example_pi.rb,
lib/actory/receiver/plugin/system_info.rb,
lib/actory/receiver/plugin/example_prime.rb,
lib/actory/receiver/plugin/processor_count.rb,
lib/actory/receiver/plugin/example_fibonacci.rb
Constant Summary
Constants inherited from Base
Constants inherited from Base
Instance Method Summary collapse
- #auth?(shared_key) ⇒ Boolean
- #fibonacci(num = 10) ⇒ Object
- #pi(len = 2) ⇒ Object
- #prime(num = 1) ⇒ Object
- #processor_count ⇒ Object
- #reload ⇒ Object
- #system_info ⇒ Object
Methods inherited from Base
get_logger_level, get_logger_output
Instance Method Details
#auth?(shared_key) ⇒ Boolean
6 7 8 9 10 11 |
# File 'lib/actory/receiver/plugin/auth.rb', line 6 def auth?(shared_key) RECEIVER['shared_key'] == shared_key rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, msg end |
#fibonacci(num = 10) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/actory/receiver/plugin/example_fibonacci.rb', line 6 def fibonacci(num=10) raise StandardError unless [Fixnum, String].include?(num.class) num = num.to_i if num.class == String and num =~ /\A[0-9]+\z/ num <= 1 ? num : fibonacci(num - 1) + fibonacci(num - 2) rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, msg end |
#pi(len = 2) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/actory/receiver/plugin/example_pi.rb', line 6 def pi(len=2) raise StandardError unless [Fixnum, String].include?(len.class) len = len.to_i if len.class == String and len =~ /\A[0-9]+\z/ b = 10 ** len b2 = b << 1 pi = (len * 8 + 1).step(3, -2).inject(b) {|a, i| (i >> 1) * (a + b2) / i} - b return "3.#{pi}" rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, msg end |
#prime(num = 1) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/actory/receiver/plugin/example_prime.rb', line 7 def prime(num=1) raise StandardError unless [Fixnum, String].include?(num.class) num = num.to_i if num.class == String and num =~ /\A[0-9]+\z/ Prime.each(num).to_a rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, msg end |
#processor_count ⇒ Object
6 7 8 9 10 11 |
# File 'lib/actory/receiver/plugin/processor_count.rb', line 6 def processor_count return Parallel.processor_count rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, msg end |
#reload ⇒ Object
6 7 8 9 10 11 |
# File 'lib/actory/receiver/plugin/reload.rb', line 6 def reload Dir[File.join(File.dirname(__FILE__), "./*.rb")].each { |f| load f } rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, e end |
#system_info ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/actory/receiver/plugin/system_info.rb', line 6 def system_info info = { :processor => { :count => Facter.value(:processorcount), :physicalcount => Facter.value(:physicalprocessorcount), }, :memory => { :free => Facter.value(:memoryfree), :size => Facter.value(:memorysize), }, :swap => { :free => Facter.value(:swapfree), :size => Facter.value(:swapsize), }, :timezone => Facter.value(:timezone), } return info rescue => e msg = Actory::Errors::Generator.new.json(level: "ERROR", message: e., backtrace: $@) raise StandardError, msg end |