narrative 0.0.1
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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +7 -0
- data/lib/narrative/context/teller.rb +18 -0
- data/lib/narrative/context.rb +35 -0
- data/lib/narrative/version.rb +3 -0
- data/lib/narrative.rb +5 -0
- data/narrative.gemspec +25 -0
- data/spec/lib/narrative/context/teller_spec.rb +40 -0
- data/spec/lib/narrative/context_spec.rb +41 -0
- data/spec/spec_helper.rb +2 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c2af8f475764b8c72d356ad9175a8d993f38c57
|
4
|
+
data.tar.gz: bfec77ba8e70dd340bd07d02c966a285c3279e96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cde76f1dde76492243dae1983fb5037cd1c34f67dc7b87eccd52f6d73d1d28c9ec9542fc025dfa46efd6369a7d7c142602456f9e4e6f4a54b897df01940a4504
|
7
|
+
data.tar.gz: 4b488d38c59cfe34292d25061c8d6114f117c4be876d136e0d08c8dd4c127221a0aa142268eb1ef4fda3513bb7904580ca9791da8ec54f98064f8ba7c8a21f31
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Takuya Watanabe, Hiroshi Kajisha
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
[](https://travis-ci.org/esminc/narrative)
|
2
|
+
[](https://codeclimate.com/github/esminc/narrative)
|
3
|
+
[](https://www.pullreview.com/github/esminc/narrative/reviews/master)
|
4
|
+
|
5
|
+
# Narrative
|
6
|
+
|
7
|
+
TODO: Write a gem description
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'narrative'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install narrative
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
module Narrative
|
4
|
+
module Context
|
5
|
+
module Teller
|
6
|
+
def with_context(context_name, data, &block)
|
7
|
+
context_for(context_name).bind! data, &block
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def context_for(name)
|
13
|
+
context_names = name.split << 'context'
|
14
|
+
context_names.map(&:capitalize).join.constantize
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Narrative
|
4
|
+
module Context
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
cattr_reader(:roles, instance_accessor: false) { {} }
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def role(name, &block)
|
13
|
+
roles[name] = block
|
14
|
+
end
|
15
|
+
|
16
|
+
def bind!(data, &block)
|
17
|
+
block.call bind_roles!(data, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def bind_roles!(data, &block)
|
23
|
+
context_roles = block.parameters.map(&:last)
|
24
|
+
context_roles.each_with_object({}) {|role_name, actors|
|
25
|
+
actors[role_name] = cast!(data[role_name], &roles[role_name])
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def cast!(datum, &method_block)
|
30
|
+
datum.instance_eval(&method_block)
|
31
|
+
datum
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/narrative.rb
ADDED
data/narrative.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'narrative/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'narrative'
|
7
|
+
spec.version = Narrative::VERSION
|
8
|
+
spec.authors = ['Takuya Watanabe', 'Hiroshi Kajisha']
|
9
|
+
spec.email = ['tkywtnb@gmail.com', 'kajisha@gmail.com']
|
10
|
+
spec.summary = %q{a simple implementation of DCI.}
|
11
|
+
spec.description = %q{a simple implementation of DCI.}
|
12
|
+
spec.homepage = 'https://github.com/esminc/narrative'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.5.3'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0.0.beta2'
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Narrative::Context::Teller do
|
4
|
+
describe '#with_context' do
|
5
|
+
class RefactorContext
|
6
|
+
include Narrative::Context
|
7
|
+
|
8
|
+
role :programmer do
|
9
|
+
def refactor!(code)
|
10
|
+
code.thrown_away!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class ContextConsumer
|
16
|
+
include Narrative::Context::Teller
|
17
|
+
|
18
|
+
attr_accessor :code
|
19
|
+
|
20
|
+
def initialize(code)
|
21
|
+
self.code = code
|
22
|
+
end
|
23
|
+
|
24
|
+
def consume
|
25
|
+
with_context 'refactor', programmer: 'alice' do |programmer:|
|
26
|
+
programmer.refactor! code
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
specify do
|
32
|
+
code = double('code')
|
33
|
+
allow(code).to receive(:thrown_away!)
|
34
|
+
|
35
|
+
ContextConsumer.new(code).consume
|
36
|
+
|
37
|
+
expect(code).to have_received(:thrown_away!).once
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Narrative::Context do
|
4
|
+
describe '.role' do
|
5
|
+
class ProjectContext
|
6
|
+
include Narrative::Context
|
7
|
+
|
8
|
+
role :programmer do; end
|
9
|
+
end
|
10
|
+
|
11
|
+
class AnotherProjectContext
|
12
|
+
include Narrative::Context
|
13
|
+
|
14
|
+
role :product_owner do; end
|
15
|
+
end
|
16
|
+
|
17
|
+
it { expect(ProjectContext.roles).to include(:programmer) }
|
18
|
+
it { expect(ProjectContext.roles).not_to include(:product_owner) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.bind' do
|
22
|
+
class ProjectContext
|
23
|
+
include Narrative::Context
|
24
|
+
|
25
|
+
role :programmer do
|
26
|
+
def coding; end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
specify do
|
31
|
+
called = false
|
32
|
+
ProjectContext.bind! programmer: 'alice' do |programmer:|
|
33
|
+
expect(programmer).to respond_to(:coding)
|
34
|
+
|
35
|
+
called = true
|
36
|
+
end
|
37
|
+
|
38
|
+
expect(called).to eq(true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: narrative
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Takuya Watanabe
|
8
|
+
- Hiroshi Kajisha
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.3
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 1.5.3
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rake
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
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: rspec
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.0.0.beta2
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.0.0.beta2
|
70
|
+
description: a simple implementation of DCI.
|
71
|
+
email:
|
72
|
+
- tkywtnb@gmail.com
|
73
|
+
- kajisha@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- lib/narrative.rb
|
86
|
+
- lib/narrative/context.rb
|
87
|
+
- lib/narrative/context/teller.rb
|
88
|
+
- lib/narrative/version.rb
|
89
|
+
- narrative.gemspec
|
90
|
+
- spec/lib/narrative/context/teller_spec.rb
|
91
|
+
- spec/lib/narrative/context_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: https://github.com/esminc/narrative
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: a simple implementation of DCI.
|
117
|
+
test_files:
|
118
|
+
- spec/lib/narrative/context/teller_spec.rb
|
119
|
+
- spec/lib/narrative/context_spec.rb
|
120
|
+
- spec/spec_helper.rb
|