sphene 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -4
- data/CHANGELOG.md +5 -1
- data/lib/sphene/attribute.rb +13 -8
- data/lib/sphene/attribute_set.rb +7 -7
- data/lib/sphene/attributes.rb +8 -8
- data/lib/sphene/version.rb +1 -1
- data/sphene.gemspec +5 -4
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91b76824fa0ecc2418e1b299e66df90c20c73ee7f1fba1563f98f720ce5ad69c
|
4
|
+
data.tar.gz: 12e1c20dc77847a0fc65373d21ecff8e0d7569657edd03f092e91049ea4daca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95f5e80b28e111ea3cfce0c9ffb92ba2990ecd24bbaad06f17c51ea02a3b459a28bd90aca039627375ed55d2b4203f883622dd2098a5542dd3dec6a8c6e0dbe
|
7
|
+
data.tar.gz: 7a9da9ed8c9936517d2948a315c86473d0205c7c59ef6e1a61f31801b2858b077cb63b59c3bd31f57d933897d026f8c42470428d60bc437a660cf0c3e27281a2
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
-
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.7
|
3
4
|
|
4
5
|
Style/StringLiterals:
|
5
6
|
Enabled: true
|
@@ -9,11 +10,11 @@ Style/StringLiteralsInInterpolation:
|
|
9
10
|
Enabled: true
|
10
11
|
EnforcedStyle: double_quotes
|
11
12
|
|
12
|
-
Style/Documentation:
|
13
|
-
Enabled: false
|
14
|
-
|
15
13
|
Layout/LineLength:
|
16
14
|
Max: 120
|
17
15
|
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
18
|
+
|
18
19
|
Layout/EmptyLineAfterGuardClause:
|
19
20
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
data/lib/sphene/attribute.rb
CHANGED
@@ -2,34 +2,39 @@
|
|
2
2
|
|
3
3
|
module Sphene
|
4
4
|
class Attribute
|
5
|
-
attr_reader :name, :type, :default
|
5
|
+
attr_reader :name, :model, :type, :default
|
6
6
|
|
7
|
-
def initialize(name, type: Types::Default, default: nil)
|
7
|
+
def initialize(name, model, type: Types::Default, default: nil)
|
8
8
|
@name = name
|
9
|
+
@model = model
|
9
10
|
@type = type
|
10
11
|
@default = default
|
11
12
|
end
|
12
13
|
|
13
14
|
def value
|
14
|
-
return
|
15
|
+
return default_value unless ivar_defined?(:@value_before_cast)
|
15
16
|
return @value if ivar_defined?(:@value)
|
16
|
-
@value = type.cast(
|
17
|
+
@value = type.cast(@value_before_cast)
|
17
18
|
end
|
18
19
|
|
19
20
|
def value=(value)
|
20
|
-
|
21
|
+
remove_ivar(:@value) if ivar_defined?(:@value)
|
21
22
|
@value_before_cast = value
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
27
|
+
def default_value
|
28
|
+
return default unless default.respond_to?(:call)
|
29
|
+
model.instance_exec(&default)
|
29
30
|
end
|
30
31
|
|
31
32
|
def ivar_defined?(name)
|
32
33
|
instance_variable_defined?(name)
|
33
34
|
end
|
35
|
+
|
36
|
+
def remove_ivar(name)
|
37
|
+
remove_instance_variable(name)
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
data/lib/sphene/attribute_set.rb
CHANGED
@@ -4,17 +4,17 @@ require "delegate"
|
|
4
4
|
|
5
5
|
module Sphene
|
6
6
|
class AttributeSet < SimpleDelegator
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :model
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@
|
9
|
+
def initialize(model)
|
10
|
+
@model = model
|
11
11
|
super({})
|
12
12
|
end
|
13
13
|
|
14
|
-
def self.from(
|
15
|
-
new(
|
16
|
-
|
17
|
-
data[name] = Attribute.new(name, **options)
|
14
|
+
def self.from(model)
|
15
|
+
new(model).tap do |data|
|
16
|
+
model.class.attributes.each do |name, options|
|
17
|
+
data[name] = Attribute.new(name, model, **options)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
data/lib/sphene/attributes.rb
CHANGED
@@ -17,14 +17,14 @@ module Sphene
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def read_attribute(name)
|
20
|
-
ensure_attribute(name) do |
|
21
|
-
@attributes[
|
20
|
+
ensure_attribute(name) do |attr|
|
21
|
+
@attributes[attr].value
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def write_attribute(name, value)
|
26
|
-
ensure_attribute(name) do |
|
27
|
-
@attributes[
|
26
|
+
ensure_attribute(name) do |attr|
|
27
|
+
@attributes[attr].value = value
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -41,7 +41,7 @@ module Sphene
|
|
41
41
|
private
|
42
42
|
|
43
43
|
def initialize_attributes
|
44
|
-
@attributes = AttributeSet.from(self
|
44
|
+
@attributes = AttributeSet.from(self)
|
45
45
|
end
|
46
46
|
|
47
47
|
def ensure_attribute(name)
|
@@ -50,9 +50,8 @@ module Sphene
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def assert_attribute(name)
|
53
|
-
|
54
|
-
raise InvalidAttributeNameError
|
55
|
-
end
|
53
|
+
@attributes.key?(name.to_sym) ||
|
54
|
+
(raise InvalidAttributeNameError, name)
|
56
55
|
end
|
57
56
|
|
58
57
|
module ClassMethods
|
@@ -65,6 +64,7 @@ module Sphene
|
|
65
64
|
end
|
66
65
|
|
67
66
|
def inherited(base)
|
67
|
+
super
|
68
68
|
base.instance_variable_set(:@attributes, attributes.dup)
|
69
69
|
end
|
70
70
|
|
data/lib/sphene/version.rb
CHANGED
data/sphene.gemspec
CHANGED
@@ -8,17 +8,18 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Alejandro Gutiérrez"]
|
9
9
|
spec.email = ["alejandrodevs@gmail.com"]
|
10
10
|
|
11
|
-
spec.summary = "
|
12
|
-
spec.description = "
|
11
|
+
spec.summary = "Simple and lightweight gem for class attributes."
|
12
|
+
spec.description = "Simple and lightweight gem for class attributes."
|
13
13
|
spec.homepage = "https://github.com/alejandrodevs/sphene"
|
14
14
|
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
16
16
|
|
17
|
-
#spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
18
18
|
|
19
19
|
spec.metadata["homepage_uri"] = spec.homepage
|
20
20
|
spec.metadata["source_code_uri"] = spec.homepage
|
21
21
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
22
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
22
23
|
|
23
24
|
# Specify which files should be added to the gem when it is released.
|
24
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sphene
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alejandro Gutiérrez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: Simple and lightweight gem for class attributes.
|
14
14
|
email:
|
15
15
|
- alejandrodevs@gmail.com
|
16
16
|
executables: []
|
@@ -54,6 +54,7 @@ metadata:
|
|
54
54
|
homepage_uri: https://github.com/alejandrodevs/sphene
|
55
55
|
source_code_uri: https://github.com/alejandrodevs/sphene
|
56
56
|
changelog_uri: https://github.com/alejandrodevs/sphene/blob/master/CHANGELOG.md
|
57
|
+
rubygems_mfa_required: 'true'
|
57
58
|
post_install_message:
|
58
59
|
rdoc_options: []
|
59
60
|
require_paths:
|
@@ -62,15 +63,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
63
|
requirements:
|
63
64
|
- - ">="
|
64
65
|
- !ruby/object:Gem::Version
|
65
|
-
version: 2.
|
66
|
+
version: 2.7.0
|
66
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
68
|
requirements:
|
68
69
|
- - ">="
|
69
70
|
- !ruby/object:Gem::Version
|
70
71
|
version: '0'
|
71
72
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.3.7
|
73
74
|
signing_key:
|
74
75
|
specification_version: 4
|
75
|
-
summary:
|
76
|
+
summary: Simple and lightweight gem for class attributes.
|
76
77
|
test_files: []
|