koltira 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f43c72eaac2ffef70b9853688a417ce631f47da3992f1cb1f195af3568b5a4b
4
+ data.tar.gz: 3d44edc5fb6983192e340ba5bff441546ba825991fc227215a7fe07279f4667a
5
+ SHA512:
6
+ metadata.gz: b7db09d770b4c0358e397fcae3b19381b66f6b82f3dd3c37872a5b662bf06d64c254fafd2a25997502ce47f2ef3de254a5d9298d611c1500b21fb7e978826151
7
+ data.tar.gz: 3cffeba78f4cc4530584e1495b112ebd0e3b6fde4bc1f3236d8629f917363cc6df66cb58756f930ecf497294fc816d64dc026d5717c742d3b160fa76493361c9
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in koltira.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ koltira (0.2.0)
5
+ activemodel (~> 7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (7.0.2.3)
11
+ activesupport (= 7.0.2.3)
12
+ activesupport (7.0.2.3)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.1.10)
19
+ diff-lcs (1.5.0)
20
+ i18n (1.10.0)
21
+ concurrent-ruby (~> 1.0)
22
+ method_source (1.0.0)
23
+ minitest (5.15.0)
24
+ pry (0.14.1)
25
+ coderay (~> 1.1)
26
+ method_source (~> 1.0)
27
+ rake (13.0.6)
28
+ rspec (3.11.0)
29
+ rspec-core (~> 3.11.0)
30
+ rspec-expectations (~> 3.11.0)
31
+ rspec-mocks (~> 3.11.0)
32
+ rspec-core (3.11.0)
33
+ rspec-support (~> 3.11.0)
34
+ rspec-expectations (3.11.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-mocks (3.11.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-support (3.11.0)
41
+ tzinfo (2.0.4)
42
+ concurrent-ruby (~> 1.0)
43
+
44
+ PLATFORMS
45
+ arm64-darwin-21
46
+
47
+ DEPENDENCIES
48
+ koltira!
49
+ pry
50
+ rake (~> 13.0)
51
+ rspec (~> 3.0)
52
+
53
+ BUNDLED WITH
54
+ 2.3.3
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Koltira
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/koltira`. 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 'koltira'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install koltira
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 the created tag, 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]/koltira.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "koltira"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ require "pry"
12
+ Pry.start
data/bin/setup ADDED
@@ -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,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koltira
4
+ class Context
5
+ attr_reader :data
6
+
7
+ def initialize(data = {})
8
+ @data = data
9
+ end
10
+
11
+ def [](key)
12
+ @data[key]
13
+ end
14
+
15
+ def []=(key, value)
16
+ @data[key] = value
17
+ end
18
+
19
+ def reset!
20
+ @data = {}
21
+ end
22
+
23
+ def dup
24
+ new(@data.dup)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koltira
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koltira
4
+ class Event < Koltira::Model
5
+ attribute :id, :string, default: -> { SecureRandom.uuid }
6
+ attribute :name, :string
7
+ attribute :date, :datetime, default: -> { Time.now }
8
+ attribute :data, default: -> { Hash.new }
9
+
10
+ def self.parse(str)
11
+ data = JSON.parse(str)
12
+ new(
13
+ id: data['id'],
14
+ name: data['name'],
15
+ date: Time.at(data['date'].to_i),
16
+ data: data['data'] || {}
17
+ )
18
+ rescue JSON::ParserError => e
19
+ raise ParserError.new(
20
+ str, "Unable to parse JSON string: #{e.message}"
21
+ )
22
+ end
23
+
24
+ def content_sha256
25
+ Digest::SHA256.hexdigest(JSON.dump(data))
26
+ end
27
+
28
+ def as_json(*)
29
+ {
30
+ 'id' => id,
31
+ 'name' => name,
32
+ 'date' => date.to_i,
33
+ 'data' => data
34
+ }
35
+ end
36
+
37
+ # == Exceptions classes
38
+ class ParserError < Koltira::Error
39
+ attr_reader :input
40
+
41
+ def initialize(input, message)
42
+ @input = input
43
+ super(message)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koltira
4
+ class Model
5
+ include ActiveModel::Model
6
+ include ActiveModel::Attributes
7
+ include ActiveModel::AttributeMethods
8
+ include ActiveModel::Serialization
9
+ include ActiveModel::Serializers::JSON
10
+
11
+ def self.from_database(arg)
12
+ new._from_database(arg)
13
+ end
14
+
15
+ def _from_database(arg)
16
+ arg.each do |key, value|
17
+ @attributes.write_from_database(key.name, value)
18
+ end
19
+ self
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koltira
4
+ class Operation
5
+ attr_reader :context
6
+
7
+ # @param args [Hash<String, Object>]
8
+ # @param context [Koltira::Context|NilClass]
9
+ # @return [Koltira::Operation::Output]
10
+ def self.call(args, context = nil)
11
+ new(context).call(args)
12
+ end
13
+
14
+ # @param context [Koltira::Context|NilClass]
15
+ def initialize(context = nil)
16
+ @context = context
17
+ end
18
+
19
+ # Operation call function
20
+ # @param args [Hash<String, Object>] A dictionnary of key (string) and value (any object) pairs
21
+ # @raise [Koltira::Operation::Error]
22
+ # @return [Koltira::Operation::Output]
23
+ def call(args)
24
+ raise "#call not implemented in #{self.class}"
25
+ end
26
+
27
+ # generic operation error exception class
28
+ class Error < ::Koltira::Error
29
+ attr_reader :data
30
+
31
+ def initialize(message, data = {})
32
+ @data = data
33
+ super(message)
34
+ end
35
+ end
36
+
37
+ # output operation class
38
+ class Output
39
+ def initialize(data = {})
40
+ unless data.is_a?(Hash)
41
+ raise ArgumentError, "Hash expected, got: #{data.class}"
42
+ end
43
+
44
+ @data = data
45
+ end
46
+
47
+ def [](key)
48
+ @data[key]
49
+ end
50
+
51
+ def []=(key, value)
52
+ @data[key] = value
53
+ end
54
+
55
+ def to_json(*args)
56
+ @data.to_json(*args)
57
+ end
58
+
59
+ def as_json(*args)
60
+ @data.as_json(*args)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koltira
4
+ VERSION = '0.2.0'
5
+ end
data/lib/koltira.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'json'
5
+ require 'active_model'
6
+
7
+ # koltira files
8
+ require_relative 'koltira/version'
9
+ require 'koltira/error'
10
+ require 'koltira/context'
11
+ require 'koltira/model'
12
+ require 'koltira/operation'
13
+
14
+ module Koltira
15
+ end
data/sig/koltira.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Koltira
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koltira
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Julien D.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Koltira - A light framework based on operations handlers
42
+ email:
43
+ - julien@koltira.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - README.md
52
+ - Rakefile
53
+ - bin/console
54
+ - bin/setup
55
+ - lib/koltira.rb
56
+ - lib/koltira/context.rb
57
+ - lib/koltira/error.rb
58
+ - lib/koltira/event.rb
59
+ - lib/koltira/model.rb
60
+ - lib/koltira/operation.rb
61
+ - lib/koltira/version.rb
62
+ - sig/koltira.rbs
63
+ homepage: https://github.com/koltira-org/koltira-ruby
64
+ licenses: []
65
+ metadata:
66
+ allowed_push_host: https://rubygems.org
67
+ homepage_uri: https://github.com/koltira-org/koltira-ruby
68
+ source_code_uri: https://github.com/koltira-org/koltira-ruby
69
+ changelog_uri: https://github.com/koltira-org/koltira-ruby
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 2.6.0
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubygems_version: 3.3.3
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Koltira - A light framework based on operations handlers
89
+ test_files: []