edn 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ README.html
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in edn.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Clinton R. Nixon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,111 @@
1
+ # edn-ruby
2
+
3
+ **edn-ruby** is a Ruby library to read and write [edn][edn] (extensible data notation), a subset of Clojure used for transferring data between applications, much like JSON, YAML, or XML.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'edn'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install edn
18
+
19
+ ## Usage
20
+
21
+ To read a string of **edn**:
22
+
23
+ ```ruby
24
+ EDN.read("[1 2 {:foo \"bar\"}]")
25
+ ```
26
+
27
+ To convert a data structure to an **edn** string:
28
+
29
+ ```ruby
30
+ data.to_edn
31
+ ```
32
+
33
+ By default, this will work for strings, symbols, numbers, arrays, hashes, sets, nil, Time, and boolean values.
34
+
35
+ ### Tagged Values
36
+
37
+ The interesting part of **edn** is the _extensible_ part. Data can be be _tagged_ to coerce interpretation of it to a particular data type. An example of a tagged data element:
38
+
39
+ ```
40
+ #wolf/pack {:alpha "Greybeard" :betas ["Frostpaw" "Blackwind" "Bloodjaw"]}
41
+ ```
42
+
43
+ The tag (`#wolf/pack`) will tell any consumers of this data to use a data type registered to handle `wolf/pack` to represent this data.
44
+
45
+ The rules for tags from the [**edn** README][README] should be followed. In short, custom tags should have a prefix (the part before the `/`) designating the user that created them or context they are used in. Non-prefixed tags are reserved for built-in tags.
46
+
47
+ There are two tags built in by default: `#uuid`, used for UUIDs, and `#inst`, used for an instant in time. In `edn-ruby`, `#inst` is converted to a Time, and Time values are tagged as `#inst`. There is not a UUID data type built into Ruby, so `#uuid` is converted to a string, but if you require `edn/uuid`, `#uuid` values are converted to an instance of `EDN::UUID`.
48
+
49
+ Tags that are not registered are converted as their base data type and a warning will be shown.
50
+
51
+ ### Registering a New Tag For Reading
52
+
53
+ To register a tag for reading, call the method `EDN.register` with a tag and one of the following:
54
+
55
+ - A block that accepts data and returns a value.
56
+ - A lambda that accepts data and returns a value.
57
+ - A class that has an `initialize` method that accepts data.
58
+
59
+ Examples:
60
+
61
+ ```ruby
62
+ EDN.register("clinton/uri") do |uri|
63
+ URI(uri)
64
+ end
65
+
66
+ EDN.register("clinton/date", lambda { |date_array| Date.new(*date_array) }
67
+
68
+ class Dog
69
+ def initialize(name)
70
+ @name = name
71
+ end
72
+ end
73
+
74
+ EDN.register("clinton/dog", Dog)
75
+ ```
76
+
77
+ ### Writing Tags
78
+
79
+ Writing tags should be done as part of the class's `.to_edn` method, like so:
80
+
81
+ ```ruby
82
+ class Dog
83
+ def to_edn
84
+ ["#clinton/dog", @name.to_edn].join(" ")
85
+ end
86
+ end
87
+ ```
88
+
89
+ `EDN` provides a helper method, `EDN.tagout`:
90
+
91
+ ```ruby
92
+ class Dog
93
+ def to_edn
94
+ EDN.tagout("clinton/dog", @name)
95
+ end
96
+ end
97
+ ```
98
+
99
+ This method calls `.to_edn` on the second argument and joins the arguments appropriately.
100
+
101
+ ## Contributing
102
+
103
+ 1. Fork it
104
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
105
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
106
+ 4. Push to the branch (`git push origin my-new-feature`)
107
+ 5. Create new Pull Request
108
+
109
+
110
+ [edn]: https://github.com/richhickey/edn
111
+ [README]: https://github.com/richhickey/edn/blob/master/README.md
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/edn/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Clinton N. Dreisbach"]
6
+ gem.email = ["clinton@thinkrelevance.com"]
7
+ gem.description = %q{'edn implements a reader for Extensible Data Notation by Rich Hickey.'}
8
+ gem.summary = gem.description
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "edn"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = EDN::VERSION
17
+ end
@@ -0,0 +1,5 @@
1
+ require "edn/version"
2
+
3
+ module EDN
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module EDN
2
+ VERSION = "0.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: edn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Clinton N. Dreisbach
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! '''edn implements a reader for Extensible Data Notation by Rich Hickey.'''
15
+ email:
16
+ - clinton@thinkrelevance.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE
24
+ - README.md
25
+ - Rakefile
26
+ - edn.gemspec
27
+ - lib/edn.rb
28
+ - lib/edn/version.rb
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.23
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: ! '''edn implements a reader for Extensible Data Notation by Rich Hickey.'''
53
+ test_files: []