active_dynamic 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10e9eb6462e773741bf5e044a2666194c71c4d5b
4
- data.tar.gz: 5a33fdec8c771396710b6f05dfe2d1280fb80739
3
+ metadata.gz: e209fa9cc3fc6975f796cdf16604f243035548b5
4
+ data.tar.gz: 6a86403d63d1839c8bbcee14e428c38d2e0a1065
5
5
  SHA512:
6
- metadata.gz: ffff1d181a7c1267537c96e565fd4db80935c087c1aef58569ece821befc0d2ac102fd374fc0ca409d243a91b50cead1de5d0737cd3fbd0c8213cb16ef953e7b
7
- data.tar.gz: 564b73bfcbd47e0a499e8ee3182a82fd8c421caa46bf0c710f480ea2367fef29e4adf21f15ed3aa2233432b696473221557a93e452ae2e9b58631e08fdc42a23
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 include `HasDynamicAttributes` concern to the model that needs to have dynamic
29
- attributses. For example, if you have `Profile` model:
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
- self.class.validates_presence_of(field.name) if field.required?
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
@@ -1,3 +1,3 @@
1
1
  module ActiveDynamic
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  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.1
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-10 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord