riker 0.1.0.pre3 → 0.1.0.pre4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b819ce3e2d6fb0f84fd16e4eb754802ca3c655810179225c9f4ba9cff3d8f068
4
- data.tar.gz: ab2a5b0a1e9f3beb29c1ba8437de4b50be42f395c79cc833985c7da082c572f4
3
+ metadata.gz: e87101245bca559270ab4ae68b854ddedcf0bcd3a946bdae50571ddb9717b074
4
+ data.tar.gz: 702df1dedeacc6dd92dda5a9e90f0640fb1763d9c766e613c4e9669727cae002
5
5
  SHA512:
6
- metadata.gz: ae433f9f555ceee2b68121953086c7de1e340773ccd1dc802a254126a7bcee94f7f77d2f28427b29e89a6f2e738f9b7aeb5ec709951eb84c150de49bff58ef9c
7
- data.tar.gz: 65a9c8f2be649a18223f3f97caf10b628155f6e0ac54b7891aba504616084eaa6ef85f79f7ac96ff55d7d057d18070bc3a84e527a0ba4b0faac276c80509e74b
6
+ metadata.gz: 4fa7e7eef30b47313061ed59cf958b7fb94ca4db2ea461ca94485b9253a3b52223734729ef51fe97bb33456403731aa68281255486aef21218625db708b06609
7
+ data.tar.gz: 7c24626c3b722677bd57cb5f83fd092e042b2b06fa170b7edc7fa1e18e2c1eb2cb06cd871bcabfd0cba06046502e9a47eb112f2882c40ee16daabceeac5c9514
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- riker (0.1.0.pre2)
4
+ riker (0.1.0.pre4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -12,7 +12,7 @@ High-Performance, Dependency-Free Command Pattern For Ruby
12
12
  ### In your gemfile:
13
13
 
14
14
  ```ruby
15
- gem 'riker', '0.1.0.pre3'
15
+ gem 'riker', '0.1.0.pre4'
16
16
  ```
17
17
 
18
18
  ### In your code:
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riker
4
+ class Command
5
+ # Individual Function
6
+ #
7
+ # Repsonible for debugging and writing out functions
8
+ # for a command to provide the needed functionality
9
+ # that is setup for it.
10
+ #
11
+ class Function
12
+ # @param command [Riker::Command]
13
+ def initialize(command)
14
+ @command = command
15
+ end
16
+
17
+ # @return [Symbol]
18
+ def name
19
+ raise NotImplementedError
20
+ end
21
+
22
+ # @return [Riker::Command::FunctionDetails]
23
+ def details
24
+ raise NotImplementedError
25
+ end
26
+
27
+ private
28
+
29
+ # @return [Riker::Command]
30
+ attr_reader :command
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riker
4
+ class Command
5
+ # Function Detail Data
6
+ #
7
+ # Holds information needed to write a function to a class
8
+ # with `class_eval` on a class object.
9
+ #
10
+ class FunctionDetails
11
+ # @return [String]
12
+ attr_reader :code
13
+
14
+ # @return [String]
15
+ attr_reader :file
16
+
17
+ # @return [Integer]
18
+ attr_reader :line
19
+
20
+ def initialize(code, file, line)
21
+ @code = code
22
+ @file = file
23
+ @line = line
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'run_bang_function'
4
+ require_relative 'initialize_function'
5
+
6
+ module Riker
7
+ class Command
8
+ # Function Writer
9
+ #
10
+ # This is responsible for creating the functions that
11
+ # are needed to create a command pattern class.
12
+ #
13
+ class FunctionWriter
14
+ DEFAULT_FUNCTIONS = [
15
+ RunBangFunction,
16
+ InitializeFunction
17
+ ].freeze
18
+
19
+ # @return [Riker::Command]
20
+ attr_reader :command
21
+
22
+ # @return [Array<Riker::Command::Function>]
23
+ attr_reader :functions
24
+
25
+ # @param command [Riker::Command]
26
+ def initialize(command)
27
+ @command = command
28
+ @functions = DEFAULT_FUNCTIONS.map { |func| func.new(command) }
29
+ end
30
+
31
+ # @param klass [Class]
32
+ def write!(klass)
33
+ klass.define_method(:execute, &command.execute_block)
34
+ define_default_setters!(klass)
35
+ define_attr_readers!(klass)
36
+ write_functions!(klass)
37
+ end
38
+
39
+ private
40
+
41
+ # @param klass [Class]
42
+ def write_functions!(klass)
43
+ functions.each do |function|
44
+ details = function.details
45
+ klass.class_eval(details.code, details.file, details.line)
46
+ end
47
+ end
48
+
49
+ # @param klass [Class]
50
+ def define_attr_readers!(klass)
51
+ klass.attr_reader(*command.parameters.map(&:name))
52
+ end
53
+
54
+ # @param klass [Class]
55
+ def define_default_setters!(klass)
56
+ command.parameters.each do |param|
57
+ param.default.build_default_function!(klass)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riker
4
+ class Command
5
+ # Run!
6
+ #
7
+ # Represents the `initialize` method for your command
8
+ #
9
+ class InitializeFunction < Function
10
+ # @return [Symbol]
11
+ def name
12
+ :initialize
13
+ end
14
+
15
+ # @return [Riker::Command::FunctionDetails]
16
+ def details
17
+ FunctionDetails.new(<<~RUBY, __FILE__, __LINE__ + 1)
18
+ def initialize(#{command.parameters.ctor_args}) # def initialize(foo:)
19
+ #{command.parameters.variable_sets} # @foo = foo
20
+ end # end
21
+ RUBY
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riker
4
+ class Command
5
+ # Command Parameters
6
+ #
7
+ # This is responsible for keeping track of the command's
8
+ # parameters. This includes how they are used and applied
9
+ # to the construction of a command.
10
+ #
11
+ class Parameters
12
+ include Enumerable
13
+ class ParamNameTaken < ::Riker::Error; end
14
+ class InvalidParamName < ::Riker::Error; end
15
+
16
+ def initialize
17
+ # @var [Hash<Symbol, Parameter>]
18
+ @params = {}
19
+ end
20
+
21
+ # @param name [Symbol]
22
+ # @return [Parameters]
23
+ #
24
+ def add(name, **options)
25
+ validate_name!(name)
26
+ @params[name] = Parameter.new(name, **options)
27
+
28
+ self
29
+ end
30
+
31
+ # @return [String]
32
+ def ctor_args
33
+ map(&:ctor_arg).join(', ')
34
+ end
35
+
36
+ # @return [String]
37
+ def variable_sets
38
+ map(&:variable_set).join("\n")
39
+ end
40
+
41
+ # @yield [Parameter]
42
+ def each(&block)
43
+ @params.values.each(&block)
44
+ end
45
+
46
+ private
47
+
48
+ def validate_name!(name)
49
+ raise InvalidParamName unless name.is_a?(Symbol)
50
+ raise ParamNameTaken if @params.key?(name)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riker
4
+ class Command
5
+ # Run!
6
+ #
7
+ # Represents the `run!` static method for your command
8
+ #
9
+ class RunBangFunction < Function
10
+ # @return [Symbol]
11
+ def name
12
+ :run!
13
+ end
14
+
15
+ # @return [Riker::Command::FunctionDetails]
16
+ def details
17
+ FunctionDetails.new(<<~RUBY, __FILE__, __LINE__ + 1)
18
+ def self.run!(**arguments) # def initialize(**arguments)
19
+ command = new(**arguments) # command = new(**arguments)
20
+ command.execute # command.execute
21
+ end # end
22
+ RUBY
23
+ end
24
+ end
25
+ end
26
+ end
data/lib/riker/command.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'command/parameters'
4
+ require_relative 'command/function'
5
+ require_relative 'command/function_details'
6
+ require_relative 'command/function_writer'
7
+
3
8
  module Riker
4
9
  # Command Builder
5
10
  #
@@ -7,56 +12,18 @@ module Riker
7
12
  # track of the build of a command in your application
8
13
  #
9
14
  class Command
10
- # @return [Riker::CommandParameters]
15
+ # @return [Riker::Command::Parameters]
11
16
  attr_reader :parameters
12
17
 
18
+ # @return [Riker::Command::FunctionWriter]
19
+ attr_reader :function_writer
20
+
13
21
  # @return [Proc, nil]
14
22
  attr_accessor :execute_block
15
23
 
16
24
  def initialize
17
- @parameters = CommandParameters.new
18
- end
19
-
20
- # @param klass [Class]
21
- def build!(klass)
22
- klass.define_method(:execute, &execute_block)
23
- define_default_setters!(klass)
24
- define_init!(klass)
25
- define_run_bang!(klass)
26
- define_attr_readers!(klass)
27
- end
28
-
29
- private
30
-
31
- # @param klass [Class]
32
- def define_init!(klass)
33
- klass.class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
34
- def initialize(#{parameters.ctor_args}) # def initialize(foo:)
35
- #{parameters.variable_sets} # @foo = foo
36
- end # end
37
- RUBY
38
- end
39
-
40
- # @param klass [Class]
41
- def define_run_bang!(klass)
42
- klass.class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
43
- def self.run!(**arguments) # def initialize(**arguments)
44
- command = new(**arguments) # command = new(**arguments)
45
- command.execute # command.execute
46
- end # end
47
- RUBY
48
- end
49
-
50
- # @param klass [Class]
51
- def define_attr_readers!(klass)
52
- klass.attr_reader(*parameters.map(&:name))
53
- end
54
-
55
- # @param klass [Class]
56
- def define_default_setters!(klass)
57
- parameters.each do |param|
58
- param.default.build_default_function!(klass)
59
- end
25
+ @parameters = Parameters.new
26
+ @function_writer = FunctionWriter.new(self)
60
27
  end
61
28
  end
62
29
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Riker
4
+ class Parameter
5
+ # Default Parameter Value
6
+ #
7
+ # Sometimes we want to have parameters default to sensible
8
+ # defaults. This class's responsibility is to keep track
9
+ # this and set's up work to ensure defaults setup properly.
10
+ #
11
+ class DefaultValue
12
+ # @return [Symbol]
13
+ attr_reader :name
14
+
15
+ # @return [BasicObject]
16
+ def self.no_value
17
+ :__no_default__
18
+ end
19
+
20
+ # @param name [Symbol]
21
+ # @param value [Object, Proc]
22
+ def initialize(name, value)
23
+ @name = name
24
+ @present = value != :__no_default__
25
+ @value_proc = value.is_a?(Proc) ? value : -> { value }
26
+ end
27
+
28
+ # @return [Boolean]
29
+ def present?
30
+ @present
31
+ end
32
+
33
+ # @return [Symbol, nil]
34
+ def function_name
35
+ return unless present?
36
+
37
+ @function_name ||= :"default_value_for_#{name}"
38
+ end
39
+
40
+ def build_default_function!(klass)
41
+ return unless present?
42
+
43
+ klass.define_method(function_name, &@value_proc)
44
+ klass.send(:private, function_name)
45
+ end
46
+ end
47
+ end
48
+ end
data/lib/riker/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Riker
4
- VERSION = '0.1.0.pre3'
4
+ VERSION = '0.1.0.pre4'
5
5
  end
data/lib/riker.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require_relative 'riker/version'
4
4
  require_relative 'riker/error'
5
5
  require_relative 'riker/command'
6
- require_relative 'riker/command_parameters'
7
6
  require_relative 'riker/parameter'
8
7
 
9
8
  # The Commander of the USS Enterprise
@@ -26,6 +25,6 @@ module Riker
26
25
  raise Error, "execute block already called for #{self}!" if command.execute_block
27
26
 
28
27
  command.execute_block = block
29
- command.build!(self)
28
+ command.function_writer.write!(self)
30
29
  end
31
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre3
4
+ version: 0.1.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Falk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: High-Performance, Dependency-Free Command Pattern For Ruby
14
14
  email:
@@ -29,9 +29,15 @@ files:
29
29
  - bin/setup
30
30
  - lib/riker.rb
31
31
  - lib/riker/command.rb
32
- - lib/riker/command_parameters.rb
32
+ - lib/riker/command/function.rb
33
+ - lib/riker/command/function_details.rb
34
+ - lib/riker/command/function_writer.rb
35
+ - lib/riker/command/initialize_function.rb
36
+ - lib/riker/command/parameters.rb
37
+ - lib/riker/command/run_bang_function.rb
33
38
  - lib/riker/error.rb
34
39
  - lib/riker/parameter.rb
40
+ - lib/riker/parameter/default_value.rb
35
41
  - lib/riker/version.rb
36
42
  - sig/riker.rbs
37
43
  homepage:
@@ -55,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
61
  - !ruby/object:Gem::Version
56
62
  version: 1.3.1
57
63
  requirements: []
58
- rubygems_version: 3.1.6
64
+ rubygems_version: 3.3.7
59
65
  signing_key:
60
66
  specification_version: 4
61
67
  summary: High-Performance, Dependency-Free Command Pattern For Ruby
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Riker
4
- # Command Parameters
5
- #
6
- # This is responsible for keeping track of the command's
7
- # parameters. This includes how they are used and applied
8
- # to the construction of a command.
9
- #
10
- class CommandParameters
11
- include Enumerable
12
- class ParamNameTaken < ::Riker::Error; end
13
- class InvalidParamName < ::Riker::Error; end
14
-
15
- def initialize
16
- # @var [Hash<Symbol, Parameter>]
17
- @params = {}
18
- end
19
-
20
- # @param name [Symbol]
21
- # @return [Parameters]
22
- #
23
- def add(name, **options)
24
- validate_name!(name)
25
- @params[name] = Parameter.new(name, **options)
26
-
27
- self
28
- end
29
-
30
- # @return [String]
31
- def ctor_args
32
- map(&:ctor_arg).join(', ')
33
- end
34
-
35
- # @return [String]
36
- def variable_sets
37
- map(&:variable_set).join("\n")
38
- end
39
-
40
- # @yield [Parameter]
41
- def each(&block)
42
- @params.values.each(&block)
43
- end
44
-
45
- private
46
-
47
- def validate_name!(name)
48
- raise InvalidParamName unless name.is_a?(Symbol)
49
- raise ParamNameTaken if @params.key?(name)
50
- end
51
- end
52
- end