sana 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (10) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +4 -0
  5. data/Gemfile +4 -0
  6. data/README.md +103 -0
  7. data/Rakefile +9 -0
  8. data/lib/sana.rb +134 -0
  9. data/sana.gemspec +24 -0
  10. metadata +150 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a0ccc534b79810c894577efd34a818fb4444d184
4
+ data.tar.gz: c7509bff9e570c8f42d41a2bb0b8844f130f4246
5
+ SHA512:
6
+ metadata.gz: 5bdbf47991be27e28dde56f72a0f7c3531e9c01c1b75df09f6ceb113844178fa9c1a21a4e86b8853d50d0715058b5c668ee9096272c654970fa785476d126895
7
+ data.tar.gz: 20a8cbd00fe4f0688cb6bffd5918fe392af224c79eb24d51c41cdd90e75884166dea39e2334f8ac355b00120d39d84d7789da9b4602fca3a37aee80da29e057a
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /doc/
6
+ /coverage/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .*.sw?
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format doc
3
+ --require ./spec/spec_helper.rb
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shioruby.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # [Sana](https://github.com/Narazaka/sana)
2
+
3
+ [![Gem](https://img.shields.io/gem/v/sana.svg)](https://rubygems.org/gems/sana)
4
+ [![Gem](https://img.shields.io/gem/dtv/sana.svg)](https://rubygems.org/gems/sana)
5
+ [![Gemnasium](https://gemnasium.com/Narazaka/sana.svg)](https://gemnasium.com/Narazaka/sana)
6
+ [![Inch CI](http://inch-ci.org/github/Narazaka/sana.svg)](http://inch-ci.org/github/Narazaka/sana)
7
+ [![Build Status](https://travis-ci.org/Narazaka/sana.svg)](https://travis-ci.org/Narazaka/sana)
8
+ [![codecov.io](https://codecov.io/github/Narazaka/sana/coverage.svg?branch=master)](https://codecov.io/github/Narazaka/sana?branch=master)
9
+ [![Code Climate](https://codeclimate.com/github/Narazaka/sana/badges/gpa.svg)](https://codeclimate.com/github/Narazaka/sana)
10
+
11
+ Ukagaka SHIORI subsystem 'Sana'
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'sana'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install sana
28
+
29
+ ## Usage
30
+
31
+ Example of basic SHIORI subsystem with SHIOLINK.DLL protocol.
32
+
33
+ make main.rb like below...
34
+
35
+ ```ruby
36
+ require 'sana'
37
+ require 'shiolink'
38
+ require 'json'
39
+
40
+ def _load(dirpath)
41
+ if File.exist?("save.json")
42
+ $save = JSON.parse(File.read("save.json"))
43
+ else
44
+ $save = {}
45
+ end
46
+ end
47
+
48
+ def _unload
49
+ File.write("save.json", JSON.dump($save))
50
+ exit
51
+ end
52
+
53
+ def version r; '0.0.1'; end
54
+ def name r; 'Sana'; end
55
+ def craftman r; 'Narazaka'; end
56
+ def craftmanw r; '奈良阪'; end
57
+
58
+ def OnBoot r
59
+ unless $save['boot_count']
60
+ $save['boot_count'] = 1
61
+ else
62
+ $save['boot_count'] += 1
63
+ end
64
+ '\h\s[0]おはよう。\w9\u\s[10]こんばんは。\e'
65
+ end
66
+
67
+ def OnClose r
68
+ if r.Reference0 == 'user'
69
+ '\h\s[0]またね。\w9\-'
70
+ else
71
+ '\h\s[0]おわー!?\w9\-'
72
+ end
73
+ end
74
+
75
+ include Sana::ResponseHelper
76
+
77
+ sana = Sana.new
78
+ shiolink = Shiolink.new(sana.method(:load), sana.method(:unload), sana.method(:request))
79
+ shiolink.start
80
+ ```
81
+
82
+ then...
83
+
84
+ ```
85
+ ruby main.rb
86
+ ```
87
+
88
+ or make SHIOLINK.INI and run with any basewares...
89
+
90
+ ```
91
+ [SHIOLINK]
92
+ commandline = ruby ./main.rb
93
+
94
+ charmode = UTF-8
95
+ ```
96
+
97
+ ## API
98
+
99
+ [API Document](http://www.rubydoc.info/github/Narazaka/sana)
100
+
101
+ ## License
102
+
103
+ This is released under [MIT License](http://narazaka.net/license/MIT?2016).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+ require 'yard/rake/yardoc_task'
5
+
6
+ task :default => :spec
7
+
8
+ RSpec::Core::RakeTask.new
9
+ YARD::Rake::YardocTask.new
data/lib/sana.rb ADDED
@@ -0,0 +1,134 @@
1
+ require 'shioruby'
2
+
3
+ # Ukagaka SHIORI submodule 'Sana'
4
+ class Sana
5
+ # the ghost/master path
6
+ attr_reader :dirpath
7
+ # events object
8
+ attr_reader :events
9
+ # default Charset header value
10
+ attr_accessor :charset
11
+ # default Sender header value
12
+ attr_accessor :sender
13
+
14
+ # initialize Sana
15
+ # @param [Object] events event definitions
16
+ def initialize(events = Kernel)
17
+ @events = events
18
+ @charset = 'UTF-8'
19
+ @sender = 'Sana'
20
+ end
21
+
22
+ # SHIORI load()
23
+ # @param [String] dirpath the ghost/master directory path
24
+ def load(dirpath)
25
+ @dirpath = dirpath
26
+ begin
27
+ events.send(:_load, dirpath)
28
+ rescue NoMethodError
29
+ end
30
+ end
31
+
32
+ # SHIORI unload()
33
+ def unload
34
+ begin
35
+ events.send(:_unload)
36
+ rescue NoMethodError
37
+ end
38
+ end
39
+
40
+ # SHIORI request()
41
+ # @param [String] request_str SHIORI Request
42
+ # @return [String] SHIORI Response
43
+ def request(request_str)
44
+ request = Shioruby.parse_request(request_str)
45
+ if request.version[0] == '2'
46
+ return build_response Sana::ResponseHelper.bad_request
47
+ end
48
+ begin
49
+ response = events.send(request.ID, request)
50
+ rescue NoMethodError
51
+ end
52
+ case response
53
+ when OpenStruct
54
+ build_response response
55
+ else
56
+ build_response Sana::ResponseHelper.ok response
57
+ end
58
+ rescue => error
59
+ case error
60
+ when Shioruby::ParseError
61
+ build_response Sana::ResponseHelper.bad_request
62
+ else
63
+ build_response Sana::ResponseHelper.internal_server_error
64
+ end
65
+ end
66
+
67
+ private
68
+ def build_response(response)
69
+ response.version ||= '3.0'
70
+ response.Charset = response.Charset || charset
71
+ response.Sender = response.Sender || sender
72
+ Shioruby.build_response(response)
73
+ end
74
+ end
75
+
76
+ class Sana
77
+ # SHIORI Response struct build helper
78
+ module ResponseHelper
79
+ # empty response struct
80
+ # @return [OpenStruct] empty SHIORI Response struct
81
+ def response
82
+ OpenStruct.new
83
+ end
84
+
85
+ # normal response (200 OK or 204 No Content)
86
+ # @param [String] value Value header content
87
+ # @param [String] to Reference0 header content (for communication)
88
+ # @return [OpenStruct] SHIORI Response struct
89
+ def ok(value = nil, to = nil)
90
+ if value.to_s.size != 0
91
+ response = OpenStruct.new({
92
+ code: 200,
93
+ Value: value.to_s,
94
+ })
95
+ if to
96
+ response.Reference0 = to.to_s
97
+ end
98
+ response
99
+ else
100
+ no_content
101
+ end
102
+ end
103
+
104
+ # 204 No Content
105
+ # @return [OpenStruct] SHIORI Response struct
106
+ def no_content
107
+ OpenStruct.new({
108
+ code: 204,
109
+ })
110
+ end
111
+
112
+ # 400 Bad Request
113
+ # @return [OpenStruct] SHIORI Response struct
114
+ def bad_request
115
+ OpenStruct.new({
116
+ code: 400,
117
+ })
118
+ end
119
+
120
+ # 500 Internal Server Error
121
+ # @return [OpenStruct] SHIORI Response struct
122
+ def internal_server_error
123
+ OpenStruct.new({
124
+ code: 500,
125
+ })
126
+ end
127
+
128
+ module_function :response
129
+ module_function :ok
130
+ module_function :no_content
131
+ module_function :bad_request
132
+ module_function :internal_server_error
133
+ end
134
+ end
data/sana.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "sana"
6
+ spec.version = "0.0.1"
7
+ spec.authors = ["Narazaka"]
8
+ spec.email = ["info@narazaka.net"]
9
+
10
+ spec.summary = %q{Ukagaka SHIORI subsystem 'Sana'}
11
+ spec.description = %q{Ukagaka SHIORI subsystem 'Sana'}
12
+ spec.homepage = "https://github.com/Narazaka/sana"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.require_paths = ["lib"]
16
+
17
+ spec.add_development_dependency "bundler", ">= 1.7.9"
18
+ spec.add_development_dependency "rake", "~> 10.0"
19
+ spec.add_development_dependency "rspec", "~> 3.4"
20
+ spec.add_development_dependency "yard", "~> 0.8.7"
21
+ spec.add_development_dependency "simplecov", "~> 0.11"
22
+ spec.add_development_dependency "codecov", "~> 0.1"
23
+ spec.add_dependency "shioruby", ">= 0.0.1"
24
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sana
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Narazaka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.9
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.9
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.7
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: shioruby
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.0.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.0.1
111
+ description: Ukagaka SHIORI subsystem 'Sana'
112
+ email:
113
+ - info@narazaka.net
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - lib/sana.rb
125
+ - sana.gemspec
126
+ homepage: https://github.com/Narazaka/sana
127
+ licenses: []
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.4.5.1
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Ukagaka SHIORI subsystem 'Sana'
149
+ test_files: []
150
+ has_rdoc: