ar_virtual_field 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ar_virtual_field/version.rb +1 -1
- data/lib/ar_virtual_field.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 891a7d54ceef88352b9799d13a9fa27ee5a390e0ecacc634de0140e61565a648
|
4
|
+
data.tar.gz: 138333e6d5f189a1754ad35b50ac7283cabef173df02c37e2f1848bedf18d7c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c95f69519e4d0c4abaacfcb98c878fc7aedf964d7e9bae19e7054eb80a440284004b03251a002259ebcd7494cbe9dade1e16e9640cd99019a545c35b3882bb69
|
7
|
+
data.tar.gz: 7c424b0acc36049f65192e9ebf7ecaa3f7c62b76c88785494c92cefb5184bb36eeb7e9944d68b5d918e1ffd1e52b174d397f14ce8c82475f2fc4aea39c0d6595
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ virtual_field :virtual_attribute,
|
|
29
29
|
Parameters:
|
30
30
|
- `name`: The name of the virtual field.
|
31
31
|
- `scope`: A lambda defining a scope that fetches the virtual field value (optional).
|
32
|
-
- `select`: SQL selection logic (can be a string or a lambda returning an SQL string) to define how the field is computed.
|
32
|
+
- `select`: SQL selection logic (can be a `string | arel_node` or a lambda returning an SQL `string | arel_node`) to define how the field is computed.
|
33
33
|
- `get`: A method to retrieve the value of the virtual field when the field isn't fetched via SQL.
|
34
34
|
- `default`: A default value for the virtual field if the result is nil.
|
35
35
|
|
data/lib/ar_virtual_field.rb
CHANGED
@@ -11,7 +11,7 @@ module ArVirtualField
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def virtual_field(name, scope
|
14
|
+
def virtual_field(name, scope: nil, select:, get:, default:)
|
15
15
|
name = name.to_s
|
16
16
|
current_class = self
|
17
17
|
unwrap_arel_expression = -> (exp) { exp.is_a?(Arel::Nodes::NodeExpression) ? exp : Arel.sql(exp) }
|