plant 0.4.0 → 0.5.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/app/models/plant/content.rb +57 -17
- data/lib/plant/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: d767dab70ab52f596d2604b3e3b1a9ff2ed1d831
|
4
|
+
data.tar.gz: 17aa9c9bded036c02a9431f6196163d150137efc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1471762fe46fa15424003009d6845145b87a8a76321a3c21003a0e9dcf12508cb2fec685b4808aaeafb3cfa5682060d4409038b5fe1053639c25594b347491f0
|
7
|
+
data.tar.gz: c3da7fe7ba433d531ccc5b8deeeb402c29343c2a3028295d71ae22480355f92e5ec96b487115c220c6b05f3c4117c47267ac8df04de34422e87663257414836a
|
data/app/models/plant/content.rb
CHANGED
@@ -1,30 +1,70 @@
|
|
1
1
|
module Plant
|
2
2
|
# Model for content
|
3
3
|
class Content < ActiveRecord::Base
|
4
|
-
#
|
4
|
+
# Can only have one scenario-node_id combination
|
5
|
+
validates_uniqueness_of :node_id
|
6
|
+
|
7
|
+
# Gets a given node
|
5
8
|
# => Parameter: node ID (string)
|
6
|
-
# => Parameter:
|
7
|
-
#
|
8
|
-
#
|
9
|
+
# => Parameter: Options (hash), containing
|
10
|
+
# - scenario (optional)
|
11
|
+
# Can either be a string or an object with
|
12
|
+
# a scenario method, for example a user.
|
13
|
+
#
|
14
|
+
# If no specific scenario returned, then will
|
15
|
+
# default back to a nil scenario.
|
16
|
+
#
|
17
|
+
# => Throws: NotFound if node not found
|
18
|
+
# => Returns: A content object
|
19
|
+
def self.get_node(node_id, options = {})
|
20
|
+
options = defaults.merge(options)
|
21
|
+
find_specific(node_id, options[:scenario]) || find_main(node_id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.defaults
|
25
|
+
{ scenario: nil,
|
26
|
+
parameters: {} }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Convenience method to get the content of a given node
|
30
|
+
# => Paramter: node ID (string)
|
31
|
+
# => Paramter: Options (hash)
|
32
|
+
# - scenario
|
33
|
+
# Can either be a string or an object with
|
34
|
+
# a scenario method, for example a user
|
9
35
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
|
36
|
+
# - Also can be any arbitary key to be injected into the
|
37
|
+
# returned content. For example
|
38
|
+
# When called get_node_content(node_id, foo: 'hhh)
|
39
|
+
# "This is content for #{foo} and bar"
|
40
|
+
# will return 'This is content for hhh and bar'
|
41
|
+
#
|
42
|
+
# Note: If second parameter is a string, it will be treated as
|
43
|
+
# scenario.
|
44
|
+
# Also see: get_node
|
45
|
+
def self.get_node_content(node_id, options = {})
|
46
|
+
options = { scenario: options } unless options.is_a? Hash
|
47
|
+
options = defaults.merge(options)
|
48
|
+
inject_content(get_node(node_id, options).content, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Interpolation of content
|
52
|
+
def self.inject_content(content, options)
|
53
|
+
options.each do |key, replacement|
|
54
|
+
content.gsub!("\#\{#{key}\}", replacement.to_s)
|
55
|
+
end
|
56
|
+
content
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.find_specific(node, scenario)
|
15
60
|
scenario = scenario.scenario if scenario.respond_to? :scenario
|
16
|
-
|
17
|
-
return specific.content if specific
|
18
|
-
find_main(node)
|
61
|
+
find_by(node_id: "#{node}.#{scenario}")
|
19
62
|
end
|
20
63
|
|
21
64
|
def self.find_main(node)
|
22
65
|
main = find_by(node_id: "#{node}.main")
|
23
|
-
return main
|
24
|
-
find_by!(node_id: "#{node}")
|
66
|
+
return main if main
|
67
|
+
find_by!(node_id: "#{node}")
|
25
68
|
end
|
26
|
-
|
27
|
-
# Can only have one scenario-node_id combination
|
28
|
-
validates_uniqueness_of :node_id
|
29
69
|
end
|
30
70
|
end
|
data/lib/plant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yule
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|