store_model 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/store_model/model.rb +25 -1
- data/lib/store_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85a27e1f3a20217b3f6134d8f2679d556ce445c74b47ff223a3abec247219b9
|
4
|
+
data.tar.gz: e4c5baceadbbd1049ff8c0616e31d41302178ed74929ee512e1625a8d983c870
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e900e6ffeaffb83c1bc87b66b810d5e652871908c46542f1d3edbd7791761721d8a69bef57b9e187ce700c480dbd7c59d0dc9cda6a01092d64fcba27c4eb277
|
7
|
+
data.tar.gz: 8744a4125da41b45bb0bb510296924758b5b07345e173cf4193a5ca0b3759f62aa2dfc54b4d9233d757d7c92e8ce0a0fed2c139f95c51ab91935bfc8e440001e
|
data/README.md
CHANGED
@@ -44,7 +44,7 @@ This approach works fine when you don't have a lot of keys with logic around the
|
|
44
44
|
|
45
45
|
For instance, try to find a way to validate `:model` value to be required. Despite of the fact, that you'll have to write this validation by hand, it violates single-repsponsibility principle: why parent model (`Product`) should know about the logic related to a child (`Configuration`)?
|
46
46
|
|
47
|
-
> 📖 Read more about the motivation in the [Wrapping JSON-based ActiveRecord attributes with classes](https://
|
47
|
+
> 📖 Read more about the motivation in the [Wrapping JSON-based ActiveRecord attributes with classes](https://evilmartians.com/chronicles/wrapping-json-based-active-record-attributes-with-classes) post
|
48
48
|
|
49
49
|
## Getting started
|
50
50
|
|
data/lib/store_model/model.rb
CHANGED
@@ -70,13 +70,37 @@ module StoreModel
|
|
70
70
|
|
71
71
|
# Checks if the attribute with a given name is defined
|
72
72
|
#
|
73
|
+
# @example
|
74
|
+
# class Person
|
75
|
+
# include StoreModel::Model
|
76
|
+
# attribute :name, :string
|
77
|
+
# alias_attribute :new_name, :name
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# Person.has_attribute?('name') # => true
|
81
|
+
# Person.has_attribute?('new_name') # => true
|
82
|
+
# Person.has_attribute?(:age) # => true
|
83
|
+
# Person.has_attribute?(:nothing) # => false
|
84
|
+
#
|
73
85
|
# @param attr_name [String] name of the attribute
|
74
86
|
#
|
75
87
|
# @return [Boolean]
|
76
88
|
# rubocop:disable Naming/PredicateName
|
77
89
|
def has_attribute?(attr_name)
|
78
|
-
|
90
|
+
attr_name = attr_name.to_s
|
91
|
+
attr_name = self.class.attribute_aliases[attr_name] || attr_name
|
92
|
+
attribute_types.key?(attr_name)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Legacy implementation of #has_attribute?
|
96
|
+
#
|
97
|
+
# @param attr_name [String] name of the attribute
|
98
|
+
#
|
99
|
+
# @return [Boolean]
|
100
|
+
def _has_attribute?(attr_name)
|
101
|
+
attribute_types.key?(attr_name)
|
79
102
|
end
|
103
|
+
|
80
104
|
# rubocop:enable Naming/PredicateName
|
81
105
|
|
82
106
|
# Contains a hash of attributes which are not defined but exist in the
|
data/lib/store_model/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|