spigit_conf 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: 804dc0d155bb8acc1c13632ee9de8abb9bb809e7
4
+ data.tar.gz: 378c431284fdad6b4f98d214c1c575376477defd
5
+ SHA512:
6
+ metadata.gz: 17908ca80f28e50522d5218e24e8e221a545a2b47469ac3956a2db87e61b5c36a6569d9ba2f32cdb744b0c62d9124c5906d47eb5d046f8ac6198282dd8ead64f
7
+ data.tar.gz: 2e5ecf89242ddfeefa24373f8c5e05d178a644c915b04ee01a45b4417f5ae51a23ebf52219b1333e77639c74d103f974e4edd4aedd6e2563457660ca9025338e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spigit_conf.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jason Barnett
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # SpigitConf
2
+
3
+ This gem was created in order to programatically modify our spigit-conf.xml and spigit-search-conf.xml configuration files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'spigit_conf'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install spigit_conf
20
+
21
+ ## Usage
22
+
23
+ require 'spigit_conf'
24
+
25
+ s = SpigitConf::Engage.new('/opt/webapps/customer/WEB-INF/spigit-conf.xml')
26
+ s.max_idle_browser_period # => "20"
27
+ s.max_idle_browser_period = 25 # => 25
28
+ s.save! # automatically backs up the config and saves updates in place.
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bundle` to install dependencies.
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/MindjetLLC/spigit_conf/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ require 'active_support/time'
3
+ $:.unshift(File.dirname(__FILE__) + "/../lib")
4
+ require 'spigit_conf'
5
+
6
+ root = File.expand_path(File.dirname(__FILE__))
7
+
8
+ configs = Dir.glob("#{root}/test/files/*.xml")
9
+
10
+ configs.each do |x|
11
+ s = SpigitConf::Engage.new(file: x)
12
+ s.max_idle_browser_period = 8.hours.to_i
13
+ s.save!(backup: false)
14
+ end
15
+
@@ -0,0 +1,38 @@
1
+ class Class
2
+ def spigit_attr(java_key, *methods)
3
+ java_key = java_key.to_s
4
+ name = methods.first.to_s
5
+
6
+ self.class_eval(%Q{
7
+ def #{name}
8
+ if node_exists?("#{java_key}")
9
+ node = get_node("#{java_key}")
10
+ node.text
11
+ end
12
+ end
13
+ })
14
+
15
+ self.class_eval(%Q{
16
+ def #{name}=(val)
17
+ if node_exists?("#{java_key}")
18
+ node = get_node("#{java_key}")
19
+ else
20
+ node = add_config("#{java_key}")
21
+ end
22
+
23
+ node.content = val
24
+ end
25
+ })
26
+
27
+ aliases = methods[1..-1]
28
+ aliases.each do |x|
29
+ x = x.to_s
30
+
31
+ self.class_eval(%Q{
32
+ alias_method :#{x}, :#{name}
33
+ alias_method :#{x}=, :#{name}=
34
+ })
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,151 @@
1
+ require 'nokogiri'
2
+ require 'fileutils'
3
+ require 'spigit_conf/options'
4
+ require 'spigit_conf/core/ext/class'
5
+
6
+ module SpigitConf
7
+ class Engage
8
+ spigit_attr :ACTIVITY_FEED_THROTTLE, :activity_feed_throttle
9
+ spigit_attr :ACTIVITY_STREAM_SCHEMA, :activity_stream_schema
10
+ spigit_attr :ACTIVITY_STREAM_SERVER_URL, :activity_stream_server_url
11
+ spigit_attr :BASE_DOMAIN, :base_domain
12
+ spigit_attr :BROKER_HOST, :broker_host
13
+ spigit_attr :BROKER_PORT, :broker_port
14
+ spigit_attr :COMPUTE_CATEGORY_REPUTATION, :compute_category_reputation
15
+ spigit_attr :COOKIE_DOMAIN, :cookie_domain
16
+ spigit_attr :DB_NAMES, :db_names
17
+ spigit_attr :DB_NAME_USER, :db_name_user
18
+ spigit_attr :DRAG_AND_DROP_ENABLED, :drag_and_drop_enabled
19
+ spigit_attr :FORM_ID_CHECKED, :form_id_checked
20
+ spigit_attr :GRID_BASED_THEME_ONLY, :grid_based_theme_only
21
+ spigit_attr :IDEAS_RECOMMENTORS, :ideas_recommentors
22
+ spigit_attr :IDEAS_RECOMMENTORS_WEIGHTS, :ideas_recommentors_weights
23
+ spigit_attr :JASPERSERVER_URL, :jasperserver_url
24
+ spigit_attr :JSP_SECTOR_THREADS_HOME, :jsp_sector_threads_home
25
+ spigit_attr :LABEL_EDASHBOARD, :label_edashboard
26
+ spigit_attr :LABEL_LEADERBOARD, :label_leaderboard
27
+ spigit_attr :MAX_IDLE_BROWSER_PERIOD, :max_idle_browser_period
28
+ spigit_attr :PARAM_INFO_MESSAGE, :param_info_message
29
+ spigit_attr :RECOMMENDED_IDEAS_WINDOW, :recommended_ideas_window
30
+ spigit_attr :RESOURCE_SERVER_URL, :resource_server_url
31
+ spigit_attr :SEARCH_HOST, :search_host
32
+ spigit_attr :SEARCH_SERVER_PORT, :search_server_port
33
+ spigit_attr :SECURITY_LEVEL, :security_level
34
+ spigit_attr :SITEMAP_FILE_PATH, :sitemap_file_path
35
+ spigit_attr :SITE_ID, :site_id
36
+ spigit_attr :SPIGIT_FROM_DISPLAY_NAME, :spigit_from_display_name
37
+ spigit_attr :SSO_REDIRECT_LOGIN_URL, :sso_redirect_login_url
38
+ spigit_attr :SSO_REDIRECT_REGISTER_URL, :sso_redirect_register_url
39
+ spigit_attr :TM_CONTENT_FIELD, :tm_content_field
40
+ spigit_attr :TM_NUMBER_TOPIC, :tm_number_topic
41
+ spigit_attr :URI_ADDUSER_PAGE, :uri_adduser_page
42
+ spigit_attr :URI_AGGREGATED_BLOGS_PAGE, :uri_aggregated_blogs_page
43
+ spigit_attr :URI_BLOG_MODERATE_PAGE, :uri_blog_moderate_page
44
+ spigit_attr :URI_COMMUNITY, :uri_community
45
+ spigit_attr :URI_DASHBOARD, :uri_dashboard
46
+ spigit_attr :URI_DASHBOARD, :uri_dashboard
47
+ spigit_attr :URI_EDITPROFILE, :uri_editprofile
48
+ spigit_attr :URI_HOMEPAGE, :uri_homepage
49
+ spigit_attr :URI_LEADERBOARD, :uri_leaderboard
50
+ spigit_attr :URI_MARKET_HOME, :uri_market_home
51
+ spigit_attr :URI_MOST_ACTIVE_MARKETS, :uri_most_active_markets
52
+ spigit_attr :URI_PAGE_POSTBLOGCOMMENT, :uri_page_postblogcomment
53
+ spigit_attr :URI_PAGE_POSTBLOGENTRY, :uri_page_postblogentry
54
+ spigit_attr :URI_PENDING_APPROVALS_ACTION, :uri_pending_approvals_action
55
+ spigit_attr :URI_POSTIDEA, :uri_postidea
56
+ spigit_attr :URI_POSTSECTOR, :uri_postsector
57
+ spigit_attr :URI_POST_MARKET_PAGE, :uri_post_market_page
58
+ spigit_attr :URI_PREDICATION_MARKET_HOME, :uri_predication_market_home
59
+ spigit_attr :URI_RECENT_MARKETS, :uri_recent_markets
60
+ spigit_attr :URI_REPORTS_HOME, :uri_reports_home
61
+ spigit_attr :URI_RESETUSER, :uri_resetuser
62
+ spigit_attr :URI_SEARCH, :uri_search
63
+ spigit_attr :URI_STORE, :uri_store
64
+ spigit_attr :URI_STORE_HOME_PAGE, :uri_store_home_page
65
+ spigit_attr :URI_TAG_SEARCH, :uri_tag_search
66
+ spigit_attr :URI_TRADE_SHARES_PAGE, :uri_trade_shares_page
67
+ spigit_attr :URI_VIEWBLOG, :uri_viewblog
68
+ spigit_attr :URI_VIEWBLOGENTRY, :uri_viewblogentry
69
+ spigit_attr :URI_VIEWIDEA, :uri_viewidea
70
+ spigit_attr :URI_VIEWIDEA_VERSION, :uri_viewidea_version
71
+ spigit_attr :URI_VIEWPROFILE, :uri_viewprofile
72
+ spigit_attr :URI_VIEWSECTOR, :uri_viewsector
73
+ spigit_attr :URI_VIEW_ALL_BLOGS_PAGE, :uri_view_all_blogs_page
74
+ spigit_attr :URI_VIEW_BLOGCOMMENT, :uri_view_blogcomment
75
+
76
+ attr_reader :doc, :file, :spigit_config
77
+
78
+ def initialize(opts = {})
79
+ @file = opts.fetch(:file)
80
+ @doc = Nokogiri::XML(File.read(@file)) { |x| x.noblanks }
81
+ @spigit_config = @doc.at_css('spigit-config')
82
+ end
83
+
84
+ def save!(opts = {})
85
+ backup = opts.fetch(:backup, true)
86
+ take_backup if backup
87
+
88
+ File.open(file, 'w') do |f|
89
+ f.write(doc.to_xml(save_with: SpigitConf::XML_SAVE_OPTIONS, :indent => 4, :encoding => 'UTF-8'))
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def take_backup
96
+ timestamp = Time.now.strftime('%Y%m%d-%H%M%Z')
97
+ backup_filename = [ file, timestamp].join('_')
98
+
99
+ ext = 0
100
+ while File.exists?(backup_filename)
101
+ backup_filename = [ file, timestamp, ext].join('_')
102
+ ext += 1
103
+ end
104
+
105
+ FileUtils.cp(file, backup_filename)
106
+ end
107
+
108
+ def add_config(key)
109
+ if node_exists?(key)
110
+ return get_node(key)
111
+ end
112
+
113
+ # Create the new node
114
+ node = Nokogiri::XML::Node.new(key, doc)
115
+
116
+ # Add the new node to the spigit-config namespace
117
+ spigit_config.add_child(node)
118
+
119
+ node
120
+ end
121
+
122
+ def get_node(key)
123
+ spigit_config.at_xpath("./#{key}")
124
+ end
125
+
126
+ def get_nodes(key)
127
+ spigit_config.xpath("./#{key}")
128
+ end
129
+
130
+ def node_exists?(key)
131
+ elements = get_nodes(key)
132
+
133
+ if elements.length == 0
134
+ return false
135
+ elsif elements.length == 1
136
+ return true
137
+ elsif element.length > 1
138
+ remove_nodes(elements[1..-1])
139
+ return true
140
+ else
141
+ return false
142
+ end
143
+ end
144
+
145
+ def remove_nodes(*nodes)
146
+ nodes.each do |node|
147
+ node.remove
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,7 @@
1
+ module SpigitConf
2
+ # Nokogiri::XML::Node::SaveOptions::FORMAT == 1
3
+ # Nokogiri::XML::Node::SaveOptions::NO_DECLARATION == 2
4
+ # Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS == 4
5
+ # Nokogiri::XML::Node::SaveOptions::AS_XML == 32
6
+ XML_SAVE_OPTIONS = 1 | 2 | 4 | 32
7
+ end
@@ -0,0 +1,3 @@
1
+ module SpigitConf
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "spigit_conf/version"
2
+ require "spigit_conf/engage"
3
+
4
+ module SpigitConf
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spigit_conf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spigit_conf"
8
+ spec.version = SpigitConf::VERSION
9
+ spec.authors = ["Jason Barnett"]
10
+ spec.email = ["jason.w.barnett@gmail.com"]
11
+
12
+ spec.summary = %q{Library for modifying spigit-conf.xml}
13
+ #spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/|^Guardfile}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "nokogiri", "~> 1.6.6.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.9"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "guard", "~> 2.12.5"
26
+ spec.add_development_dependency "guard-minitest", "~> 2.4.4"
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spigit_conf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jason Barnett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-03-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.12.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.4.4
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.4.4
83
+ description:
84
+ email:
85
+ - jason.w.barnett@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - examples/set_max_idle_browser_period.rb
97
+ - lib/spigit_conf.rb
98
+ - lib/spigit_conf/core/ext/class.rb
99
+ - lib/spigit_conf/engage.rb
100
+ - lib/spigit_conf/options.rb
101
+ - lib/spigit_conf/version.rb
102
+ - spigit_conf.gemspec
103
+ homepage:
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Library for modifying spigit-conf.xml
127
+ test_files: []