active_dynamic 0.5.1 → 0.5.2
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 +4 -3
- data/lib/active_dynamic/has_dynamic_attributes.rb +7 -1
- data/lib/active_dynamic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e209fa9cc3fc6975f796cdf16604f243035548b5
|
|
4
|
+
data.tar.gz: 6a86403d63d1839c8bbcee14e428c38d2e0a1065
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1d0d2ac25933e40b50f604fe667fc5ae8a09da7afa139c534f1ce8e74f02bb11fa0f0bdd4206c4a46ee5838159d64107510c15177a6a0c4d6f22f41b81a48fb
|
|
7
|
+
data.tar.gz: b861719d552382ed4bd3a4fa1d12778b62266feb0ceabbba89d0f33865b9ea352ab892700ce5020318d293acb8fd89c7a67837924c649a567e0b855f0ef9d275
|
data/README.md
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
ActiveDynamic allows to dynamically add properties to your ActiveRecord models and
|
|
7
7
|
work with them as regular properties.
|
|
8
|
-
To see this in practice, check out the demo application available at [https://github.com/koss-lebedev/active_dynamic_demo](https://github.com/koss-lebedev/active_dynamic_demo)
|
|
8
|
+
To see this in practice, check out the demo application available at [https://github.com/koss-lebedev/active_dynamic_demo](https://github.com/koss-lebedev/active_dynamic_demo).
|
|
9
|
+
I also wrote [an article](https://medium.com/@koss_lebedev/how-to-dynamically-add-attributes-to-your-activerecord-models-e233b17ad695#.k66n002of) explaining how to use active_dynamic.
|
|
9
10
|
|
|
10
11
|
## Installation
|
|
11
12
|
|
|
@@ -25,8 +26,8 @@ Or install it yourself as:
|
|
|
25
26
|
|
|
26
27
|
## Usage
|
|
27
28
|
|
|
28
|
-
To make this gem work, first you need to
|
|
29
|
-
|
|
29
|
+
To make this gem work, first you need to add `has_dynamic_attributes` to the model that needs to have dynamic
|
|
30
|
+
attributes. For example, if you have `Profile` model:
|
|
30
31
|
|
|
31
32
|
```ruby
|
|
32
33
|
class Profile < ActiveRecord::Base
|
|
@@ -29,7 +29,7 @@ module ActiveDynamic
|
|
|
29
29
|
def generate_accessors(fields)
|
|
30
30
|
fields.each do |field|
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
add_presence_validator(field.name) if field.required?
|
|
33
33
|
|
|
34
34
|
define_singleton_method(field.name) do
|
|
35
35
|
_custom_fields[field.name]
|
|
@@ -42,6 +42,12 @@ module ActiveDynamic
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
def add_presence_validator(attribute)
|
|
46
|
+
self.singleton_class.instance_eval do
|
|
47
|
+
validates_presence_of(attribute)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
45
51
|
def _custom_fields
|
|
46
52
|
@_custom_fields ||= ActiveSupport::HashWithIndifferentAccess.new
|
|
47
53
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_dynamic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Constantine Lebedev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-02-
|
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|