Class: ClearLogic::Types
- Inherits:
-
Object
- Object
- ClearLogic::Types
- Defined in:
- lib/clear_logic/types.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #define ⇒ Object
-
#initialize(klass, prefix: nil) ⇒ Types
constructor
A new instance of Types.
- #klass_key ⇒ Object
- #register ⇒ Object
Constructor Details
#initialize(klass, prefix: nil) ⇒ Types
Returns a new instance of Types.
11 12 13 14 |
# File 'lib/clear_logic/types.rb', line 11 def initialize(klass, prefix: nil) @klass = klass @prefix = prefix end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/clear_logic/types.rb', line 5 def klass @klass end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
5 6 7 |
# File 'lib/clear_logic/types.rb', line 5 def prefix @prefix end |
Class Method Details
.register(*args) ⇒ Object
7 8 9 |
# File 'lib/clear_logic/types.rb', line 7 def self.register(*args) new(*args).register end |
Instance Method Details
#define ⇒ Object
20 21 22 |
# File 'lib/clear_logic/types.rb', line 20 def define Dry::Types::Nominal.new(klass).constrained(type: klass) end |
#klass_key ⇒ Object
24 25 26 |
# File 'lib/clear_logic/types.rb', line 24 def klass_key [prefix, Dry::Inflector.new.underscore(klass.name).gsub('/', '.')].compact.join('.') end |
#register ⇒ Object
16 17 18 |
# File 'lib/clear_logic/types.rb', line 16 def register Dry::Types.register(klass_key, define) end |