surrounded 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38ccce9051567f5c868f6bf3886a1ed6a7f88886
4
- data.tar.gz: 55256f9f23f0e5369426b6a5b8abc5ab8e08f3ae
3
+ metadata.gz: f5e41776a1619ac88e5a77857ae85f6d0ef7bbf1
4
+ data.tar.gz: 2e39e542b1955af150bf148dc4b15fd29bd7dd46
5
5
  SHA512:
6
- metadata.gz: ff8264560362b3b41d266abc4498937ca5521c725533febd0d28916af5349235faeb45cb84df0775ce0ee4ae32dbf83e3d9c4e0b8e0bd2d8021e7690e5747898
7
- data.tar.gz: 6a96f9ddf345233bcbac765eb28eceec2da8d60756d7adaece9093b111abca093af8915b90dc9b071a6ff922b4531efc933f4487be379f5fd8613ed9c63a6cc7
6
+ metadata.gz: 2bbac0d9d89de2880aee0c54b8916a37d7862d4071f0d9a24f9e93cc7df53733fc9b9e206fbe7552736ef0c90f1320e728fe0990deeda8a03e5921b6080ccc59
7
+ data.tar.gz: 94765d82ed5d64e8d2318ddb53cafd2ad633e3288157df9528df6a40687d04dda66f50b432572a1dc9f361bb73f0549e7d5453b9f5872ab69c4a5c2f6f8aeeab
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  group :test do
4
4
  gem 'minitest'
5
+ # gem 'mutant', git: 'https://github.com/kbrock/mutant.git', ref: 'minitest'
5
6
  gem "simplecov"
6
7
  gem 'coveralls', :require => false
7
8
  gem 'casting'
data/README.md CHANGED
@@ -74,7 +74,7 @@ This will allow you to prepare your accessing code to use keywords.
74
74
  If you need to override the initializer with additional work, you have the ability to use a block to be evaluated in the context of the initialized object.
75
75
 
76
76
  ```ruby
77
- initialize :role1, :role3 do
77
+ initialize :role1, :role2 do
78
78
  map_role(:role3, 'SomeRoleConstantName', initialize_the_object_to_play)
79
79
  end
80
80
  ```
@@ -668,6 +668,8 @@ class ActiviatingAccount
668
668
  # this must be done to handle the mapping of roles to objects
669
669
  # pass an array of arrays with role name symbol and the object for that role
670
670
  map_roles([[:activator, activator],[:account, account]])
671
+ # or pass a hash
672
+ map_roles(:activator => activator, :account => account)
671
673
 
672
674
  # or load extra objects, perform other functions, etc. if you need and then use super
673
675
  account.perform_some_funtion
@@ -677,6 +679,13 @@ class ActiviatingAccount
677
679
  # this is a shortcut for using attr_reader and private
678
680
  private_attr_reader :activator, :account
679
681
 
682
+ # If you need to mix default initialzation and extra work use a block
683
+ initialize :activator, :account do
684
+ map_roles(:third_party => get_some_other_object)
685
+ end
686
+ # but remember to set the extra accessors:
687
+ private_attr_reader :third_party
688
+
680
689
  # initialize with keyword arguments
681
690
  keyword_initialize(:activator, :account)
682
691
  # this makes the following instance method signature with required keyword arguments
data/Rakefile CHANGED
@@ -9,3 +9,9 @@ Rake::TestTask.new do |t|
9
9
  t.verbose = true
10
10
  end
11
11
  task :default => :test
12
+
13
+
14
+ # task :mutant, [:class] do |task, args|
15
+ # klass = args[:class] || 'Surrounded'
16
+ # sh "bundle exec mutant --include lib --require surrounded --use minitest #{klass}"
17
+ # end
@@ -135,7 +135,7 @@ module Surrounded
135
135
  end
136
136
 
137
137
  def map_roles(role_object_array)
138
- role_object_array.each do |role, object|
138
+ role_object_array.to_a.each do |role, object|
139
139
  if self.respond_to?("map_role_#{role}")
140
140
  self.send("map_role_#{role}", object)
141
141
  else
@@ -209,7 +209,9 @@ module Surrounded
209
209
  def apply_behaviors
210
210
  role_map.each do |role, mod_name, object|
211
211
  player = apply_behavior(role, mod_name, object)
212
- player.__send__(:store_context) do; end
212
+ if player.respond_to?(:store_context, true)
213
+ player.__send__(:store_context) do; end
214
+ end
213
215
  end
214
216
  end
215
217
 
@@ -1,5 +1,5 @@
1
1
  module Surrounded
2
- VERSION = "0.9.7"
2
+ VERSION = "0.9.8"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -215,6 +215,32 @@ describe Surrounded::Context, 'assigning roles' do
215
215
  end
216
216
  end
217
217
 
218
+ class BareObjectContext
219
+ extend Surrounded::Context
220
+
221
+ def initialize(number, string, user)
222
+ map_roles(:number => number, :string => string, :user => user)
223
+ end
224
+ private_attr_reader :number, :string, :user
225
+
226
+ role :user do
227
+ def output
228
+ [number.to_s, string, name].join(' - ')
229
+ end
230
+ end
231
+
232
+ trigger :output do
233
+ user.output
234
+ end
235
+ end
236
+
237
+ describe Surrounded::Context, 'skips affecting non-surrounded objects' do
238
+ it 'works with non-surrounded objects' do
239
+ context = BareObjectContext.new(123,'hello', User.new('Jim'))
240
+ assert_equal '123 - hello - Jim', context.output
241
+ end
242
+ end
243
+
218
244
  class CollectionContext
219
245
  extend Surrounded::Context
220
246
 
data/test/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'simplecov'
2
- require 'minitest/autorun'
2
+ require 'minitest/autorun' unless ENV['MUTANT']
3
3
  require 'coveralls'
4
4
 
5
5
  if ENV['COVERALLS']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: surrounded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Jim Gay'"
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: triad
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 2.4.5
119
+ rubygems_version: 2.4.8
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Create encapsulated environments for your objects.