odsl 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3381098ae987f86e0112bd8dd2da9b3e8967f8f1ff877db7b3276fd4953c252a
4
- data.tar.gz: 4f80c98a9b2545b5b34b98a224cc09b4f079b9cb16160976fa89bd41e67547c4
3
+ metadata.gz: b972b04076091e4880481f3120c36fc38d233dae65c68ed62cfb5089b5064978
4
+ data.tar.gz: a974bbde6e1cc8e7c9fa9f6af823c0d7ded81e5f11ca0bbf2b69ac69adc17cc5
5
5
  SHA512:
6
- metadata.gz: fc52a73349084832f0d5b33abf0cce2ae2dc66bfe69c4d1c7f56820b29c823a3ea75c66a79b6446e8104dc709ba18916f5e13ff172c3146633c74bd17aab27a5
7
- data.tar.gz: 83412e38868589940d872853ae46e7fe34f9954bc19e2c460eb7597a7c5511df591ff9747fd61720c38a7f42a5228f319b82ee8e9ad3d73ef0aac03259bd6821
6
+ metadata.gz: efd5eaaee6252374c7bdf82c44479770d211e570e1daedea948285aaa51a2e121020361c585480be3728ee49bb0a93e2301a49bacc48276fbeeeea5cc7dfe9fa
7
+ data.tar.gz: 63e3865d022968e0fae4e09c3c8fe5ccef63b7b0f1a46efcad11a18be34c50edd93d07edf55daf900cb0b1987017979f3f753d3b24b2f8c43a9a41fc22f505ab
data/README.md CHANGED
@@ -10,6 +10,17 @@ This is a prototype oriented to use OOP and a functional programming approach by
10
10
  # Your code
11
11
 
12
12
  ```
13
+ class ScoreBoard
14
+
15
+ def initialize(game_object)
16
+ @game, @player = game_object.game, game_object.player
17
+ end
18
+
19
+ def publish
20
+ STDOUT.puts "Player: @player.name is playing: #{@game.game_type}"
21
+ end
22
+ end
23
+
13
24
  module Game
14
25
  def start(game_type)
15
26
  @game = Struct.new(game_type: game_type, player: @player.name)
@@ -26,7 +37,7 @@ end
26
37
 
27
38
  module Game
28
39
  module Crud
29
- def create
40
+ def create
30
41
  build(Game, Players)
31
42
  .get(:game_object)
32
43
 
@@ -34,6 +45,13 @@ module Game
34
45
  .set(:new_game)
35
46
  .get(:game_instance)
36
47
 
48
+ with(:game_object)
49
+ .instanciate(ScoreBoard)
50
+ .get(:score_board_object)
51
+
52
+ with(:score_board_object)
53
+ .call(:publish)
54
+
37
55
  finish_with(:game_instance)
38
56
  end
39
57
 
@@ -68,8 +86,24 @@ Games::Service
68
86
  .run(:create)
69
87
  ```
70
88
 
71
-
72
89
  # Future development
73
90
 
74
- .run_in_background()
75
- .run_in_parallel()
91
+ - Run in background mode
92
+
93
+ ```.run_in_background(:method)```
94
+
95
+ - Run sevreral methods in paralell
96
+
97
+ ```.run_in_parallel(:method_a, :method_b)```
98
+
99
+ - Make service objects subscribe to messaages
100
+
101
+ module Game
102
+ class Service < Odsl:Dsl
103
+ include Crud
104
+
105
+ subscribe 'start_game', to: :create
106
+ subscribe 'end_game', to: end_game
107
+ end
108
+ end
109
+ ```
data/lib/odsl/dsl.rb CHANGED
@@ -11,6 +11,7 @@ module Odsl
11
11
 
12
12
  def initialize(**kwargs)
13
13
 
14
+ @delegated = self
14
15
  @kwargs = kwargs
15
16
  @context = {}
16
17
  @last_results = []
@@ -33,6 +34,20 @@ module Odsl
33
34
 
34
35
  protected
35
36
 
37
+ def instantiate(object, public: false)
38
+
39
+ resolved_attrs = with_attributes_resolver
40
+
41
+ @last_results = [ ] << if resolved_attrs.any?
42
+
43
+ resolved_attrs.is_a?(Array) ? object.new(*resolved_attrs) : object.new(**resolved_attrs)
44
+ else
45
+ object.new
46
+ end
47
+
48
+ self
49
+ end
50
+
36
51
  def build(*modules)
37
52
  @last_results = [ Odsl::Builder.build(*modules).new ]
38
53
  self
@@ -43,7 +58,7 @@ module Odsl
43
58
  self
44
59
  end
45
60
 
46
- def value_return(with)
61
+ def value_return(*with)
47
62
  @finish_with = with
48
63
  end
49
64
 
data/lib/odsl/methods.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  module Odsl
2
2
  module Methods
3
+
4
+ def use(object)
5
+ @delegated = instance_variable_get("@#{object}")
6
+
7
+ self
8
+ end
9
+
3
10
  def call(methodo)
4
-
5
- @last_results = send(methodo, *@with_attributes.map { |attribute| instance_variable_get("@#{attribute}") })
6
- @last_results = [@last_results] unless @last_results.is_a? Array
7
-
11
+
12
+ run_method(methodo)
13
+ restore_delegate
14
+
8
15
  self
9
16
  end
10
17
 
@@ -15,5 +22,20 @@ module Odsl
15
22
 
16
23
  self
17
24
  end
25
+
26
+ private
27
+
28
+ def run_method(methodo)
29
+ @last_results = @delegated.send(methodo, *with_attributes_resolver)
30
+ @last_results = [ @last_results ] unless @last_results.is_a? Array
31
+ end
32
+
33
+ def restore_delegate
34
+ @delegated = self
35
+ end
36
+
37
+ def with_attributes_resolver
38
+ @with_attributes.map { |attribute| instance_variable_get("@#{attribute}") }
39
+ end
18
40
  end
19
41
  end
data/lib/odsl/runners.rb CHANGED
@@ -3,7 +3,13 @@ module Odsl
3
3
  def run(method)
4
4
 
5
5
  instance_eval(method.to_s)
6
- instance_variable_get "@#{@finish_with}"
6
+
7
+ if @finish_with.is_a? Array
8
+
9
+ @finish_with.map { |variable| instance_variable_get("@#{variable}") }
10
+ else
11
+ instance_variable_get "@#{@finish_with}"
12
+ end
7
13
  end
8
14
  end
9
15
  end
data/lib/odsl/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Odsl
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/odsl.gemspec CHANGED
@@ -1,44 +1,44 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path(
4
- File.join('..', 'lib', 'odsl', 'version'),
5
- __FILE__
6
- )
7
-
8
- Gem::Specification.new do |spec|
9
- spec.name = "odsl"
10
- spec.version = Odsl::VERSION
11
- spec.authors = ["alejandro gurovich"]
12
- spec.email = ["alejandro.gurovich@gmail.com"]
13
-
14
- spec.summary = "DSL Approach to OOP and functional programming."
15
- spec.description = "This is a prototype oriented to use OOP and a functional programming approach by providing a DSL to decouple code logic from coding itself while enforcing good practices and providing - Design patterns
16
- - Inmutability
17
- - Dry off
18
- - Decouple aspects from code ( background, paralelization )."
19
- spec.homepage = "https://github.com/aleguro/ODSL."
20
- spec.license = "MIT"
21
- spec.required_ruby_version = ">= 2.6.0"
22
-
23
- spec.metadata["homepage_uri"] = spec.homepage
24
- spec.metadata["source_code_uri"] = "https://github.com/aleguro/ODSL"
25
- spec.metadata["changelog_uri"] = "https://github.com/aleguro/ODSL/blob/master/CHANGELOG.md"
26
-
27
- # Specify which files should be added to the gem when it is released.
28
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
- spec.files = Dir.chdir(__dir__) do
30
- `git ls-files -z`.split("\x0").reject do |f|
31
- (File.expand_path(f) == __FILE__) ||
32
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
33
- end
34
- end
35
- spec.bindir = "exe"
36
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
37
- spec.require_paths = ["lib"]
38
-
39
- spec.add_development_dependency "minitest", ">= 5.8"
40
- spec.add_development_dependency "minitest-reporters", ">= 1.1"
41
-
42
- # For more information and examples about making a new gem, check out our
43
- # guide at: https://bundler.io/guides/creating_gem.html
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path(
4
+ File.join('..', 'lib', 'odsl', 'version'),
5
+ __FILE__
6
+ )
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "odsl"
10
+ spec.version = Odsl::VERSION
11
+ spec.authors = ["alejandro gurovich"]
12
+ spec.email = ["alejandro.gurovich@gmail.com"]
13
+
14
+ spec.summary = "DSL Approach to OOP and functional programming."
15
+ spec.description = "This is a prototype oriented to use OOP and a functional programming approach by providing a DSL to decouple code logic from coding itself while enforcing good practices and providing - Design patterns
16
+ - Inmutability
17
+ - Dry off
18
+ - Decouple aspects from code ( background, paralelization )."
19
+ spec.homepage = "https://github.com/aleguro/ODSL"
20
+ spec.license = "MIT"
21
+ spec.required_ruby_version = ">= 2.6.0"
22
+
23
+ spec.metadata["homepage_uri"] = spec.homepage
24
+ spec.metadata["source_code_uri"] = "https://github.com/aleguro/ODSL"
25
+ spec.metadata["changelog_uri"] = "https://github.com/aleguro/ODSL/blob/master/CHANGELOG.md"
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(__dir__) do
30
+ `git ls-files -z`.split("\x0").reject do |f|
31
+ (File.expand_path(f) == __FILE__) ||
32
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
33
+ end
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = [] #spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "minitest", ">= 5.8"
40
+ spec.add_development_dependency "minitest-reporters", ">= 1.1"
41
+
42
+ # For more information and examples about making a new gem, check out our
43
+ # guide at: https://bundler.io/guides/creating_gem.html
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alejandro gurovich
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -64,11 +64,11 @@ files:
64
64
  - lib/odsl/version.rb
65
65
  - odsl.gemspec
66
66
  - sig/odsl.rbs
67
- homepage: https://github.com/aleguro/ODSL.
67
+ homepage: https://github.com/aleguro/ODSL
68
68
  licenses:
69
69
  - MIT
70
70
  metadata:
71
- homepage_uri: https://github.com/aleguro/ODSL.
71
+ homepage_uri: https://github.com/aleguro/ODSL
72
72
  source_code_uri: https://github.com/aleguro/ODSL
73
73
  changelog_uri: https://github.com/aleguro/ODSL/blob/master/CHANGELOG.md
74
74
  post_install_message: