defaulty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7bd0e7fcb292b3ccbed2841b58d79cfcb3f5f421
4
+ data.tar.gz: ebbd47477cd755673e54f295586ad87c40ae801d
5
+ SHA512:
6
+ metadata.gz: f3f95406b3075850b66351162af9917894ca642cf88829d1450d9f13e9cb517e33166153da897e5cdf93d2e65da3cc8939578ec3d48488aabf3ddb57aaf86ef9
7
+ data.tar.gz: 3d1de3f5b0a94deb36a6f27c16924b054bbf3ce398ab6d8796ecbe2a8ddb49554329be5ad3e58411c67762febad127af0c0ea6deb8ebab945a160dab86385161
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in defaulty.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
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.
@@ -0,0 +1,41 @@
1
+ # Defaulty
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/defaulty`. 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 'defaulty'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install defaulty
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 `rake spec` to run the tests. You can also 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`, which will 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
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/defaulty. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "defaulty"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
12
+
13
+ #require "irb"
14
+ #IRB.start
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'defaulty'
5
+ require 'stringio_equals'
6
+
7
+ require 'hashdiff'
8
+ require 'pp'
9
+
10
+ def defaults(domain)
11
+ defaults = Defaulty::defaults(domain)
12
+ pp defaults
13
+ end
14
+
15
+ defaults(ARGV[0])
16
+
17
+
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'defaulty'
5
+ require 'stringio_equals'
6
+
7
+ require 'hashdiff'
8
+ require 'pp'
9
+
10
+ def diff
11
+ puts "Capturing all defaults..."
12
+ before = Defaulty::all_defaults
13
+ puts "Done."
14
+
15
+ puts "Make a change somewhere and then come back here and press <ENTER>"
16
+ STDIN.getc
17
+
18
+ puts "Capturing all defaults again..."
19
+ after = Defaulty::all_defaults
20
+ puts "Done."
21
+
22
+ diffs = HashDiff.diff(before, after)
23
+ end
24
+
25
+
26
+ differences = diff
27
+
28
+ pp differences
29
+ puts "Number of diffs: #{differences.size}"
30
+
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'defaulty/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "defaulty"
8
+ spec.version = Defaulty::VERSION
9
+ spec.authors = ["Jon-Erling Dahl", "Niclas Nilsson"]
10
+ spec.email = ["jon-erling@fooheads.com", "niclas@fooheads.com"]
11
+
12
+ spec.summary = %q{OS X defaults handler}
13
+ spec.homepage = "https://github.com/fooheads/defaulty"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "plist", "~> 3.1"
30
+ spec.add_dependency "hashdiff"
31
+ spec.add_dependency "git"
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.10"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec"
36
+ spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "dp"
38
+ end
@@ -0,0 +1,132 @@
1
+ require "defaulty/version"
2
+ require 'plist'
3
+ require 'open-uri'
4
+ require 'json'
5
+ require 'yaml'
6
+
7
+ require 'open-uri'
8
+ require 'uri'
9
+
10
+ # From: http://stackoverflow.com/questions/7578898/is-there-a-unified-way-to-get-content-at-a-file-or-http-uri-scheme-in-ruby
11
+ module URI
12
+ class File < Generic
13
+ def open(*args, &block)
14
+ ::File.open(self.path, &block)
15
+ end
16
+ end
17
+
18
+ @@schemes['FILE'] = File
19
+ end
20
+
21
+
22
+ class Defaulty
23
+ class Domain
24
+ attr_reader :name, :properties
25
+
26
+ def initialize(h)
27
+ raise "Domain needs to be initialized with a hash containing one key, the domain name" unless h.size == 1
28
+
29
+ @name, data = h.first
30
+ properties = data.delete('keys').map { |key, data| Property.new(key, data) }
31
+ @properties = Hash[ properties.map { |property| [property.name, property] } ]
32
+ end
33
+ end
34
+
35
+ class Property
36
+ attr_reader :name, :summary, :type
37
+
38
+ def initialize(key, data)
39
+ @name = key
40
+ @summary = data['summary']
41
+ @type = data['type']
42
+ # TODO: add more properties
43
+ end
44
+ end
45
+
46
+ def self.load(*urls)
47
+ defs = urls.map do |url|
48
+ if github_index_url?(url)
49
+ load_ymls_from_github(url)
50
+ else
51
+ load_ymls_from_path(url)
52
+ end
53
+ end
54
+
55
+ Defaulty.new(defs.flatten)
56
+ end
57
+
58
+
59
+ def self.domains
60
+ `defaults domains`.split(",").map { |domain| domain.strip }
61
+ end
62
+
63
+ def self.defaults(domain)
64
+ Plist::parse_xml `defaults export #{domain} -`
65
+ rescue
66
+ puts "failed to parse #{domain}"
67
+ []
68
+ end
69
+
70
+ def self.all_defaults
71
+ all_domains = domains + ['NSGlobalDomain']
72
+ selected_domains = all_domains
73
+ pairs = selected_domains.map do |domain|
74
+ [domain, defaults(domain)]
75
+ end
76
+ Hash[pairs]
77
+ end
78
+
79
+ def write(app, options)
80
+ domain = @domains[app]
81
+ raise "Can't find domain for '#{app}'" unless domain
82
+ options.each do |key, value|
83
+ key = key.to_s
84
+ property = domain.properties[key]
85
+ raise "Can't find a property '#{key}' in domain '#{domain.name}'" unless property
86
+ cmd = "defaults write #{domain.name} #{property.name} -#{property.type} #{value}"
87
+ puts cmd
88
+ `#{cmd}`
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ def self.github_index_url?(url)
95
+ url =~ %r(^https://api.github.com/repos/.*/contents/?$)
96
+ end
97
+
98
+ def self.yml_url?(url)
99
+ url =~ /\.yml$/
100
+ end
101
+
102
+ def self.load_ymls_from_github(contents_url)
103
+ begin
104
+ contents = JSON.parse(open(contents_url, :http_basic_authentication=>[ENV['GITHUB_USERNAME'], ENV['BOXY_GITHUB_API_TOKEN']]).read)
105
+ yml_contents = contents.select { |f| yml_url?(f['name']) }
106
+ yml_contents.map { |yml| load_yml(yml['download_url']) }
107
+ rescue => e
108
+ puts "Problem loading content from github: #{contents_url}"
109
+ puts e.inspect
110
+ puts e.io.read
111
+ puts "Exiting..."
112
+ exit
113
+ end
114
+ end
115
+
116
+ def self.load_ymls_from_path(contents_url)
117
+ yml_files = Dir.glob("#{contents_url}/**/*.yml")
118
+ yml_files.map { |yml_file| load_yml(yml_file) }
119
+ end
120
+
121
+ def self.load_yml(url)
122
+ YAML.load(open(url).read)
123
+ end
124
+
125
+ def initialize(defs)
126
+ domains = defs.map { |d| Domain.new(d) }
127
+ @domains = Hash[ domains.map { |domain| [domain.name, domain] } ]
128
+ end
129
+
130
+ end
131
+
132
+
@@ -0,0 +1,3 @@
1
+ class Defaulty
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Needed in order to make diff work for StringIO objects
3
+ #
4
+ class StringIO
5
+ def ==(o)
6
+ self.read == o.read
7
+ end
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: defaulty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jon-Erling Dahl
8
+ - Niclas Nilsson
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: plist
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '3.1'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: hashdiff
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: git
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '1.10'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.10'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: pry
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: dp
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description:
127
+ email:
128
+ - jon-erling@fooheads.com
129
+ - niclas@fooheads.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .rspec
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/defaults
143
+ - bin/differ
144
+ - bin/setup
145
+ - defaulty.gemspec
146
+ - lib/defaulty.rb
147
+ - lib/defaulty/version.rb
148
+ - lib/stringio_equals.rb
149
+ homepage: https://github.com/fooheads/defaulty
150
+ licenses:
151
+ - MIT
152
+ metadata:
153
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.0.14
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: OS X defaults handler
174
+ test_files: []