contents_core 0.3.0 → 0.3.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 +1 -1
- data/app/models/contents_core/item.rb +3 -2
- data/app/models/contents_core/item_array.rb +2 -6
- data/app/models/contents_core/item_boolean.rb +6 -2
- data/app/models/contents_core/item_float.rb +0 -4
- data/app/models/contents_core/item_hash.rb +10 -4
- data/app/models/contents_core/item_integer.rb +0 -4
- data/app/models/contents_core/item_object.rb +1 -1
- data/lib/contents_core/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: 01e850b0c0c4fbacf54ecb2f9c847b8f80d4ad9b
|
4
|
+
data.tar.gz: a9652d2e234c5c5dee333820f78138bfd422af8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6d7bc017c8b50fba54fa390a3e44c9b02065f900cd276f9f84e683c44cc2f8036de77dc9710242ecb06f63d57d861d97283b4275f49331820a6b3f8cec59751
|
7
|
+
data.tar.gz: 6e827ac0122c0b3edb0d23ca73549c86f6cad69d318f650f1d1db10e42f15412cc4f30553d60c1c6b1db7d66089c0ede4e4410bd20c496ab4740d1779ce66f50
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ContentsCore [](https://badge.fury.io/rb/contents_core) [](https://travis-ci.org/blocknotes/contents_core)
|
1
|
+
# ContentsCore [](https://badge.fury.io/rb/contents_core) [](https://travis-ci.org/blocknotes/contents_core) [](https://gemnasium.com/github.com/blocknotes/contents_core) [](https://codeclimate.com/github/blocknotes/contents_core/test_coverage)
|
2
2
|
|
3
3
|
A Rails gem which offer a structure to manage contents in a flexible way: blocks with recursive nested blocks + items as "leaves"
|
4
4
|
|
@@ -14,6 +14,7 @@ module ContentsCore
|
|
14
14
|
# --- validations ---------------------------------------------------------
|
15
15
|
validate :validate_item
|
16
16
|
validates :block, presence: true, allow_blank: false
|
17
|
+
validates :type, presence: true, allow_blank: false
|
17
18
|
|
18
19
|
# --- methods -------------------------------------------------------------
|
19
20
|
def on_after_initialize
|
@@ -85,7 +86,7 @@ module ContentsCore
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def to_s
|
88
|
-
self.data
|
89
|
+
self.data.to_s
|
89
90
|
end
|
90
91
|
|
91
92
|
def update_data( value )
|
@@ -98,7 +99,7 @@ module ContentsCore
|
|
98
99
|
end
|
99
100
|
|
100
101
|
def self.permitted_attributes
|
101
|
-
[
|
102
|
+
[:data_boolean, :data_datetime, :data_file, :data_float, :data_hash, :data_integer, :data_string, :data_text]
|
102
103
|
end
|
103
104
|
|
104
105
|
def self.type_name
|
@@ -16,12 +16,12 @@ module ContentsCore
|
|
16
16
|
if data_type
|
17
17
|
self.data_text = case data_type
|
18
18
|
# when :boolean
|
19
|
-
# self.data_boolean = ( value == 1 ) || ( value == '1' ) || ( value == 'true' ) || ( value == 'yes' )
|
19
|
+
# self.data_boolean = value # ( value == 1 ) || ( value == '1' ) || ( value == 'true' ) || ( value == 'yes' )
|
20
20
|
when :float
|
21
21
|
value.map( &:to_f )
|
22
22
|
when :integer
|
23
23
|
value.map( &:to_i )
|
24
|
-
when :string, :text
|
24
|
+
when :string # , :text
|
25
25
|
value.map( &:to_s )
|
26
26
|
else
|
27
27
|
value
|
@@ -55,10 +55,6 @@ module ContentsCore
|
|
55
55
|
config[:multiple] ? true : false
|
56
56
|
end
|
57
57
|
|
58
|
-
def to_s
|
59
|
-
self.data
|
60
|
-
end
|
61
|
-
|
62
58
|
def self.type_name
|
63
59
|
'array'
|
64
60
|
end
|
@@ -7,13 +7,17 @@ module ContentsCore
|
|
7
7
|
self
|
8
8
|
end
|
9
9
|
|
10
|
+
def from_string( value )
|
11
|
+
self.data = ( value == 1 ) || ( value == '1' ) || ( value == 'true' ) || ( value == 'yes' )
|
12
|
+
end
|
13
|
+
|
10
14
|
def update_data( value )
|
11
|
-
self.data =
|
15
|
+
self.data = value
|
12
16
|
self.save
|
13
17
|
end
|
14
18
|
|
15
19
|
def to_s
|
16
|
-
self.
|
20
|
+
self.data_boolean ? 'true' : 'false'
|
17
21
|
end
|
18
22
|
|
19
23
|
def self.permitted_attributes
|
@@ -20,13 +20,19 @@ module ContentsCore
|
|
20
20
|
m = line.match( /([^:]*):(.*)/ )
|
21
21
|
val[m[1]] = m[2].strip if m && !m[1].blank?
|
22
22
|
end
|
23
|
-
self.data_hash = val
|
23
|
+
self.data_hash = val.symbolize_keys
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def method_missing( method, *args, &block )
|
28
|
-
matches = /data_(
|
29
|
-
|
28
|
+
matches = /data_([^=]+)([=]{0,1})/.match method.to_s
|
29
|
+
if matches
|
30
|
+
if matches[2].blank?
|
31
|
+
return self.data[matches[1].to_sym]
|
32
|
+
elsif matches[1]
|
33
|
+
self.data[matches[1].to_sym] = args[0]
|
34
|
+
end
|
35
|
+
end
|
30
36
|
end
|
31
37
|
|
32
38
|
def respond_to?( method, include_private = false )
|
@@ -34,7 +40,7 @@ module ContentsCore
|
|
34
40
|
end
|
35
41
|
|
36
42
|
def to_s
|
37
|
-
self.data_hash ? self.data_hash.inject( '' ) { |k, v| k
|
43
|
+
self.data_hash ? self.data_hash.inject( '' ) { |k, v| "#{k}#{v[0]}: #{v[1]}\n" } : {}
|
38
44
|
end
|
39
45
|
|
40
46
|
def self.permitted_attributes
|
@@ -28,7 +28,7 @@ module ContentsCore
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def to_s
|
31
|
-
self.data_hash ? self.data_hash.inject( '' ) { |k, v| k
|
31
|
+
self.data_hash ? self.data_hash.inject( '' ) { |k, v| "#{k}#{v[0]}: #{v[1]}\n" } : {}
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.permitted_attributes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contents_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|