elm_history_tools 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a30716f0cdb540ad8228ec16e82e2e42d1a000f
4
+ data.tar.gz: 3163afcb272e617cce11a7c4afdfea92db1d801d
5
+ SHA512:
6
+ metadata.gz: d34ce51ff0aa23cbc2dae2d6dbd5ee5a7cd568e02cd222a43cdf93e049998c5015d1d2be3f3af68ba12701d4b0c7bbc3f0e4a4c6225e60613b36dc83680bed7e
7
+ data.tar.gz: b1d356d39c1434c69b5520006bd1be06c39efde94ee8ff0096d008f2334371ef683d6cb9d18817a84eef0aa63af69b32dc10cce668768c62da06f92564a42679
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .DS_Store
11
+ .byebug_history
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alex@alexkoppel.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in elm_history_tools.gemspec
6
+ gemspec
7
+
8
+ group :development do
9
+ gem "byebug"
10
+ end
11
+
12
+ group :test do
13
+ gem "rspec"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ elm_history_tools (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ awesome_print (1.8.0)
10
+ byebug (10.0.2)
11
+ diff-lcs (1.3)
12
+ rake (10.5.0)
13
+ rspec (3.7.0)
14
+ rspec-core (~> 3.7.0)
15
+ rspec-expectations (~> 3.7.0)
16
+ rspec-mocks (~> 3.7.0)
17
+ rspec-core (3.7.1)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-expectations (3.7.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-mocks (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-support (3.7.1)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ awesome_print
32
+ bundler (~> 1.16)
33
+ byebug
34
+ elm_history_tools!
35
+ rake (~> 10.0)
36
+ rspec
37
+
38
+ BUNDLED WITH
39
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Alex Koppel
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,182 @@
1
+ # ElmHistoryTools
2
+
3
+ One of the great aspects of the Elm programming language is its debugger. Because all the possible states of an Elm program are clearly defined and state only changes in response to messages, Elm can track everything that happens -- and make it available to you to debug both.
4
+
5
+ You can also export this history to a file, allowing your support team and developers to debug a user's session without having to be in the same room. Using a package like [ElmRings](https://github.com/arsduo/elm-rings/), you can even capture this data automatically and upload it to your servers for later use.
6
+
7
+ Of course, once you have that data on your servers, you'll have to work through two challenges:
8
+
9
+ 1. **Security**: every keystroke of a user’s password and all the sensitive personal information they enter in your app go into Elm’s history. It’s no good hashing passwords on the user model if another table contains them in plain text — you need to sanitize and secure this data carefully if you store it.
10
+ 2. **Complicated data structure**: the Elm history data is meant to be imported into Elm more than it's meant to be analyzed by humans. If you want to show your support team what happened in a user session in which an error occurred, you need to make that data presentable.
11
+
12
+ If you, like me, have these problems, you're in the right place.
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'elm_history_tools'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install elm_history_tools
29
+
30
+
31
+ ## Usage
32
+
33
+ Right now, ElmHistoryTools comes with two utilities:
34
+
35
+ _Sanitizing History_
36
+
37
+ **Be careful you don't accidentally expose critical user information** -- it's no good hashing passwords on the user model if an Elm history table contains them in plain text. Before storing
38
+
39
+ How do you actually do this?
40
+
41
+ COMING SOON
42
+
43
+ _Format a History into a Hash_
44
+
45
+ One approach we've found useful for user issues at eSpark Learning has been to skim the
46
+ history and see if anything looks amiss. Eyeballing the user's actions shows if a student get an unhappy response back from a
47
+ server, if they were able to they answer any quiz questions, etc., providing a useful context for
48
+ further debugging.
49
+
50
+ In order to make sense of data, it has to be presented in a comprehensible format. That's what the
51
+ `ElmHistoryTools::HistoryFormatter` object can do:
52
+
53
+ ```ruby
54
+ # given a JSON history file like
55
+ # {"history": [{"ctor": "MessageType", "_0": "Arg1", "_02": {"ctor": "AnotherType"}}, {"ctor":"AnotherMessageType", "_0": "AnotherArg"}]}
56
+
57
+ ElmHistoryTools::HistoryFormatter.to_simple_hash(JSON.parse(history_json))
58
+
59
+ # will produce
60
+
61
+ [
62
+ {"MessageType" => ["Arg1", {"AnotherType" => []}],
63
+ {"AnotherMessageType" => ["AnotherArg"]}
64
+ ]
65
+ ```
66
+
67
+ You can then easily loop over this data in Ruby to present a readable internal dashboard:
68
+
69
+ <img width="954" alt="elm-history-dashboard" src="https://user-images.githubusercontent.com/48325/39089476-5ae84a92-458d-11e8-9039-489886d17b0b.png">
70
+
71
+
72
+ ## Elm History Export Format
73
+
74
+ The Elm 0.18.0 history export is structured as followed:
75
+
76
+ ```js
77
+ {
78
+ "metadata": {
79
+ "versions": {"elm": "0.18.0"},
80
+ "types": {
81
+ // the Message type used by your program
82
+ "message": "Message.Message",
83
+ // all the type aliases defined in your program
84
+ "aliases": {
85
+ "Json.Decode.Value": {"args":[],"type":"Json.Encode.Value"},
86
+ // etc.
87
+ },
88
+ // all the union types used in your program
89
+ "unions": {
90
+ "Maybe.Maybe": {
91
+ // what arguments the union type takes
92
+ "args": ["a"],
93
+ // what tags/constructors make up that union type and what arguments they take
94
+ "tags":{
95
+ "Just": ["a"],
96
+ "Nothing": []
97
+ }
98
+ }
99
+ }
100
+ }
101
+ }
102
+ // what's happened in user session being exported
103
+ "history": [
104
+ // each entry is stored with the contructor and any ordered arguments passed to it
105
+ {"ctor": "MessageType", "_0": "Arg1", "_02": {"ctor": "AnotherType"}},
106
+ {"ctor": "AnotherMessageType", "_0": "AnotherArg"},
107
+ // etc.
108
+ ]
109
+ }
110
+ ```
111
+
112
+ Each entry in the history hash represents an Elm message object -- so
113
+
114
+ ```js
115
+ {"ctor": "MessageType", "_0": "Arg1", "_02": {"ctor": "AnotherType"}},
116
+ ```
117
+
118
+ represents the Elm message
119
+
120
+ ```elm
121
+ -- if type alias SomeType = AnotherType | SomethingElse
122
+ --
123
+ -- MessageType String SomeType
124
+ MessageType "Arg1" AnotherType
125
+ ```
126
+
127
+ A few notes:
128
+
129
+ **Lists**
130
+
131
+ List entries are recursively nested objects whose constructor is `::` (cons).
132
+
133
+ As an example, an Elm list of three books (`[{title = "Too Like the Lightning"}, {title = "The Fear of Barbarians"}, {title = "Evicted"}]`) would be represented as:
134
+
135
+ ```js
136
+ {
137
+ "ctor": "::",
138
+ "_0": {"title": "Too Like the Lightning"},
139
+ "_1": {
140
+ "ctor": "::",
141
+ "_0": {"title": "The Fear of Barbarians"},
142
+ "_1": {
143
+ "ctor": "::",
144
+ "_0": {"title": "Evicted"}
145
+ }
146
+ }
147
+ }
148
+ ```
149
+
150
+ This is because in Elm, `List` is implemented as a linked list (each element is an object that both stores its value and points to the next element in the list, rather than sitting in an array of plain values).
151
+
152
+ You don't need to know anything about linked lists to use Elm (or Javascript or Ruby or, likely, whatever you're using for work or fun -- I've literally never used them in my career), but if you're curious, you can read more about them [on Wikipedia](https://en.wikipedia.org/wiki/Linked_list). You can also check out [this interesting discussion](https://github.com/elm-lang/elm-plans/issues/13) of Arrays vs. Lists in Elm.
153
+
154
+ **In the future**
155
+
156
+ It looks like the terms will change somewhat in a future version of Elm: `"ctor"` and `"_01"`, `"_02"`, etc. will be [replaced with `$`, `a`, `b`, etc](https://github.com/elm-lang/virtual-dom/commit/61cf2090ecb745542532dd7ea87de37c6ed6c3b4#diff-25d902c24283ab8cfbac54dfa101ad31). ElmHistoryTools will support both formats in the future; should the structure change, obviously that will be addressed too.
157
+
158
+ **Why hashes?**
159
+
160
+ Why hashes?, you might wonder. Why not use arrays (e.g. `{"MessageType": ["Arg1", {"AnotherType": []}]}` or `["MessageType", "Arg1", ["AnotherType"]]`)? Wouldn't that be simpler?
161
+
162
+ Turns out you're not the first person to wonder about it. As @evancz [wrote in response to a similar question in 2015](https://groups.google.com/d/msg/elm-dev/pr4d8jUKz9c/bYejb7JOCgAJ):
163
+
164
+ > I believe in the olden times, I did use an array because I just assumed it'd be fast. I later ran some benchmarks and was totally wrong, objects were a lot faster. So I switched everything.
165
+
166
+ ## Development
167
+
168
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
169
+
170
+ 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).
171
+
172
+ ## Contributing
173
+
174
+ Bug reports and pull requests are welcome on GitHub at https://github.com/arsduo/elm_history_tools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
175
+
176
+ ## License
177
+
178
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
179
+
180
+ ## Code of Conduct
181
+
182
+ Everyone interacting in the ElmHistoryTools project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [Code of Conduct](https://github.com/arsduo/elm_history_tools/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "elm_history_tools"
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(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "elm_history_tools/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elm_history_tools"
8
+ spec.version = ElmHistoryTools::VERSION
9
+ spec.authors = ["Alex Koppel"]
10
+ spec.email = ["alex@alexkoppel.com"]
11
+
12
+ spec.summary = %q{Tools to work with Elm history exports.}
13
+ spec.homepage = "http://github.com/arsduo/elm-history-tools"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.16"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,6 @@
1
+ require "elm_history_tools/version"
2
+ require "elm_history_tools/history_formatter"
3
+
4
+ module ElmHistoryTools
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,42 @@
1
+ module ElmHistoryTools::HistoryFormatter
2
+ # Given a raw Elm history file parsed to JSON, return a simplified hash of the history.
3
+ #
4
+ # For instance, given an array like:
5
+ # [{"ctor": "MessageType", "_0": "Arg1", "_02": {"ctor": "AnotherType"}}]
6
+ #
7
+ # you'll get
8
+ #
9
+ # [{"MessageType" => ["Arg1", {"AnotherType" => []}]}]
10
+ #
11
+ def self.to_simple_hash(history_data)
12
+ history_data["history"].map do |entry|
13
+ simplify_history_entry(entry)
14
+ end
15
+ end
16
+
17
+ # Turn an Elm history entry into a simple Ruby hash, as described above.
18
+ #
19
+ # Constructors that take no arguments are represented as taking an empty list (see above); an
20
+ # alternative approach would be to use nil. While that would clearly distinguish between those
21
+ # cases, it would make working with the results more complicated.
22
+ def self.simplify_history_entry(entry)
23
+ if !entry.is_a?(Hash)
24
+ entry
25
+ elsif entry["ctor"] == "::"
26
+ # Elm lists are represented as nested entries with the contructor ::. (See the readme for
27
+ # more detail.)
28
+ # We collapse those into a proper Ruby array via flatten.
29
+ # The last entry of the list will have no nested entry, so we use compact to remove the nil.
30
+ [simplify_history_entry(entry["_0"]), simplify_history_entry(entry["_1"])].compact.flatten
31
+ elsif entry["ctor"]
32
+ # we have an Elm type
33
+ {
34
+ entry["ctor"] => entry.reject {|k, _v| k == "ctor"}.values.map {|val| simplify_history_entry(val) }
35
+ }
36
+ else
37
+ entry.each_with_object({}) do |(key, value), hash|
38
+ hash[key] = simplify_history_entry(value)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module ElmHistoryTools
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elm_history_tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Koppel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-21 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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:
42
+ email:
43
+ - alex@alexkoppel.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - elm_history_tools.gemspec
58
+ - lib/elm_history_tools.rb
59
+ - lib/elm_history_tools/history_formatter.rb
60
+ - lib/elm_history_tools/version.rb
61
+ - readme-images/elm-history-dashboard.png
62
+ homepage: http://github.com/arsduo/elm-history-tools
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.6.12
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Tools to work with Elm history exports.
86
+ test_files: []