class_composer 0.0.1

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: a1bb350ed5d28637c5d2cf2574450eb66459c14c06a49e6f427eaece430df73f
4
+ data.tar.gz: db684a27bbe7b948380538952c1a9f6a348c6c2c96c1e7774915b92709b0f372
5
+ SHA512:
6
+ metadata.gz: 3a316374ba96891a3b1e202893bb79d125db16126636a981b7a19f5aa3caad8b34756f6b650bbc4632996e2de49e8ceb2399b40773213145570d7804fc77a4bd
7
+ data.tar.gz: 0e04d577ad1984244d0a89be64c407f456d53641486ec06531d7cf390ce8439029dc8cdea7ee42acadb123d8ee1c5e7888e061a1524cee3b2b52c842fa1282d8
@@ -0,0 +1,27 @@
1
+ version: 2.1
2
+
3
+ orbs:
4
+ cst: cst/framework@1
5
+
6
+ workflows:
7
+ version: 2
8
+ yeet-le-jobs:
9
+ jobs:
10
+ - cst/enforce-gem-version-bump
11
+ - cst/rspec-ruby:
12
+ rspec-system-args: "SIMPLE_COV_RUN=true"
13
+ cc-report-collect-ruby: "2.7.5"
14
+ matrix:
15
+ parameters:
16
+ ruby-version: ["2.7.5" , "3.0.0", "3.0.3"]
17
+ alias: required-matrix-tests
18
+ name: test-ruby<< matrix.ruby-version >>
19
+ - cst/publish-gem:
20
+ publish-git: true
21
+ publish-default-gem: true
22
+ requires:
23
+ - required-matrix-tests
24
+ filters:
25
+ branches:
26
+ only:
27
+ - main
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .DS_Store
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ # generated gems
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.0.1] - 2022-06-18
11
+
12
+ ### Added
13
+ - New feature 1
14
+ - New feature 2
15
+
16
+ ### Changed
17
+ - Changed feature 1
18
+ - Changed feature 2
19
+
20
+ ### Removed
21
+ - Removed feature 1
22
+ - Removed feature 2
23
+
24
+ ### Fixed
25
+ - Bug fix 1
26
+ - Bug fix 2
data/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @matt-taylor
data/Dockerfile ADDED
@@ -0,0 +1,16 @@
1
+ FROM ruby:3.0.1
2
+ RUN cd /tmp && curl -L --output ghr.tar.gz https://github.com/tcnksm/ghr/releases/download/v0.12.0/ghr_v0.12.0_linux_amd64.tar.gz && \
3
+ tar -xzvf ghr.tar.gz && chmod +x ghr_v0.12.0_linux_amd64/ghr && mv ghr_v0.12.0_linux_amd64/ghr /usr/local/bin/ghr && rm -rf /tmp/*
4
+
5
+ WORKDIR /gem
6
+ COPY Gemfile /gem/Gemfile
7
+
8
+ COPY class_composer.gemspec /gem/class_composer.gemspec
9
+ COPY lib/class_composer/version.rb /gem/lib/class_composer/version.rb
10
+
11
+
12
+ RUN gem update --system && gem install bundler && bundle install --jobs=3 --retry=3 && \
13
+ rm -rf /usr/local/bundle/cache
14
+
15
+ COPY . /gem
16
+ RUN gem build class_composer
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in GEMNAME.gemspec
6
+ gemspec
7
+
8
+ gem 'faker'
9
+ gem 'pry'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rspec_junit_formatter'
12
+ gem 'simplecov', require: false, group: :test
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ class_composer (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (11.1.3)
10
+ coderay (1.1.3)
11
+ concurrent-ruby (1.1.10)
12
+ diff-lcs (1.5.0)
13
+ docile (1.4.0)
14
+ faker (2.21.0)
15
+ i18n (>= 1.8.11, < 2)
16
+ i18n (1.10.0)
17
+ concurrent-ruby (~> 1.0)
18
+ method_source (1.0.0)
19
+ pry (0.13.1)
20
+ coderay (~> 1.1)
21
+ method_source (~> 1.0)
22
+ pry-byebug (3.9.0)
23
+ byebug (~> 11.0)
24
+ pry (~> 0.13.0)
25
+ rake (12.3.3)
26
+ rspec (3.11.0)
27
+ rspec-core (~> 3.11.0)
28
+ rspec-expectations (~> 3.11.0)
29
+ rspec-mocks (~> 3.11.0)
30
+ rspec-core (3.11.0)
31
+ rspec-support (~> 3.11.0)
32
+ rspec-expectations (3.11.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.11.0)
35
+ rspec-mocks (3.11.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.11.0)
38
+ rspec-support (3.11.0)
39
+ rspec_junit_formatter (0.5.1)
40
+ rspec-core (>= 2, < 4, != 2.12.0)
41
+ simplecov (0.21.2)
42
+ docile (~> 1.1)
43
+ simplecov-html (~> 0.11)
44
+ simplecov_json_formatter (~> 0.1)
45
+ simplecov-html (0.12.3)
46
+ simplecov_json_formatter (0.1.4)
47
+
48
+ PLATFORMS
49
+ x86_64-linux
50
+
51
+ DEPENDENCIES
52
+ class_composer!
53
+ faker
54
+ pry
55
+ pry-byebug
56
+ rake (~> 12.0)
57
+ rspec (~> 3.0)
58
+ rspec_junit_formatter
59
+ simplecov
60
+
61
+ BUNDLED WITH
62
+ 2.3.16
data/Makefile ADDED
@@ -0,0 +1,21 @@
1
+ .PHONY: bash build bundle rspec
2
+
3
+ APP_NAME?=class-composer
4
+
5
+ build: #: Build the containers that we'll need
6
+ docker-compose build --pull
7
+
8
+ bash: #: Get a bash prompt on the core container
9
+ docker-compose run --rm -e RAILS_ENV=development $(APP_NAME) bash
10
+
11
+ bash_test: #: Get a test bash prompt on the core container
12
+ docker-compose run --rm -e RAILS_ENV=test $(APP_NAME) bash
13
+
14
+ down: #: Bring down the service -- Destroys everything in redis and all containers
15
+ docker-compose down
16
+
17
+ clean: #: Clean up stopped/exited containers
18
+ docker-compose rm -f
19
+
20
+ bundle: #: install gems for Dummy App with
21
+ docker-compose run --rm $(APP_NAME) bundle install
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # ClassComposer
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be
4
+ able to package up your Ruby library into a gem. Put your Ruby code in the file
5
+ `lib/class_composer`. To experiment with that code, run
6
+ `bin/console` for an interactive prompt.
7
+
8
+ TODO: Delete this and the text above, and describe your gem
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'class_composer'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle install
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install class_composer
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
33
+ `rake rspec` to run the tests. You can also run `bin/console` for an interactive
34
+ prompt that will allow you to experiment. Run `bundle exec class_composer` to use
35
+ the gem in this directory, ignoring other installed copies of this gem.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`.
38
+
39
+ To release a new version:
40
+
41
+ 1. Update the version number in [lib/class_composer/version.rb]
42
+ 2. Update [CHANGELOG.md]
43
+ 3. Merge to the main branch. This will trigger an automatic build in CircleCI
44
+ and push the new gem to the repo.
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at
49
+ https://github.com/matt-taylor/class_composer.
50
+
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,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'class_composer'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/publish ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [ -z "$GEMFURY_TOKEN" ]; then
4
+ echo 'Environment variable GEMFURY_TOKEN must be specified. Aborting.'
5
+ exit 1
6
+ fi
7
+
8
+ VERSION=$(make version)
9
+ PACKAGE=class_composer-${VERSION}.gem
10
+
11
+ # Build and publish to Gemfury
12
+ gem build class_composer.gemspec
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ lefthook install
9
+
10
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/class_composer/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "class_composer"
7
+ spec.version = ClassComposer::VERSION
8
+ spec.authors = ["Matt Taylor"]
9
+ spec.email = ["mattius.taylor@gmail.com"]
10
+
11
+ spec.summary = "Describe the gem here"
12
+ spec.description = "Describe the gem here"
13
+ spec.homepage = "https://github.com/matt-taylor/class_composer"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
17
+
18
+ spec.metadata = {
19
+ "homepage_uri" => spec.homepage,
20
+ "source_code_uri" => spec.homepage,
21
+ }
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "pry-byebug"
33
+ spec.add_development_dependency "rake", "~> 12.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "simplecov", "~> 0.17.0"
36
+ end
@@ -0,0 +1,15 @@
1
+ version: '3'
2
+
3
+ services:
4
+ class-composer:
5
+ command: tail -f /dev/null
6
+ build:
7
+ context: .
8
+ dockerfile: ./Dockerfile
9
+ volumes:
10
+ - .:/gem
11
+ - ..:/local
12
+ - bundle-cache:/usr/local/bundle:delegated
13
+
14
+ volumes:
15
+ bundle-cache:
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClassComposer
4
+ class Array
5
+ def initialize(validator)
6
+ @validator = validator
7
+ super
8
+ end
9
+
10
+ def <<
11
+ value = super
12
+
13
+
14
+
15
+ value
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "class_composer/version"
4
+
5
+ module ClassComposer
6
+ module Generator
7
+ def self.included(base)
8
+ base.extend(ClassMethods)
9
+ end
10
+
11
+ module ClassMethods
12
+ COMPOSER_VALIDATE_METHOD_NAME = ->(name) { :"__composer_#{name}_is_valid__?" }
13
+ COMPOSER_ASSIGNED_ATTR_NAME = ->(name) { :"@__composer_#{name}_value_assigned__" }
14
+ COMPOSER_ASSIGNED_ARRAY_METHODS = ->(name) { :"@__composer_#{name}_array_methods_set__" }
15
+
16
+ def add_composer(name, allowed:, default: nil, accessor: true, validator: ->(_) { true }, **params)
17
+ validate_proc = __composer_validator_proc__(validator: validator, allowed: allowed, name: name)
18
+ __composer_validate_options__!(name: name, validate_proc: validate_proc, default: default)
19
+
20
+ array_proc = __composer_array_proc__(name: name, validator: validator, allowed: allowed, params: params)
21
+ __composer_assignment__(name: name, params: params, validator: validate_proc, array_proc: array_proc)
22
+ __composer_retrieval__(name: name, default: default, array_proc: array_proc)
23
+ end
24
+
25
+ def __composer_validate_options__!(name:, validate_proc:, default:)
26
+ unless validate_proc.(default)
27
+ raise ClassComposer::ValidatorError, "Default value [#{default}] for #{self.class}.#{name} is not valid"
28
+ end
29
+
30
+ if self.class.instance_methods.include?(name.to_sym)
31
+ raise ClassComposer::Error, "#{name} is already defined. Ensure composer names are all uniq and do not class with class instance methods"
32
+ end
33
+ end
34
+
35
+ def __composer_array_proc__(name:, validator:, allowed:, params:)
36
+ Proc.new do |value, _itself|
37
+ _itself.send(:"#{name}=", value)
38
+ end
39
+ end
40
+
41
+ # create assignment method for the incoming name
42
+ def __composer_assignment__(name:, params:, validator:, array_proc:)
43
+ define_method(:"#{name}=") do |value|
44
+ is_valid = validator.(value)
45
+
46
+ if is_valid
47
+ instance_variable_set(COMPOSER_ASSIGNED_ATTR_NAME.(name), true)
48
+ instance_variable_set(:"@#{name}", value)
49
+ else
50
+ value.pop
51
+ message = ["#{self.class}.#{name} failed validation."]
52
+
53
+ message << (params[:invalid_message].is_a?(Proc) ? params[:invalid_message].(value) : params[:invalid_message].to_s)
54
+ raise ClassComposer::ValidatorError, message.compact.join(" ")
55
+ end
56
+
57
+ if value.is_a?(Array) && !value.instance_variable_get(COMPOSER_ASSIGNED_ARRAY_METHODS.(name))
58
+ _itself = itself
59
+ value.define_singleton_method(:<<) do |val|
60
+ array_proc.(super(val), _itself)
61
+ end
62
+ value.instance_variable_set(COMPOSER_ASSIGNED_ARRAY_METHODS.(name), true)
63
+ end
64
+
65
+ value
66
+ end
67
+ end
68
+
69
+ # retrieve the value for the name -- Or return the default value
70
+ def __composer_retrieval__(name:, default:, array_proc:)
71
+ define_method(:"#{name}") do
72
+ value = instance_variable_get(:"@#{name}")
73
+ return value if instance_variable_get(COMPOSER_ASSIGNED_ATTR_NAME.(name))
74
+
75
+ if default.is_a?(Array) && !default.instance_variable_get(COMPOSER_ASSIGNED_ARRAY_METHODS.(name))
76
+ _itself = itself
77
+ default.define_singleton_method(:<<) do |value|
78
+ array_proc.(super(value), _itself)
79
+ end
80
+ default.instance_variable_set(COMPOSER_ASSIGNED_ARRAY_METHODS.(name), true)
81
+ end
82
+ default
83
+ end
84
+ end
85
+
86
+ # create validator method for incoming name
87
+ def __composer_validator_proc__(validator:, allowed:, name:)
88
+ if validator && !validator.is_a?(Proc)
89
+ raise ClassComposer::Error, "Expected validator to be a Proc. Received [#{validator.class}]"
90
+ end
91
+
92
+ # Proc will validate the entire attribute -- Full assignment must occur before validate is called
93
+ Proc.new do |value|
94
+ begin
95
+ allow =
96
+ if allowed.is_a?(Array)
97
+ allowed.include?(value.class)
98
+ else
99
+ allowed == value.class
100
+ end
101
+ allow && validator.(value)
102
+ rescue StandardError => e
103
+ raise ClassComposer::Error, "#{e} occured during validation for value [#{value}]. Check custom validator for #{name}"
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ClassComposer
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "class_composer/version"
4
+ require "class_composer/generator"
5
+
6
+ module ClassComposer
7
+ class Error < StandardError; end
8
+ class ValidatorError < Error; end
9
+ # Your code goes here...
10
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: class_composer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matt Taylor
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry-byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.17.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.17.0
69
+ description: Describe the gem here
70
+ email:
71
+ - mattius.taylor@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".circleci/config.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - CHANGELOG.md
80
+ - CODEOWNERS
81
+ - Dockerfile
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - Makefile
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/publish
89
+ - bin/setup
90
+ - class_composer.gemspec
91
+ - docker-compose.yml
92
+ - lib/class_composer.rb
93
+ - lib/class_composer/array.rb
94
+ - lib/class_composer/generator.rb
95
+ - lib/class_composer/version.rb
96
+ homepage: https://github.com/matt-taylor/class_composer
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://github.com/matt-taylor/class_composer
101
+ source_code_uri: https://github.com/matt-taylor/class_composer
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '2.7'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.3.11
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Describe the gem here
121
+ test_files: []