characterize 0.0.2 → 0.0.3
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 +4 -4
- data/.travis.yml +16 -0
- data/Gemfile +5 -1
- data/README.md +68 -1
- data/characterize.gemspec +1 -1
- data/lib/characterize.rb +24 -3
- data/lib/characterize/controller.rb +8 -14
- data/lib/characterize/version.rb +1 -1
- data/test/characterize_test.rb +7 -1
- data/test/internal/app/characters/edit_user_character.rb +5 -0
- data/test/internal/app/controllers/users_controller.rb +5 -1
- data/test/internal/config/database.yml +1 -5
- data/test/internal/config/routes.rb +1 -1
- data/test/test_helper.rb +10 -0
- metadata +8 -6
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6dd6c5bddafaef5e7619904642a61bc18e4d3ceb
|
4
|
+
data.tar.gz: b19c6b3417f70fed51cceaad19951ab356fd2c4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 604831f80be02bc1fa74f7d4db542ec6dd082d8b738364fd9cff991432c882df576aa7eebf396895198f83a8806d598ae8400bd4d39fd1da05beb6079cc1df7a
|
7
|
+
data.tar.gz: b2d21c279d3c1752da601c02731f7c9dfa4f8ba3c6c03f3f3bd55324e11ea518f2cfaf8ded55d5c602f9d824c5312a85fdabbefffcacff00b53b971f18930c64
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -4,7 +4,11 @@ source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem '
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0.rc1', platform: :jruby
|
8
|
+
gem 'sqlite3', platform: :ruby
|
8
9
|
gem 'rails'
|
9
10
|
gem 'minitest-spec-rails'
|
11
|
+
gem 'rubinius-coverage', platform: :rbx
|
12
|
+
gem 'coveralls', require: false
|
13
|
+
gem 'simplecov'
|
10
14
|
end
|
data/README.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Characterize
|
2
2
|
|
3
|
-
Make your models behave in special ways.
|
3
|
+
Make your models behave in special ways without wrapping them.
|
4
|
+
|
5
|
+
Characterize is built on top of [Casting](https://github.com/saturnflyer/casting) and makes it easy to get going in Rails.
|
6
|
+
|
7
|
+
[](https://travis-ci.org/saturnflyer/characterize)
|
8
|
+
[](https://codeclimate.com/github/saturnflyer/characterize)
|
9
|
+
[](https://coveralls.io/r/saturnflyer/characterize)
|
10
|
+
[](http://badge.fury.io/rb/characterize)
|
11
|
+
|
12
|
+
|
13
|
+
|
4
14
|
|
5
15
|
## Usage
|
6
16
|
|
@@ -13,6 +23,12 @@ class UsersController < ApplicationController
|
|
13
23
|
end
|
14
24
|
# the above sets a helper_method of 'user' and loads UserCharacter
|
15
25
|
|
26
|
+
module UserCharacter
|
27
|
+
def special_behavior_available_in_the_view
|
28
|
+
# ...
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
16
32
|
class UsersController < ApplicationController
|
17
33
|
def show
|
18
34
|
characterize(user, display_module)
|
@@ -38,6 +54,57 @@ module StandardUser
|
|
38
54
|
end
|
39
55
|
```
|
40
56
|
|
57
|
+
Set special modules to be used for different actions:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
class UsersController < ApplicationController
|
61
|
+
characterize :user, show: [SpecialStuff, StandardStuff],
|
62
|
+
edit: [EditingCharacter],
|
63
|
+
default: [StandardStuff]
|
64
|
+
|
65
|
+
def show
|
66
|
+
end
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
By default Characterize will look for modules that match the name of your object. So `characterize :user` would apply a `UserCharacter` module (and will blow up if it can't find it.) Or you can override it with the above configuration.
|
71
|
+
|
72
|
+
## Atering the Settings
|
73
|
+
|
74
|
+
### Module names
|
75
|
+
|
76
|
+
Characterize will automatically look for modules using the "Character" suffix in it's name. But you can change this if you like.
|
77
|
+
|
78
|
+
Just create an initializer which will change the setting when your Rails application boots:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
Characterize.module_suffix = 'Details'
|
82
|
+
```
|
83
|
+
|
84
|
+
With the above change, using `characterize :user` in your controller, it will attempt to load `UserDetails` instead of `UserCharacter`. This will apply for your *entire* application; if you only want to override the suffix in some places, just specify the module you want in your controller.
|
85
|
+
|
86
|
+
### Creating your own standard features
|
87
|
+
|
88
|
+
By default Characterize has some helpful features built in. You can use them like this:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
class UsersController < ApplicationController
|
92
|
+
characterize :user, show: [SpecialStuff].concat(Characterize.standard_features)
|
93
|
+
|
94
|
+
def show
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
That will load the built-in features from Characterize. But you can change what is considered "standard" in your application.
|
100
|
+
|
101
|
+
Set the `standard_features` option in your initializer to whatever you want:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
original_features = Characterize.standard_features
|
105
|
+
Characterize.standard_features = [MyAwesomeStuff, ExtraDoodads].concat(original_features)
|
106
|
+
```
|
107
|
+
|
41
108
|
## Installation
|
42
109
|
|
43
110
|
Add this line to your application's Gemfile:
|
data/characterize.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "casting", "~> 0.
|
21
|
+
spec.add_dependency "casting", "~> 0.7.1"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
data/lib/characterize.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "characterize/version"
|
2
2
|
require "characterize/controller"
|
3
|
+
require 'characterize/feature_controls'
|
3
4
|
require "casting"
|
4
5
|
require 'characterize/railtie' if defined?(::Rails)
|
5
6
|
|
@@ -12,11 +13,31 @@ module Characterize
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def view
|
15
|
-
@
|
16
|
+
@characterize_view
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
@
|
19
|
+
def __set_characterize_view__(obj)
|
20
|
+
@characterize_view = obj
|
20
21
|
self
|
21
22
|
end
|
23
|
+
|
24
|
+
def self.module_suffix
|
25
|
+
@characterize_suffix ||= 'Character'
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.module_suffix=(val)
|
29
|
+
@characterize_suffix = val
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.standard_features
|
33
|
+
@standard_features ||= builtin_standard_features
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.standard_features=(mods_array)
|
37
|
+
@standard_features = mods_array
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.builtin_standard_features
|
41
|
+
[::Characterize::FeatureControls]
|
42
|
+
end
|
22
43
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'characterize/feature_controls'
|
2
|
-
|
3
1
|
module Characterize
|
4
2
|
module Controller
|
5
3
|
def self.included(klass)
|
@@ -9,21 +7,17 @@ module Characterize
|
|
9
7
|
private
|
10
8
|
|
11
9
|
def characterize(obj, *mods)
|
12
|
-
obj.
|
10
|
+
obj.__set_characterize_view__(view_context).cast_as(*mods)
|
13
11
|
obj
|
14
12
|
end
|
15
13
|
|
16
14
|
def characters_for_action(object_name, action_name)
|
17
|
-
if self.respond_to?("#{object_name}_#{action_name}
|
18
|
-
Array(self.send("#{object_name}_#{action_name}
|
15
|
+
if self.respond_to?("#{object_name}_#{action_name}_features") && action_methods.include?(action_name.to_s)
|
16
|
+
Array(self.send("#{object_name}_#{action_name}_features"))
|
19
17
|
else
|
20
|
-
self.send("default_#{object_name}
|
18
|
+
self.send("default_#{object_name}_features")
|
21
19
|
end
|
22
20
|
end
|
23
|
-
|
24
|
-
def self.view_features
|
25
|
-
[::Characterize::FeatureControls]
|
26
|
-
end
|
27
21
|
end
|
28
22
|
|
29
23
|
module ControllerMacros
|
@@ -35,7 +29,7 @@ module Characterize
|
|
35
29
|
actions_hash = options.last
|
36
30
|
|
37
31
|
object_constant_name = object_name.to_s.gsub(/(?:^|_)([a-z])/){ $1.upcase }.gsub('/','::')
|
38
|
-
|
32
|
+
default_features = actions_hash.delete(:default) || ["::#{object_constant_name}#{Characterize.module_suffix}"]
|
39
33
|
|
40
34
|
mod = Module.new
|
41
35
|
mod.module_eval %{
|
@@ -48,13 +42,13 @@ module Characterize
|
|
48
42
|
#{object_constant_name}.find(params[:id])
|
49
43
|
end
|
50
44
|
|
51
|
-
def default_#{object_name}
|
52
|
-
[#{
|
45
|
+
def default_#{object_name}_features
|
46
|
+
[#{default_features.map(&:to_s).join(', ')}]
|
53
47
|
end
|
54
48
|
}
|
55
49
|
actions_hash.each_pair do |action_name, characters|
|
56
50
|
mod.module_eval %{
|
57
|
-
def #{object_name}_#{action_name}
|
51
|
+
def #{object_name}_#{action_name}_features
|
58
52
|
[#{characters.map(&:to_s).join(', ')}]
|
59
53
|
end
|
60
54
|
}
|
data/lib/characterize/version.rb
CHANGED
data/test/characterize_test.rb
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
describe UsersController do
|
4
|
-
it 'renders views with extra features from characters' do
|
4
|
+
it 'renders views with extra features from default characters' do
|
5
5
|
get :show, id: '1'
|
6
6
|
assert_template :show
|
7
|
+
assert_select 'a', 'm( O.O )m'
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'renders objects with extra features from specified characters' do
|
11
|
+
get :edit, id: '1'
|
12
|
+
assert_equal "Yay! Special title", response.body
|
7
13
|
end
|
8
14
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: characterize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Jim Gay'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: casting
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.7.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.7.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,7 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
|
-
- ".
|
63
|
+
- ".travis.yml"
|
64
64
|
- Gemfile
|
65
65
|
- LICENSE.txt
|
66
66
|
- README.md
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- test/internal/app/assets/images/.keep
|
79
79
|
- test/internal/app/assets/javascripts/application.js
|
80
80
|
- test/internal/app/assets/stylesheets/application.css
|
81
|
+
- test/internal/app/characters/edit_user_character.rb
|
81
82
|
- test/internal/app/characters/special_character.rb
|
82
83
|
- test/internal/app/characters/user_character.rb
|
83
84
|
- test/internal/app/controllers/application_controller.rb
|
@@ -142,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
145
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
146
|
+
rubygems_version: 2.4.5
|
146
147
|
signing_key:
|
147
148
|
specification_version: 4
|
148
149
|
summary: Use plain modules like presenters
|
@@ -153,6 +154,7 @@ test_files:
|
|
153
154
|
- test/internal/app/assets/images/.keep
|
154
155
|
- test/internal/app/assets/javascripts/application.js
|
155
156
|
- test/internal/app/assets/stylesheets/application.css
|
157
|
+
- test/internal/app/characters/edit_user_character.rb
|
156
158
|
- test/internal/app/characters/special_character.rb
|
157
159
|
- test/internal/app/characters/user_character.rb
|
158
160
|
- test/internal/app/controllers/application_controller.rb
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.0
|