active_dynamic 0.3.0 → 0.4.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 +3 -3
- data/lib/active_dynamic/attribute.rb +0 -1
- data/lib/active_dynamic/attribute_definition.rb +11 -1
- data/lib/active_dynamic/data_type.rb +0 -2
- data/lib/active_dynamic/has_dynamic_attributes.rb +4 -2
- data/lib/active_dynamic/migration.rb +1 -0
- 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: 06893fd851d9cb515ef8301c30c90225e095d4b9
|
4
|
+
data.tar.gz: 176497655badfaac02c1fef76928d670f1709431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f15edb3f106ced0263bed6ca0d02c547a58d4e63f07fb5abdcf03913f0744e87f335fec9544055834f91e03fb3064a78409f63404ff28a61cc74f88d63985a05
|
7
|
+
data.tar.gz: 5fd59c3c82d8585dc7a1c176e3524f8379d83e1475129710a434e18bf2921dce2a97a4f8d72dc375c18ae9494bdd292a4a70c8fca85e6337cb25ba843a4bce8e
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ attributses. For example, if you have `Profile` model:
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
class Profile < ActiveRecord::Base
|
33
|
-
include
|
33
|
+
include ActiveDynamic::HasDynamicAttributes
|
34
34
|
|
35
35
|
# ...
|
36
36
|
end
|
@@ -57,8 +57,8 @@ class ProfileAttributeProvider
|
|
57
57
|
def call
|
58
58
|
[
|
59
59
|
# attribute definition has to specify attribute name, datatype, and optionally default value
|
60
|
-
ActiveDynamic::AttributeDefinition.new('age', ActiveDynamic::DataType::Integer, 18),
|
61
|
-
ActiveDynamic::AttributeDefinition.new('biography', ActiveDynamic::DataType::Text)
|
60
|
+
ActiveDynamic::AttributeDefinition.new('age', datatype: ActiveDynamic::DataType::Integer, default_value: 18),
|
61
|
+
ActiveDynamic::AttributeDefinition.new('biography', datatype: ActiveDynamic::DataType::Text)
|
62
62
|
]
|
63
63
|
end
|
64
64
|
|
@@ -1,4 +1,14 @@
|
|
1
1
|
module ActiveDynamic
|
2
|
-
class AttributeDefinition
|
2
|
+
class AttributeDefinition
|
3
|
+
|
4
|
+
attr_reader :display_name, :name, :datatype, :value
|
5
|
+
|
6
|
+
def initialize(display_name, options = {})
|
7
|
+
@display_name = display_name
|
8
|
+
@name = options[:system_name] || display_name.gsub(/[^a-zA-Z\s]/, ''.freeze).gsub(/\s+/, '_'.freeze)
|
9
|
+
@datatype = options[:datatype]
|
10
|
+
@value = options[:default_value]
|
11
|
+
end
|
12
|
+
|
3
13
|
end
|
4
14
|
end
|
@@ -13,7 +13,7 @@ module ActiveDynamic
|
|
13
13
|
if persisted?
|
14
14
|
active_dynamic_attributes.order(:created_at)
|
15
15
|
else
|
16
|
-
ActiveDynamic.configuration.provider_class.new(self).call
|
16
|
+
ActiveDynamic.configuration.provider_class.new(self.class).call
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -54,7 +54,9 @@ module ActiveDynamic
|
|
54
54
|
|
55
55
|
def save_dynamic_attributes
|
56
56
|
dynamic_attributes.each do |field|
|
57
|
-
|
57
|
+
props = { name: field.name, display_name: field.display_name,
|
58
|
+
datatype: field.datatype, value: field.value }
|
59
|
+
attr = self.active_dynamic_attributes.find_or_initialize_by(props)
|
58
60
|
if _custom_fields[field.name]
|
59
61
|
if self.persisted?
|
60
62
|
attr.update(value: _custom_fields[field.name])
|
@@ -5,6 +5,7 @@ class CreateActiveDynamicAttributesTable < ActiveRecord::Migration[4.2]
|
|
5
5
|
t.integer :customizable_id, null: false
|
6
6
|
t.string :customizable_type, limit: 50
|
7
7
|
|
8
|
+
t.string :display_name, null: false
|
8
9
|
t.string :name, null: false
|
9
10
|
t.text :value
|
10
11
|
t.integer :datatype, null: false
|
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.
|
4
|
+
version: 0.4.0
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|