cenit-collection-base 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1f93c2be1b4cac9749b4991327999454f061227
4
+ data.tar.gz: a0d71ef6129602ca80e74dc99e0d635b57e060a4
5
+ SHA512:
6
+ metadata.gz: 188df0cc5efcb469b8d61786ea69610022c147402e7e8e74777d0d0f4c19e5ea5764fd48b30d848606b5353449e4cb83fb76ed6a5344ad2ba4c5ac97734a39cb
7
+ data.tar.gz: c0e50f9f97349779e7be7ed14767c2aaa2b94e9cc29e9fc955dcf20991535644b440d165b4633dd449d92cefdbe1be5a0d7098873048221f6ca90a614b807ff8
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ .idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cenit-collection-base.gemspec
4
+ gemspec
5
+ gem 'json'
6
+ gem 'cenit-client'
7
+ gem 'activesupport'
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2015 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Cenit::Collection::Base
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cenit/collection/base`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cenit-collection-base'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cenit-collection-base
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/cenit-collection-base/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cenit/collection/base/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = %q{cenit-collection-base}
8
+ spec.version = Cenit::Collection::Base::VERSION
9
+ spec.authors = ["asnioby"]
10
+ spec.email = ["asnioby@gmail.com"]
11
+
12
+ spec.summary = %q{Cenit collection build class}
13
+ spec.description = %q{Base code to build Cenit Collection}
14
+ spec.homepage = "http://www.cenitsaas.com"
15
+
16
+ spec.rubyforge_project = "cenit-collection"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = 'bin'
20
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,9 @@
1
+ require "cenit/collection/base/version"
2
+
3
+ module Cenit
4
+ module Collection
5
+ module Base
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,128 @@
1
+ module Cenit
2
+ module Collection
3
+ module Base
4
+
5
+ require 'json'
6
+ require 'active_support/core_ext/hash/deep_merge'
7
+
8
+ class Build
9
+
10
+ attr_accessor :base_path
11
+ attr_accessor :collection_dep
12
+
13
+ def initialize (base_path)
14
+ @base_path = base_path
15
+ @collection_dep = []
16
+ end
17
+
18
+ def register_dep (dep)
19
+ @collection_dep << dep
20
+ end
21
+
22
+ def build_data
23
+ shared = {}
24
+ hash = {}
25
+ models = ['flows','connection_roles','translators','events','connections','webhooks']
26
+ models.collect do |model|
27
+ temp = []
28
+ hash.merge!({model => []})
29
+ @collection_dep.collect do |collection|
30
+ temp = collection.process_model(model)
31
+ hash.deep_merge!({model => temp}){ |_, val1, val2| array_sum(val1, val2) }
32
+ end
33
+ temp = process_model(model)
34
+ hash.deep_merge!({model => temp}){ |_, val1, val2| array_sum(val1, val2) }
35
+ end
36
+ shared.merge!(hash)
37
+ temp = []
38
+ hash = {'libraries' => []}
39
+ @collection_dep.collect do |collection|
40
+ temp = collection.process_libraries
41
+ hash.deep_merge!({'libraries' => temp}){ |_, val1, val2| array_sum(val1, val2) }
42
+ end
43
+ temp = process_libraries
44
+ hash.deep_merge!({'libraries' => temp}){ |_, val1, val2| array_sum(val1, val2) }
45
+ shared.merge!(hash)
46
+ {"data" => shared}
47
+ end
48
+
49
+ def shared_collection
50
+ shared = collection_base
51
+ shared.deep_merge!(build_data)
52
+ {"shared_collection" => shared}
53
+ end
54
+
55
+ protected
56
+
57
+ def process_model(model)
58
+ result = []
59
+ files = load_json_dir(model).to_a
60
+ files.collect do |file|
61
+ result << JSON.parse(open_json(file))
62
+ end
63
+ result
64
+ end
65
+
66
+ def process_libraries
67
+ results = []
68
+ lib_index = @base_path + '/libraries/index.json'
69
+ libraries = JSON.parse(open_json(lib_index)).to_a
70
+ libraries.collect do |lib|
71
+ schemas = []
72
+ files = load_library_dir(lib["file"]).to_a
73
+ files.collect do |file|
74
+ hash = {"uri" => File.basename(file),
75
+ "schema" => open_json(file).to_s,
76
+ "library" => {
77
+ "_reference" => true,
78
+ "name" => lib["name"]
79
+ }
80
+ }
81
+ schemas << hash
82
+ end
83
+ results << {"name" => lib["name"], "schemas" => schemas}
84
+ end
85
+ results
86
+ end
87
+
88
+ def collection_base
89
+ JSON.parse(open_head)
90
+ end
91
+
92
+ def sample_model(model)
93
+ JSON.parse(open_sample(model))
94
+ end
95
+
96
+ def open_json(file)
97
+ File.open(file, mode: "r:utf-8").read
98
+ rescue {}
99
+ end
100
+
101
+ def open_head
102
+ File.open(@base_path + '/index.json', mode: "r:utf-8").read
103
+ rescue {}
104
+ end
105
+
106
+ def open_sample(model)
107
+ File.open(@base_path + "/support/sample/#{model}.json", mode: "r:utf-8").read
108
+ rescue {}
109
+ end
110
+
111
+ def load_json_dir(model)
112
+ Dir.glob("#{@base_path}/#{model}/*.json")
113
+ rescue []
114
+ end
115
+
116
+ def load_library_dir(lib)
117
+ Dir.glob("#{@base_path}/libraries/#{lib}/*.json")
118
+ rescue []
119
+ end
120
+
121
+ def array_sum(val1, val2)
122
+ val1.is_a?(Array) && val2.is_a?(Array) ? (val1 + val2).uniq : val2
123
+ end
124
+
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,7 @@
1
+ module Cenit
2
+ module Collection
3
+ module Base
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cenit-collection-base
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - asnioby
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Base code to build Cenit Collection
42
+ email:
43
+ - asnioby@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - cenit-collection-base.gemspec
55
+ - lib/cenit/collection/base.rb
56
+ - lib/cenit/collection/base/build.rb
57
+ - lib/cenit/collection/base/version.rb
58
+ homepage: http://www.cenitsaas.com
59
+ licenses: []
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project: cenit-collection
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Cenit collection build class
81
+ test_files: []