catalyst_automation 0.0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/catalyst_automation.rb +112 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0ea6c5b4764354727ef25234c155ffab56c7d0ff
|
4
|
+
data.tar.gz: c7ca1c125caa91395e1af45551ea6a8ee917ed5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d485c8b6061bf08d1b71befa49f9926e42a5b328144a9fe21472f3a58aa7d1b68f24911a9de3c3b0d90202a755e58a9b0b6de103cf5f8888940dde2e28b3c78
|
7
|
+
data.tar.gz: 56aa0367371f3c49870e50137c77c8730d4f5ae5fdc5488042be61d90563500283da8e33e88eee5a8a7f147d7389c78422d8dee4fd0ca30da50e163466d5c1ad
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'mongo'
|
2
|
+
require 'json'
|
3
|
+
require 'bson'
|
4
|
+
require 'site_prism'
|
5
|
+
|
6
|
+
|
7
|
+
module CatalystAutomation
|
8
|
+
|
9
|
+
class WithJson
|
10
|
+
|
11
|
+
def self.initialize(pages)
|
12
|
+
pages_json = JSON.parse(pages, sections)
|
13
|
+
sections_json = JSON.parse(sections)
|
14
|
+
Base.create_pages(pages_json, sections_json)
|
15
|
+
Base.create_sections(sections_json)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class WithDataBase
|
21
|
+
|
22
|
+
def self.initialize(conn_str)
|
23
|
+
Base.connect_db(conn_str) do |db|
|
24
|
+
db_pages = Base.get_db_info(db, :pages)
|
25
|
+
db_sections = Base.get_db_info(db, :sections)
|
26
|
+
Base.create_pages(db_pages, db_sections)
|
27
|
+
Base.create_sections(db_sections)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class Base
|
34
|
+
|
35
|
+
def self.create_const(const_name, key, const_type)
|
36
|
+
Object.const_set(const_name[(const_name.class.eql?(Symbol) ? key : key.to_s)], const_type)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.set_elements(const_name, key)
|
40
|
+
Object.const_get(const_name[(const_name.kind_of?(Symbol) ? key : key.to_s)]).class_eval do
|
41
|
+
const_name[(const_name.kind_of?(Symbol) ? :elements : "elements" )].each do |element|
|
42
|
+
send(:element, element[(const_name.kind_of?(Symbol) ? :name : "name")], element[(const_name.kind_of?(Symbol) ? :path : "path")])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.set_sections(const_name, key, db_sections)
|
48
|
+
Object.const_get(const_name[(const_name.kind_of?(Symbol) ? :name : "name")]).class_eval do
|
49
|
+
const_name[(const_name.kind_of?(Symbol) ? :page_sections : "page_sections")].each do |section|
|
50
|
+
m_class_name = ""
|
51
|
+
db_sections.each do |db_section|
|
52
|
+
if section[:section_id].to_s.eql?(db_section[:_id].to_s)
|
53
|
+
m_class_name = db_section[const_name.kind_of?(Symbol) ? :name : "name"]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
send(:section, section[(const_name.kind_of?(Symbol) ? :name : "name")], Object.const_get(m_class_name), section[(const_name.kind_of?(Symbol) ? :path : "path")])
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.connect_db(conn_str)
|
62
|
+
db_conn = Mongo::Client.new(conn_str)
|
63
|
+
begin
|
64
|
+
yield db_conn
|
65
|
+
rescue => error
|
66
|
+
raise error
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_db_info(db_con, info)
|
71
|
+
m_info = []
|
72
|
+
db_info = db_con.database[info].find()
|
73
|
+
db_info.each_entry do |entry|
|
74
|
+
m_info << entry
|
75
|
+
end
|
76
|
+
return m_info
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.create_sections(db_pages)
|
80
|
+
db_pages.each do |section|
|
81
|
+
create_const(section, :name, Class.new(SitePrism::Section))
|
82
|
+
set_elements(section, :name)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.connect_db(conn_str)
|
87
|
+
db_conn = Mongo::Client.new(conn_str)
|
88
|
+
begin
|
89
|
+
yield db_conn
|
90
|
+
rescue => error
|
91
|
+
raise error
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.get_db_info(db_con, info)
|
96
|
+
m_info = []
|
97
|
+
db_info = db_con.database[info].find()
|
98
|
+
db_info.each_entry do |entry|
|
99
|
+
m_info << entry
|
100
|
+
end
|
101
|
+
return m_info
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.create_sections(db_pages)
|
105
|
+
db_pages.each do |section|
|
106
|
+
create_const(section, :name, Class.new(SitePrism::Section))
|
107
|
+
set_elements(section, :name)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: catalyst_automation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Broersma
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem
|
14
|
+
email: catalystautomation@mailinator.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/catalyst_automation.rb
|
20
|
+
homepage: http://rubygems.org/gems/catalyst_automation
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Catalyst Automation
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|