conderaction 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a09898c6686b343bb6252352f17086e3975284d5
4
+ data.tar.gz: 8e5e1178483b3962de9fd6a5f5c07e7d7c49ad0f
5
+ SHA512:
6
+ metadata.gz: 6f6d9ddbdecba509d5a701e69e80da2c24c7355125efd3c171edb8b611cb749dde69bdf7080fba5c68f4a712af4703785fb7fa00f9c34ba6b5c17491f6b35e1e
7
+ data.tar.gz: 9d08289d8b96488adc3af5f3f9551dd181163f293b90b3b57765fd2f46baec7fbc6d9f2c6f45eecd338e1748702a93d396d3b270b792ec1c43510c6e2ede593d
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012-2014 SpruceMedia LLC
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,53 @@
1
+ # Conderaction
2
+
3
+ [![Circle CI](https://circleci.com/gh/sprucemail/conderaction.png?style=shield&circle-token=55b18893cfc9e61d96670bf41c3496e2bce21302)](https://circleci.com/gh/sprucemail/conderaction)
4
+ [![Code Climate](https://codeclimate.com/repos/5422f047e30ba04f2400133d/badges/732d9a461037fbfbb90a/gpa.svg)](https://codeclimate.com/repos/5422f047e30ba04f2400133d/feed)
5
+
6
+ ## A simple implementation of DCI that specifically targets Ruby on Rails.
7
+ Do it for the life of the object or only for the life of a block of code.
8
+
9
+ Conderaction is inspired by Jim Gay's [casting](https://github.com/saturnflyer/casting) gem but provides a Rails-specific twist to DCI.
10
+
11
+ Here's a quick example that you might try in a Rails project:
12
+
13
+ ```ruby
14
+ # implement a module that contains information for the request response
15
+ # and apply it to an object in your system.
16
+ def show
17
+ respond_with user.as(UserRepresenter)
18
+ end
19
+ ```
20
+
21
+ To use proper delegation, your approach should preserve `self` as a reference
22
+ to the original object receiving a method. When the object receiving the forwarded
23
+ message has its own and separate notion of `self`, you're working with a wrapper (also called
24
+ consultation) and not using delegation.
25
+
26
+ The Ruby standard library includes a library called "delegate", but it is
27
+ a consultation approach. With that "delegate", all messages are forwarded to
28
+ another object, but the attendant object maintains its own identity.
29
+
30
+ With Conderaction, your defined methods may reference `self` and during
31
+ execution it will refer to the original client object.
32
+
33
+ ## Installation
34
+
35
+ If you are using Bundler, add this line to your application's Gemfile:
36
+
37
+ ```ruby
38
+ gem 'conderaction'
39
+ ```
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install conderaction
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
52
+
53
+ Built by [SpruceMail](http://www.sprucemail.com)
@@ -0,0 +1,3 @@
1
+ module Conderaction
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'dci/context'
2
+ require 'dci/data'
@@ -0,0 +1,25 @@
1
+ require 'casting'
2
+ require 'active_support'
3
+
4
+ module DCI
5
+
6
+ module Context
7
+
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def self.perform(*args)
12
+ self.new.perform(*args)
13
+ end
14
+ end
15
+
16
+ def characterize(*args, &block)
17
+ yield
18
+ args.each do |item|
19
+ item.uncast unless item.nil?
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ end
data/lib/dci/data.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'casting'
2
+
3
+ module DCI
4
+
5
+ module Data
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ include Casting::Client
11
+ delegate_missing_methods
12
+ end
13
+
14
+ def as(role, &block)
15
+ if block_given?
16
+ Casting.delegating(self => role) do
17
+ block.call(self)
18
+ end
19
+ else
20
+ self.cast_as(role)
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'test_helper'
2
+
3
+ describe DCI::Context, '.characterize' do
4
+
5
+ it 'responds to added methods inside the block' do
6
+ data = test_person
7
+ context = test_greet
8
+ assert !data.respond_to?(:greet)
9
+
10
+ context.characterize data.as(TestPerson::Greeter) do
11
+ assert data.respond_to?(:greet)
12
+ end
13
+
14
+ assert !data.respond_to?(:greet)
15
+ end
16
+
17
+ end
data/test/data_test.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'test_helper'
2
+
3
+ describe DCI::Data, '.as' do
4
+
5
+ it 'responds to added methods inside the block' do
6
+ data = test_person
7
+ assert !data.respond_to?(:greet)
8
+
9
+ data.as(TestPerson::Greeter) { assert data.respond_to?(:greet) }
10
+
11
+ assert !data.respond_to?(:greet)
12
+ end
13
+
14
+ it 'responds to added methods without a block' do
15
+ data = test_person
16
+ assert !data.respond_to?(:greet)
17
+
18
+ data.as(TestPerson::Greeter)
19
+
20
+ assert data.respond_to?(:greet)
21
+ end
22
+
23
+ it 'returns results from added methods inside the block' do
24
+ data = test_person
25
+ assert_raises(NoMethodError) do
26
+ data.greet
27
+ end
28
+
29
+ result = data.as(TestPerson::Greeter) { data.greet }
30
+ assert_equal 'hello', result
31
+
32
+ assert_raises(NoMethodError) do
33
+ data.greet
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require 'conderaction'
3
+
4
+ class TestPerson
5
+
6
+ include DCI::Data
7
+
8
+ def name
9
+ 'name from TestPerson'
10
+ end
11
+
12
+ module Greeter
13
+
14
+ def greet
15
+ 'hello'
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ class TestGreet
23
+
24
+ include DCI::Context
25
+
26
+ end
27
+
28
+ def test_person
29
+ TestPerson.new
30
+ end
31
+
32
+ def test_greet
33
+ TestGreet.new
34
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conderaction
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Palmer
8
+ - Brian Knight
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: casting
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '0.7'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '0.7'
28
+ description: Allows you to follow DCI principles in Ruby on Rails
29
+ email:
30
+ - nathan@nathanpalmer.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - lib/conderaction.rb
36
+ - lib/dci/context.rb
37
+ - lib/dci/data.rb
38
+ - lib/conderaction/version.rb
39
+ - LICENSE
40
+ - README.md
41
+ - test/test_helper.rb
42
+ - test/data_test.rb
43
+ - test/context_test.rb
44
+ homepage: https://github.com/sprucemail/conderaction
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '2.0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.0.14
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: DCI for Ruby on Rails
68
+ test_files:
69
+ - test/test_helper.rb
70
+ - test/data_test.rb
71
+ - test/context_test.rb