-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added getter and setter Domain Specific Language (DSL) as features to the Datory framework. This change includes creation of new files for getter, setter, and their collection classes. Moreover, adjustments were made in the test files and examples to demonstrate the usage of these newly added features.
- Loading branch information
Showing
15 changed files
with
222 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Getters | ||
class Collection | ||
extend Forwardable | ||
def_delegators :@collection, :<<, :each, :merge | ||
|
||
def initialize(collection = Set.new) | ||
@collection = collection | ||
end | ||
|
||
# def find_by(name:) | ||
# find { |getter| getter.name == name } | ||
# end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Getters | ||
module DSL | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
base.include(Workspace) | ||
end | ||
|
||
module ClassMethods | ||
def inherited(child) | ||
super | ||
|
||
child.send(:collection_of_getters).merge(collection_of_getters) | ||
end | ||
|
||
private | ||
|
||
def getter(name) | ||
collection_of_getters << Getter.new(name, ->(attributes:) { yield(attributes: attributes) }) | ||
end | ||
|
||
def collection_of_getters | ||
@collection_of_getters ||= Collection.new | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Getters | ||
class Getter | ||
attr_reader :name, :block | ||
|
||
def initialize(name, block) | ||
@name = name | ||
@block = block | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Getters | ||
module Workspace | ||
private | ||
|
||
def deserialize(incoming_attributes:, collection_of_attributes:, collection_of_getters:) | ||
super | ||
|
||
collection_of_getters.each do |getter| | ||
incoming_attributes.merge!(getter.name => getter.block.call(attributes: incoming_attributes)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Setters | ||
class Collection | ||
extend Forwardable | ||
def_delegators :@collection, :<<, :each, :merge | ||
|
||
def initialize(collection = Set.new) | ||
@collection = collection | ||
end | ||
|
||
# def find_by(name:) | ||
# find { |getter| getter.name == name } | ||
# end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Setters | ||
module DSL | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
base.include(Workspace) | ||
end | ||
|
||
module ClassMethods | ||
def inherited(child) | ||
super | ||
|
||
child.send(:collection_of_setters).merge(collection_of_setters) | ||
end | ||
|
||
private | ||
|
||
def setter(name) | ||
collection_of_setters << Setter.new(name, ->(attributes:) { yield(attributes: attributes) }) | ||
end | ||
|
||
def collection_of_setters | ||
@collection_of_setters ||= Collection.new | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Setters | ||
class Setter | ||
attr_reader :name, :block | ||
|
||
def initialize(name, block) | ||
@name = name | ||
@block = block | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datory | ||
module Setters | ||
module Workspace | ||
private | ||
|
||
def serialize(model:, collection_of_attributes:, collection_of_setters:) | ||
super | ||
|
||
collection_of_setters.each do |setter| | ||
hash = Datory::Attributes::Serialization::Model.to_hash(model) | ||
|
||
model.add(setter.name, setter.block.call(attributes: hash)) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters