hws-resources 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 42ec8ec2906b290d7d0543dd289bb7ef6e5b6e2ace24acb5070bccbaeec5d295
4
+ data.tar.gz: 7c7b9b8123dec773d4de42aa8e1f92b34f0ad5152d4e4c8f98bce53f50c2e2d6
5
+ SHA512:
6
+ metadata.gz: d59f5b30144b0bea35e5e40b6d39480998421f638579d7f0b00d7ccb8d30ea4087d00445757f53b1a3ac76399bda795b176ac340a970f3d6eae880ba27f6ebd3
7
+ data.tar.gz: cf34c91ff55368dbb948801eb13b1673e453fe5c1318b16cff5a49978502c1faeb493e32c3c52abff01e641717fb5c1ec4bfaf813ce8a5a8c74caf1efdd0a6e7
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: single_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/ClassAndModuleChildren:
14
+ Enabled: true
15
+ EnforcedStyle: compact
16
+
17
+ Style/RedundantSelf:
18
+ Enabled: false
19
+
20
+ Layout/LineLength:
21
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-23
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in hws-resources-ruby.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.7'
13
+
14
+ gem 'json_schemer', '0.2.16'
15
+ gem 'lsuuid', '0.1.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Karthick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Hws::Resources
2
+
3
+ We define resource as an independent financial entity that can be used to represent any physical or virtual component of value. A resource can be stored or used as a medium of exchange to create any use case in centralized and decentralized finance. This library can be used to programmatically define and manage resources.
4
+
5
+ ## Installation
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'hws-resources'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle install
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install hws-resource
19
+
20
+ ## Usage
21
+
22
+ ### Create a resource
23
+
24
+ ```ruby
25
+ Hws::Resources::Models::Resource.create(name: "hypto_coin", schema: {"type": "integer", "multipleOf" => 0.001})
26
+
27
+ => #<Hws::Resources::Models::Resource id: "99dbf504-ffc4-46d3-aea1-802f91ebd0b0", name: "hypto_coin", description: nil, resource_type: "fungible_connected", schema: {"type"=>"integer", "multipleOf"=>0.001}, created_at: "2021-11-25 13:46:27", updated_at: "2021-11-25 13:46:27">
28
+ ```
29
+
30
+ ### Update a resource
31
+
32
+ Schema is marked a read_only and cannot be updated. Only the name and description of the resource can be updated
33
+
34
+ ```ruby
35
+ Hws::Resources::Models::Resource
36
+ .find_by(id: "99dbf504-ffc4-46d3-aea1-802f91ebd0b0")
37
+ .update!(name: 'Hypto Duper Coin', description: 'Sample primitive financial resource')
38
+ => true
39
+ ```
40
+ ### Delete a resource
41
+
42
+ ```ruby
43
+ Hws::Resources::Models::Resource
44
+ .find_by(id: "99dbf504-ffc4-46d3-aea1-802f91ebd0b0")
45
+ .delete
46
+ => #<Hws::Resources::Models::Resource id: "99dbf504-ffc4-46d3-aea1-802f91ebd0b0", ...>
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hwslabs/hws-resources-ruby.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'hws-resources'
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
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
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,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/migration'
4
+ require 'rails/generators/active_record'
5
+
6
+ module Hws
7
+ module Resources
8
+ class InstallGenerator < ::Rails::Generators::Base # :nodoc:
9
+ include Rails::Generators::Migration
10
+ source_root File.expand_path('templates', __dir__)
11
+
12
+ def self.next_migration_number(path)
13
+ ActiveRecord::Generators::Base.next_migration_number(path)
14
+ end
15
+
16
+ desc 'copying migrations to db/migrate'
17
+ def copy_migrations
18
+ migration_template 'migration.rb.erb', 'db/migrate/create_hws_resources_tables.rb'
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def self.up
3
+ enable_extension 'pgcrypto' unless extensions.include?('pgcrypto')
4
+ create_table :resources, id: :uuid, force: true do |t|
5
+ t.string :name
6
+ t.text :description
7
+ t.string :resource_type # fungible_backed, fungible_soft, non_fungibe
8
+ t.jsonb :schema, default: {}
9
+ t.timestamps
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :resources
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json_schemer'
4
+
5
+ class Hws::Resources::Models::Resource < ActiveRecord::Base # :nodoc:
6
+ attr_readonly :schema
7
+
8
+ validate :validate_schema, on: :create
9
+
10
+ private
11
+
12
+ def validate_schema
13
+ if self.schema.blank?
14
+ errors.add(:schema, 'blank schema specified')
15
+ return
16
+ end
17
+ JSONSchemer.schema(self.schema)
18
+ rescue StandardError => _e
19
+ errors.add(:schema, 'invalid schema specified')
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hws
4
+ module Resources
5
+ module Models # :nodoc:
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'hws-resources/models/resource'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hws-resources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hypto Engineering Team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json_schemer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.16
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.16
27
+ - !ruby/object:Gem::Dependency
28
+ name: lsuuid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ description: Experimental resource primitive
42
+ email:
43
+ - engineering@hypto.in
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rspec"
49
+ - ".rubocop.yml"
50
+ - CHANGELOG.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - lib/generators/hws/resources/install_generator.rb
58
+ - lib/generators/hws/resources/templates/migration.rb.erb
59
+ - lib/hws-resources.rb
60
+ - lib/hws-resources/models/resource.rb
61
+ homepage: https://github.com/hwslabs/hws-resources-ruby
62
+ licenses:
63
+ - MIT
64
+ metadata:
65
+ homepage_uri: https://github.com/hwslabs/hws-resources-ruby
66
+ source_code_uri: https://github.com/hwslabs/hws-resources-ruby
67
+ changelog_uri: https://github.com/hwslabs/hws-resources-ruby/blob/main/CHANGELOG.md
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.5.0
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Experimental resource primitive
87
+ test_files: []