lupe 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/lupe.rb +87 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ed9aef097512d3209003ecc4d3f5884cf5399d9e2e067069981188e11b685f25
4
+ data.tar.gz: f644fd2d40a06dc7ac398da0198d32b86650d2a636859f4b2703b1f752ddcc95
5
+ SHA512:
6
+ metadata.gz: 9bfb564e6326d0cb57e1b79b076277163ceb0b325edcd6154ca484fd31751d3a2bf61c8639cff3b5981f2e125be4d0cde1141a30680f47a948cdfefc3e976a83
7
+ data.tar.gz: 0b72e2777b0c6a5f9d11cb94ce9b61200deaaa2021c1ffea589a882a8d1cf4ff7689915d76920ad3232bb6462dac00835d004d6ceb2652fe2089dfb914e442b3
data/lib/lupe.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'json'
2
+ require 'logger'
3
+
4
+ class Lupe
5
+ DEFAULT_CONFIGURATION = {
6
+ :running => true,
7
+ :name => 'lupita',
8
+ :counter => 0,
9
+ :interval => 4,
10
+ :monitor => false,
11
+ :environment => 'development',
12
+ :log_to => 'log/%s.log',
13
+ :description => '%s - Lupita',
14
+ :print_ticks => false
15
+ }
16
+ def initialize(configuration)
17
+ @configuration = DEFAULT_CONFIGURATION
18
+ @configuration.merge!(configuration)
19
+ at_exit do
20
+ logger.info 'Service is going down.'
21
+ logger.info('Running teardown..')
22
+ tear_down
23
+ end
24
+ shutdown = proc do
25
+ puts 'bye.'
26
+ @configuration[:running] = false
27
+ end
28
+ trap('QUIT', &shutdown)
29
+ trap('TERM', &shutdown)
30
+ trap('INT', &shutdown)
31
+ end
32
+ def environment
33
+ @configuration[:environment]
34
+ end
35
+ def log_path
36
+ template = @configuration[:log_to]
37
+ bindings = []
38
+ @configuration[:log_to].scan('%s').each do |interpolation|
39
+ bindings.push(@configuration[:name])
40
+ end
41
+ (template % bindings)
42
+ end
43
+ def logger
44
+ @logger ||= Logger.new(log_path)
45
+ end
46
+ def program_name
47
+ template = @configuration[:description]
48
+ bindings = []
49
+ bindings.push(@configuration[:name])
50
+ (template % bindings)
51
+ end
52
+ def _configuration
53
+ template = "%s : %s"
54
+ bindings = []
55
+ bindings.push("Start with configuration")
56
+ bindings.push(@configuration.to_json)
57
+ (template % bindings)
58
+ end
59
+ def _reset_log
60
+ logger.info 'running on monitor mode'
61
+ File.open(log_path, 'w+') {}
62
+ end
63
+ def setup
64
+ end
65
+ def tear_down
66
+ end
67
+ def run(&operation)
68
+ logger.info(program_name)
69
+ logger.info(_configuration)
70
+ logger.info('Running setup..')
71
+ setup
72
+ loop do
73
+ break unless @configuration[:running]
74
+ sleep 1
75
+ _reset_log if @configuration[:monitor]
76
+ @configuration[:counter] += 1
77
+ if @configuration[:counter] > @configuration[:interval]
78
+ @configuration[:counter] = 0
79
+ operation.call(logger)
80
+ next
81
+ end
82
+ if @configuration[:print_ticks]
83
+ logger.debug "tick: #{@configuration[:counter]}"
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lupe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kazuyoshi Tlacaelel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows you to create loop programs easily
14
+ email: kazu.dev@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/lupe.rb
20
+ homepage: http://rubygems.org/gems/lupe
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.7.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Loop Program Abstraction
44
+ test_files: []