active_dynamic 0.3.0 → 0.4.0

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: 0e3a6c7d16108bd7a5689a0d8d125b01bc5cdce0
4
- data.tar.gz: a3db6ea5125ece2d63e5189f13246653e011d824
3
+ metadata.gz: 06893fd851d9cb515ef8301c30c90225e095d4b9
4
+ data.tar.gz: 176497655badfaac02c1fef76928d670f1709431
5
5
  SHA512:
6
- metadata.gz: d02e4a617c3bd878080bd2bd8a16d76c1a72b8ed3ad29c246878beeaf98a92fe9f7f9438b9d4f39276ebaf5b7af64e8c86391a52268083a43a83390f9130f122
7
- data.tar.gz: cb529e4b253ae05eb99811f75bb8ff99e3da13d10b126110be088aca6513fe7b138d1dfa5d3068cba3a7baaf72d6c9de48a9aafbcb2fcf975ec5c477f1b11ebf
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 DynamicAttributes::HasDynamicAttributes
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
 
@@ -4,6 +4,5 @@ module ActiveDynamic
4
4
 
5
5
  self.table_name = 'active_dynamic_attributes'
6
6
  validates :name, presence: true
7
- validates :datatype, presence: true, inclusion: DataType::All
8
7
  end
9
8
  end
@@ -1,4 +1,14 @@
1
1
  module ActiveDynamic
2
- class AttributeDefinition < Struct.new(:name, :datatype, :value)
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
@@ -6,7 +6,5 @@ module ActiveDynamic
6
6
  Decimal = 3
7
7
  Date = 4
8
8
  DateTime = 5
9
-
10
- All = [String, Text, Integer, Decimal]
11
9
  end
12
10
  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
- attr = self.active_dynamic_attributes.find_or_initialize_by(name: field.name, datatype: field.datatype)
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
@@ -1,3 +1,3 @@
1
1
  module ActiveDynamic
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
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.3.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-06 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord