colonel_kurtz_ruby 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +5 -0
- data/colonel_kurtz_ruby.gemspec +29 -0
- data/lib/colonel_kurtz.rb +10 -0
- data/lib/colonel_kurtz/block.rb +46 -0
- data/lib/colonel_kurtz/block/data.rb +27 -0
- data/lib/colonel_kurtz/block/type.rb +24 -0
- data/lib/colonel_kurtz/model/blockable.rb +21 -0
- data/lib/colonel_kurtz/version.rb +8 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85fac15fa64598b07234a2830267c47a75246fcc
|
4
|
+
data.tar.gz: 5ea19fc21e7b656d5497fadc7cb11798b5333f72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 04240d2ec0e9e46c03c94c7748f2156831a97b27fe6ff14a3d661bc17700d105d63fcbd9e18f0dd0bc161bded3ac0ff15b9f30e234336b8bdcbe7a87277e53ad
|
7
|
+
data.tar.gz: b45a496131e8a8724293546e1b5e94793ddfc84dce412c7b0a3316d183608f2b7db38eaf315bd8251ab246e678f709d7404d8a1608afe0544069dcd1165d6081
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Viget
|
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,106 @@
|
|
1
|
+
# ColonelKurtzRuby
|
2
|
+
|
3
|
+
Ruby wrapper for Colonel Kurtz data.
|
4
|
+
|
5
|
+
[![Code Climate](https://codeclimate.com/github/vigetlabs/colonel_kurtz_ruby/badges/gpa.svg)](https://codeclimate.com/github/vigetlabs/colonel_kurtz_ruby) [![Test Coverage](https://codeclimate.com/github/vigetlabs/colonel_kurtz_ruby/badges/coverage.svg)](https://codeclimate.com/github/vigetlabs/colonel_kurtz_ruby/coverage)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'colonel_kurtz_ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install colonel_kurtz_ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Colonel Kurtz Ruby is a lightweight shim between the JSON data that Colonel Kurtz (https://github.com/vigetlabs/colonel-kurtz) creates and POROs.
|
26
|
+
|
27
|
+
#### Example
|
28
|
+
|
29
|
+
for Colonel Kurtz `data`:
|
30
|
+
|
31
|
+
```JSON
|
32
|
+
{
|
33
|
+
"type" : "example-block",
|
34
|
+
"content" : { "html" : "<p>Example</p>" },
|
35
|
+
"blocks" : [
|
36
|
+
{
|
37
|
+
"type" : "example-block",
|
38
|
+
"content" : { "html" : "<p>Text</p>" },
|
39
|
+
"blocks" : []
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
43
|
+
```
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
block = ColonelKurtz::Block.new(data)
|
47
|
+
|
48
|
+
block.type
|
49
|
+
#=> :example_block
|
50
|
+
|
51
|
+
block.contents
|
52
|
+
#=> { "html" => "<p>Example</p>" }
|
53
|
+
|
54
|
+
block.children
|
55
|
+
#=> [
|
56
|
+
#<ColonelKurtz::Block:0x007fb0eb7bf950....>
|
57
|
+
]
|
58
|
+
```
|
59
|
+
|
60
|
+
#### Model
|
61
|
+
|
62
|
+
Colonel Kurtz Ruby also includes a model mixin for exposing fields that contain Colonel Kurtz data.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class BlockableExample
|
66
|
+
extend ColonelKurtz::Model::Blockable
|
67
|
+
|
68
|
+
has_blocks :content
|
69
|
+
|
70
|
+
attr_reader :data
|
71
|
+
|
72
|
+
def initialize(data)
|
73
|
+
@data = data
|
74
|
+
end
|
75
|
+
|
76
|
+
def content
|
77
|
+
JSON.generate([data])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
example = BlockExample.new(data)
|
84
|
+
|
85
|
+
example.content_blocks
|
86
|
+
#=> [
|
87
|
+
#<ColonelKurtz::Block:0x007fb0eb7bf950....
|
88
|
+
...
|
89
|
+
]
|
90
|
+
```
|
91
|
+
|
92
|
+
## Development
|
93
|
+
|
94
|
+
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.
|
95
|
+
|
96
|
+
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).
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
1. Fork it ( https://github.com/[my-github-username]/colonel_kurtz_ruby/fork )
|
101
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
102
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
103
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
104
|
+
5. Create a new Pull Request
|
105
|
+
|
106
|
+
Viget (www.viget.com)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "colonel_kurtz"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'colonel_kurtz/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "colonel_kurtz_ruby"
|
8
|
+
spec.version = ColonelKurtz::VERSION
|
9
|
+
spec.authors = ["Viget"]
|
10
|
+
spec.email = ["developers@viget.com"]
|
11
|
+
|
12
|
+
spec.summary = "Ruby wrapper for Colonel Kurtz data"
|
13
|
+
spec.description = "Colonel Kurtz Ruby is a lightweight shim between the JSON data that Colonel Kurtz (https://github.com/vigetlabs/colonel-kurtz) creates and POROs."
|
14
|
+
spec.homepage = "https://github.com/vigetlabs/colonel_kurtz_ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
25
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
26
|
+
spec.add_development_dependency "activesupport", "~> 4.2"
|
27
|
+
|
28
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Ruby wrapper for Colonel Kurtz data
|
2
|
+
#
|
3
|
+
# Contents of `data` hash
|
4
|
+
#
|
5
|
+
# type:
|
6
|
+
# block type
|
7
|
+
# string, lower-cased and dashed, e.g. "hero-photo"
|
8
|
+
#
|
9
|
+
# content:
|
10
|
+
# block content
|
11
|
+
# hash
|
12
|
+
#
|
13
|
+
# blocks:
|
14
|
+
# block children
|
15
|
+
# array of `data` hashes
|
16
|
+
#
|
17
|
+
|
18
|
+
module ColonelKurtz
|
19
|
+
class Block
|
20
|
+
|
21
|
+
def initialize(data)
|
22
|
+
@data = Data.new(data).to_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def type
|
26
|
+
@type ||= Type.new(data.fetch("type")).to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def content
|
30
|
+
@content ||= data.fetch("content", {})
|
31
|
+
end
|
32
|
+
|
33
|
+
def children
|
34
|
+
@children ||= blocks.map{ |data| Block.new(data) }
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :data
|
41
|
+
|
42
|
+
def blocks
|
43
|
+
data.fetch("blocks", [])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ColonelKurtz
|
2
|
+
class Block
|
3
|
+
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
class Data
|
8
|
+
|
9
|
+
attr_reader :data
|
10
|
+
|
11
|
+
def initialize(data)
|
12
|
+
@data = data
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
defined?(HashWithIndifferentAccess) ? with_indifferent_access(data) : data
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def with_indifferent_access(hash)
|
23
|
+
HashWithIndifferentAccess.new(hash)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module ColonelKurtz
|
2
|
+
class Block
|
3
|
+
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
class Type
|
8
|
+
|
9
|
+
attr_reader :type
|
10
|
+
|
11
|
+
def initialize(type)
|
12
|
+
@type = type
|
13
|
+
end
|
14
|
+
|
15
|
+
def formatted_type
|
16
|
+
type.gsub("-", "_").downcase
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_sym
|
20
|
+
formatted_type.to_sym
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module ColonelKurtz
|
4
|
+
module Model
|
5
|
+
module Blockable
|
6
|
+
|
7
|
+
def has_blocks(*fields)
|
8
|
+
fields.each do |field|
|
9
|
+
|
10
|
+
define_method "#{field}_blocks" do
|
11
|
+
begin
|
12
|
+
JSON.parse(send(field)).map{ |data| ColonelKurtz::Block.new(data) }
|
13
|
+
rescue
|
14
|
+
[] # TODO error handling
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: colonel_kurtz_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Viget
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-16 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.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Colonel Kurtz Ruby is a lightweight shim between the JSON data that Colonel
|
98
|
+
Kurtz (https://github.com/vigetlabs/colonel-kurtz) creates and POROs.
|
99
|
+
email:
|
100
|
+
- developers@viget.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- colonel_kurtz_ruby.gemspec
|
115
|
+
- lib/colonel_kurtz.rb
|
116
|
+
- lib/colonel_kurtz/block.rb
|
117
|
+
- lib/colonel_kurtz/block/data.rb
|
118
|
+
- lib/colonel_kurtz/block/type.rb
|
119
|
+
- lib/colonel_kurtz/model/blockable.rb
|
120
|
+
- lib/colonel_kurtz/version.rb
|
121
|
+
homepage: https://github.com/vigetlabs/colonel_kurtz_ruby
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.4.5
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Ruby wrapper for Colonel Kurtz data
|
145
|
+
test_files: []
|