role_playing 0.1.0 → 0.1.2

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: 0bb79da3d2d1f840906ef6a9b5007a4c3341a354
4
+ data.tar.gz: 116bd8cddd8b97b7bf4b47fedf49d2090c8fbf70
5
+ SHA512:
6
+ metadata.gz: a6e6e30ede28a81b584185b3d4e113f81bcb5a33ab96f5e74d285404f5b504ae7d0d982c4e0944345faf83796b4321123104d1652f54f28afc30686edbedf025
7
+ data.tar.gz: 558d0d07a4bfe621689d2524f6bf33ecb608523f5d3a3819dc3b3dafa0db3ed53d1b28fdc94c9a62a8f0c3a8b127a1cf69adc2d16293940b97e9c18cdd601bb5
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.2"
4
+ - "1.9.3"
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
7
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/johnae/role_playing.png)](https://travis-ci.org/johnae/role_playing)
2
+
1
3
  # RolePlaying
2
4
 
3
5
  A ruby DCI implementation using SimpleDelegator. This was extracted from a Rails app I'm working on. It's a very simple and straightforward implementation.
@@ -15,7 +17,9 @@ A further comment on 2 is that it means EVERY time you call extend it blows Ruby
15
17
 
16
18
  Add this line to your application's Gemfile:
17
19
 
18
- gem 'role_playing'
20
+ ```ruby
21
+ gem 'role_playing'
22
+ ```
19
23
 
20
24
  And then execute:
21
25
 
@@ -29,85 +33,97 @@ Or install it yourself as:
29
33
 
30
34
  Using it is as simple as defining (usually) a context like so:
31
35
 
32
- class MoneyTransferring
33
- include RolePlaying::Context
34
-
35
- def initialize(from_account, to_account)
36
- @from_account = from_account
37
- @to_account = to_account
38
- end
39
- def call(amount)
40
- ## this is a little contrived I know
41
- ## it could be easily implemented using
42
- ## increment/decrement methods - just
43
- ## showing the block syntax here
44
- SourceAccount(@from_account) do |source_account|
45
- DestinationAccount(@to_account).deposit(source_account.withdraw(amount))
46
- end
47
- end
48
-
49
- role :SourceAccount do
50
- def withdraw(amount)
51
- self.amount=self.amount-amount
52
- amount
53
- end
54
- end
55
-
56
- role :DestinationAccount do
57
- def deposit(amount)
58
- self.amount=self.amount+amount
59
- end
60
- end
61
-
36
+ ```ruby
37
+ class MoneyTransferring
38
+ include RolePlaying::Context
39
+
40
+ def initialize(from_account, to_account)
41
+ @from_account = from_account
42
+ @to_account = to_account
43
+ end
44
+ def call(amount)
45
+ ## this is a little contrived I know
46
+ ## it could be easily implemented using
47
+ ## increment/decrement methods - just
48
+ ## showing the block syntax here
49
+ SourceAccount(@from_account) do |source_account|
50
+ DestinationAccount(@to_account).deposit(source_account.withdraw(amount))
62
51
  end
52
+ end
63
53
 
64
- Basically a role is a class inheriting from RolePlayer::Role, roles can also be defined by themselves(outside a context) like this:
65
-
66
- class MyRole < RolePlayer::Role
67
- def my_additional_method
68
- end
54
+ role :SourceAccount do
55
+ def withdraw(amount)
56
+ self.amount=self.amount-amount
57
+ amount
69
58
  end
70
-
71
- class MyOtherRole < RolePlayer::Role
72
- def my_other_method
73
- end
59
+ end
60
+
61
+ role :DestinationAccount do
62
+ def deposit(amount)
63
+ self.amount=self.amount+amount
74
64
  end
65
+ end
66
+
67
+ end
68
+ ```
69
+
70
+ Or roles by themselves like so:
71
+
72
+ ```ruby
73
+ class MyRole < RolePlaying::Role
74
+ def my_additional_method
75
+ end
76
+ end
77
+
78
+ class MyOtherRole < RolePlaying::Role
79
+ def my_other_method
80
+ end
81
+ end
82
+ ```
75
83
 
76
84
  And, if defined by themselves, they can be applied in a few ways:
77
85
 
78
- ## our data object which will play different roles (eg. get new/different behavior within a context)
79
- class MyDataObject
80
- end
81
-
82
- MyRole.played_by(MyDataObject) do |role|
83
- role.my_additional_method
84
- end
86
+ ```ruby
87
+ ## our data object which will play different roles (eg. get new/different behavior within a context)
88
+ class MyDataObject
89
+ end
90
+
91
+ MyRole.played_by(MyDataObject) do |role|
92
+ role.my_additional_method
93
+ end
94
+ ```
85
95
 
86
96
  or
87
97
 
88
- role = MyRole.played_by(MyDataObject)
89
- role.my_additional_method
98
+ ```ruby
99
+ role = MyRole.played_by(MyDataObject)
100
+ role.my_additional_method
101
+ ```
90
102
 
91
103
  several roles can be applied too like so:
92
104
 
93
- [MyRole, MyOtherRole].played_by(MyDataObject) do |role|
94
- role.my_additional_method
95
- role.my_other_method
96
- end
105
+ ```ruby
106
+ [MyRole, MyOtherRole].played_by(MyDataObject) do |role|
107
+ role.my_additional_method
108
+ role.my_other_method
109
+ end
110
+ ```
97
111
 
98
112
  or
99
113
 
100
- role = [MyRole, MyOtherRole].played_by(MyDataObject)
101
- role.my_additional_method
102
- role.my_other_method
114
+ ```ruby
115
+ role = [MyRole, MyOtherRole].played_by(MyDataObject)
116
+ role.my_additional_method
117
+ role.my_other_method
118
+ ```
103
119
 
104
- Within a context a role is defined by the role class method. The syntax sugar of applying a role - eg. MyRole(MyDataObject) do |role| - is only available within classes including the RolePlayer::Context module. This was the way I envisioned it - to basically keep all code concerning a context within the same file (and inside the context class).
120
+ Within a context a role is defined by the role class method. The syntax sugar of applying a role - eg. MyRole(MyDataObject) do |role| - is only available within classes including the RolePlaying::Context module. This was the way I envisioned it - to basically keep all code concerning a context within the same file (and inside the context class).
105
121
 
106
122
  Please read the specs for a better understanding. Also please look up DCI (data, context, interaction) for a better understanding of what this is trying to accomplish.
107
123
 
108
124
  ## RSpec
109
125
 
110
- Theres an RSpec extension included which basically aliases RSpecs context to role so the language used in RSpec can be closer to DCI when testing these things.
126
+ There's an RSpec extension included which basically aliases RSpecs context to role so the language used in RSpec can be closer to DCI when testing these things.
111
127
  To use that extension just do require 'role_playing/rspec_role' in your spec_helper. Look at the specs in this gem to see what I mean.
112
128
 
113
129
  ## Rails
data/lib/role_playing.rb CHANGED
@@ -2,4 +2,5 @@ require "active_support/core_ext"
2
2
  require "role_playing/version"
3
3
  require "role_playing/core_ext"
4
4
  require "role_playing/context"
5
- require "role_playing/role"
5
+ require "role_playing/role"
6
+ require 'role_playing/railtie' if defined?(Rails)
@@ -4,7 +4,7 @@ module RolePlaying
4
4
  base.extend(ClassMethods)
5
5
  end
6
6
  module ClassMethods
7
- ## this seemed to dangerous to use
7
+ ## this seemed too dangerous to use
8
8
  ## it enabled us to use Constants when
9
9
  ## defining roles but would also not
10
10
  ## warn about missing constants - which is pretty bad
@@ -1,9 +1,15 @@
1
- require 'rails'
1
+ require 'rails/railtie'
2
2
 
3
3
  module RolePlaying
4
- class Railtie < ::Rails::Railtie #:nodoc:
5
- initializer 'role_playing.configure_rails_initialization' do |app|
4
+ class Railtie < Rails::Railtie #:nodoc:
5
+
6
+ config.after_initialize do |app|
6
7
  config.autoload_paths += %W(#{config.root}/app/contexts)
8
+ ## this seems necessary
9
+ Dir["#{config.root}/app/contexts/*"].each do |ctx|
10
+ require_dependency ctx
11
+ end
7
12
  end
13
+
8
14
  end
9
15
  end
@@ -1,3 +1,3 @@
1
1
  module RolePlaying
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
data/role_playing.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency("rspec", ">= 2.12.0")
21
- gem.add_development_dependency("bundler", "~> 1.2.0")
21
+ gem.add_development_dependency("bundler")
22
22
 
23
23
  gem.add_dependency("activesupport", ">= 3.0.0")
24
24
  end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: role_playing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - John Axel Eriksson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-12 00:00:00.000000000 Z
11
+ date: 2013-09-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 2.12.0
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 2.12.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
- version: 1.2.0
33
+ version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
- version: 1.2.0
40
+ version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: 3.0.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: 3.0.0
62
55
  description: A ruby DCI implementation
@@ -67,6 +60,7 @@ extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
62
  - .gitignore
63
+ - .travis.yml
70
64
  - Gemfile
71
65
  - LICENSE.txt
72
66
  - README.md
@@ -74,7 +68,6 @@ files:
74
68
  - lib/role_playing.rb
75
69
  - lib/role_playing/context.rb
76
70
  - lib/role_playing/core_ext.rb
77
- - lib/role_playing/engine.rb
78
71
  - lib/role_playing/railtie.rb
79
72
  - lib/role_playing/role.rb
80
73
  - lib/role_playing/rspec_role.rb
@@ -84,29 +77,27 @@ files:
84
77
  - spec/spec_helper.rb
85
78
  homepage: ''
86
79
  licenses: []
80
+ metadata: {}
87
81
  post_install_message:
88
82
  rdoc_options: []
89
83
  require_paths:
90
84
  - lib
91
85
  required_ruby_version: !ruby/object:Gem::Requirement
92
- none: false
93
86
  requirements:
94
- - - ! '>='
87
+ - - '>='
95
88
  - !ruby/object:Gem::Version
96
89
  version: '0'
97
90
  required_rubygems_version: !ruby/object:Gem::Requirement
98
- none: false
99
91
  requirements:
100
- - - ! '>='
92
+ - - '>='
101
93
  - !ruby/object:Gem::Version
102
94
  version: '0'
103
95
  requirements: []
104
96
  rubyforge_project:
105
- rubygems_version: 1.8.25
97
+ rubygems_version: 2.0.2
106
98
  signing_key:
107
- specification_version: 3
99
+ specification_version: 4
108
100
  summary: A ruby DCI implementation
109
101
  test_files:
110
102
  - spec/role_playing/role_playing_spec.rb
111
103
  - spec/spec_helper.rb
112
- has_rdoc:
@@ -1,4 +0,0 @@
1
- module RolePlaying #:nodoc:
2
- class Engine < ::Rails::Engine #:nodoc:
3
- end
4
- end