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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00e40cca8ad8624b4a6ab85ab521ecdb08f2f689
4
- data.tar.gz: c791593bc4a01b224dfc37ee944417239b6e10a7
3
+ metadata.gz: 6dd6c5bddafaef5e7619904642a61bc18e4d3ceb
4
+ data.tar.gz: b19c6b3417f70fed51cceaad19951ab356fd2c4c
5
5
  SHA512:
6
- metadata.gz: e690b1251155f2cab4e14ae3a021efa95f68a99ad5ec2881032f7a3b774091b1eecdc45e1beb0ae6760d04a363781165ea6c683e72c68f117a6e824da2a5edf0
7
- data.tar.gz: f1613c4bd503315e41676a77daa47fe76a32c0a4fc460cb79d973000dc58df6d33a972f78a3c9e1b6ba555fe01ff01fdf9f210758c04b92f98f2255d371bc797
6
+ metadata.gz: 604831f80be02bc1fa74f7d4db542ec6dd082d8b738364fd9cff991432c882df576aa7eebf396895198f83a8806d598ae8400bd4d39fd1da05beb6079cc1df7a
7
+ data.tar.gz: b2d21c279d3c1752da601c02731f7c9dfa4f8ba3c6c03f3f3bd55324e11ea518f2cfaf8ded55d5c602f9d824c5312a85fdabbefffcacff00b53b971f18930c64
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ - jruby-19mode # JRuby in 1.9 mode
7
+ - ruby-head
8
+ - jruby-head
9
+ - rbx-2
10
+ env:
11
+ - COVERALLS=true
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: jruby-head
16
+ - rvm: rbx-2
data/Gemfile CHANGED
@@ -4,7 +4,11 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  group :test do
7
- gem 'sqlite3'
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
+ [![Build Status](https://travis-ci.org/saturnflyer/characterize.png?branch=master)](https://travis-ci.org/saturnflyer/characterize)
8
+ [![Code Climate](https://codeclimate.com/github/saturnflyer/characterize.png)](https://codeclimate.com/github/saturnflyer/characterize)
9
+ [![Coverage Status](https://coveralls.io/repos/saturnflyer/characterize/badge.png)](https://coveralls.io/r/saturnflyer/characterize)
10
+ [![Gem Version](https://badge.fury.io/rb/characterize.png)](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:
@@ -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.6.8"
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"
@@ -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
- @view
16
+ @characterize_view
16
17
  end
17
18
 
18
- def __set_view__(obj)
19
- @view = obj
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.__set_view__(view_context).cast_as(*mods)
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}_characters") && action_methods.include?(action_name.to_s)
18
- Array(self.send("#{object_name}_#{action_name}_characters"))
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}_characters")
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
- default_characters = actions_hash.delete(:default) || ["::#{object_constant_name}Character"]
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}_characters
52
- [#{default_characters.map(&:to_s).join(', ')}]
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}_characters
51
+ def #{object_name}_#{action_name}_features
58
52
  [#{characters.map(&:to_s).join(', ')}]
59
53
  end
60
54
  }
@@ -1,3 +1,3 @@
1
1
  module Characterize
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -0,0 +1,5 @@
1
+ module EditUserCharacter
2
+ def editing_title
3
+ "Yay! Special title"
4
+ end
5
+ end
@@ -1,6 +1,10 @@
1
1
  class UsersController < ApplicationController
2
- characterize :user, default: [SpecialCharacter]
2
+ characterize :user, default: [SpecialCharacter],
3
+ edit: [EditUserCharacter]
3
4
 
4
5
  def show; end
6
+ def edit
7
+ render :text => user.editing_title
8
+ end
5
9
 
6
10
  end
@@ -18,8 +18,4 @@ development:
18
18
  # Do not set this db to the same as development or production.
19
19
  test:
20
20
  <<: *default
21
- database: db/test.sqlite3
22
-
23
- production:
24
- <<: *default
25
- database: db/production.sqlite3
21
+ database: db/test.sqlite3
@@ -1,3 +1,3 @@
1
1
  Rails.application.routes.draw do
2
- resources :users, only: [:show]
2
+ resources :users, only: [:show, :edit]
3
3
  end
@@ -1,3 +1,13 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter 'test'
4
+ end
5
+
6
+ require 'coveralls'
7
+ if ENV['COVERALLS']
8
+ Coveralls.wear!
9
+ end
10
+
1
11
  # Configure Rails Environment
2
12
  ENV["RAILS_ENV"] = "test"
3
13
 
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.2
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: 2014-06-22 00:00:00.000000000 Z
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.6.8
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.6.8
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
- - ".ruby-version"
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.2.0
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
@@ -1 +0,0 @@
1
- 2.1.0