activeoopish 0.0.1 → 0.0.2

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: 256e008c0ef28562a42f0b9250ddfa37096abd72
4
- data.tar.gz: e1e3b3fefbd6db22dfd6049b92d5918299111b0a
3
+ metadata.gz: 650b235e105ff9d1e787a92b7c71415f66cc810a
4
+ data.tar.gz: b7f3d38032ee7ecc1d2f100d542ad1d6a4095163
5
5
  SHA512:
6
- metadata.gz: bf0203fca919d91c95e622300bb53ea52c960ab2477893651173c23113337a844959a6f070ec6f7e40d4dce8ffe9f60822420f589e3850851cee5138f70dae28
7
- data.tar.gz: bd3eee6bfba42b3e75d5b7150d846e29959746af601868da40a203ec3d93fac963c3eb0741b80594ec5fece2929d318cbff479754bb779da5929eb6956b4dd9d
6
+ metadata.gz: 6efd69a0876b47abbfddc1df64dbf96cd7a5f3bbe40e1dc74ee8bb964d3d21706a6a604107e05691eb17a994e33e233c9a3f49061b246ade2f3deedf91c14c9f
7
+ data.tar.gz: 0b8509f75c81fe3bdd01ab15c685c6e0a7ffa26286807627146109defa18fbdcdd5810db2464dbde5fc28ce81e0a10c9f1b9c091dc6a81a7eb80a44290c001fa
data/README.md CHANGED
@@ -1,15 +1,15 @@
1
- # AvtiveOOPish
1
+ # AvtiveOopish
2
2
 
3
3
  [![Build Status](https://travis-ci.org/yuku-t/activeoopish.svg?branch=master)](https://travis-ci.org/yuku-t/activeoopish) [![Code Climate](https://codeclimate.com/github/yuku-t/activeoopish/badges/gpa.svg)](https://codeclimate.com/github/yuku-t/activeoopish) [![Coverage Status](https://coveralls.io/repos/yuku-t/activeoopish/badge.svg)](https://coveralls.io/r/yuku-t/activeoopish) [![Dependency Status](https://gemnasium.com/yuku-t/activeoopish.svg)](https://gemnasium.com/yuku-t/activeoopish)
4
4
 
5
5
  Simple tools for better OOP in Rails projects.
6
6
 
7
- ## ActiveOOPish::Validator
7
+ ## ActiveOopish::Validator
8
8
 
9
9
  Encapsulates the responsibility of validating a model into a validator.
10
10
 
11
11
  ```rb
12
- class BookValidator < ActiveOOPish::Validator
12
+ class BookValidator < ActiveOopish::Validator
13
13
  declear do
14
14
  validates :author, presence: true
15
15
 
@@ -39,10 +39,14 @@ end
39
39
  ### RSpec
40
40
 
41
41
  ```rb
42
- require 'activeoopish/rspec'
42
+ require 'activeoopish/rspec_helper'
43
43
  require 'shoulda-matchers'
44
44
 
45
- declear BookValidator, :with_activeoopish_helper do
45
+ describe Book do
46
+ it { should be_monitored_by BookValidator }
47
+ end
48
+
49
+ describe BookValidator, :with_activeoopish_helper do
46
50
  include_context 'describe declaration' do
47
51
  it { should validate_presence_of(:author) }
48
52
 
@@ -50,7 +54,8 @@ declear BookValidator, :with_activeoopish_helper do
50
54
 
51
55
  context 'when #biography? returns true' do
52
56
  before do
53
- allow_any_instance_of(described_class).to receive(:biography?).and_return(true)
57
+ allow_any_instance_of(described_class)
58
+ .to receive(:biography?).and_return(true)
54
59
  end
55
60
 
56
61
  it 'calls #title_must_include_author_name' do
data/activeoopish.gemspec CHANGED
@@ -4,11 +4,11 @@ require "activeoopish/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'activeoopish'
7
- spec.version = ActiveOOPish::VERSION
7
+ spec.version = ActiveOopish::VERSION
8
8
  spec.authors = ['Yuku Takahashi']
9
9
  spec.email = ['yuku@qiita.com']
10
10
  spec.summary = 'Simple OOP-ish tools for Rails'
11
- spec.homepage = 'https://github.com/increments/activeoopish'
11
+ spec.homepage = 'https://github.com/yuku-t/activeoopish'
12
12
  spec.license = 'MIT'
13
13
 
14
14
  spec.files = `git ls-files -z`.split("\x0")
@@ -0,0 +1,38 @@
1
+ require 'active_support/concern'
2
+
3
+ module ActiveOopish
4
+ module Inheritance
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ instance_variable_set('@instantiation_rules', [])
9
+ end
10
+
11
+ module ClassMethods
12
+ # Public:
13
+ #
14
+ # class_name - A String represents the class which instantiates an instance.
15
+ # condition - A Hash with :when key.
16
+ #
17
+ def instantiate_as(class_name, options = {})
18
+ @instantiation_rules << { class_name: class_name, condition: options[:when].stringify_keys }
19
+ end
20
+
21
+ private
22
+
23
+ # Internal: Called by ActiveRecord::Persistence.instantiate to decide which
24
+ # class to use for a new record instance.
25
+ #
26
+ # Returns a Class to instantiate an instance.
27
+ def discriminate_class_for_record(record)
28
+ @instantiation_rules.each do |rule|
29
+ satisfy_rule = rule[:condition].each_pair.all? do |column, expected|
30
+ record[column] == expected
31
+ end
32
+ return rule[:class_name].constantize if satisfy_rule
33
+ end
34
+ self
35
+ end
36
+ end
37
+ end
38
+ end
@@ -9,14 +9,14 @@ RSpec::Matchers.define :be_monitored_by do |validator_class|
9
9
  end
10
10
  end
11
11
 
12
- module ActiveOOPish
12
+ module ActiveOopish
13
13
  module RSpecHelper
14
14
  module SharedContext
15
15
  extend ActiveSupport::Concern
16
16
 
17
17
  included do
18
18
  let(:model_class) do
19
- Class.new(ActiveOOPish::RSpecHelper::ValidationTarget) do
19
+ Class.new(ActiveOopish::RSpecHelper::ValidationTarget) do
20
20
  def self.name
21
21
  'ValidationTarget'
22
22
  end
@@ -62,5 +62,5 @@ module ActiveOOPish
62
62
  end
63
63
 
64
64
  RSpec.configure do |config|
65
- config.include ActiveOOPish::RSpecHelper::SharedContext, :with_activeoopish_helpers
65
+ config.include ActiveOopish::RSpecHelper::SharedContext, :with_activeoopish_helpers
66
66
  end
@@ -1,11 +1,11 @@
1
1
  require 'active_support/core_ext/module/delegation'
2
2
 
3
- module ActiveOOPish
3
+ module ActiveOopish
4
4
  # Public: Base class for validators.
5
5
  #
6
6
  # Example
7
7
  #
8
- # class BookValidator < ActiveOOPish::Validator
8
+ # class BookValidator < ActiveOopish::Validator
9
9
  # declear do
10
10
  # validates :author, presence: true
11
11
  # validate :title_must_include_author_name, if: :biography?
@@ -41,7 +41,7 @@ module ActiveOOPish
41
41
  # # => "author cannot write a biography of another person"
42
42
  #
43
43
  class Validator
44
- # Public: Generic ActiveOOPish::Validator related error.
44
+ # Public: Generic ActiveOopish::Validator related error.
45
45
  # Exceptions raised in this class should inherit from Error.
46
46
  class Error < StandardError
47
47
  end
@@ -1,3 +1,3 @@
1
- module ActiveOOPish
2
- VERSION = '0.0.1'
1
+ module ActiveOopish
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/activeoopish.rb CHANGED
@@ -1,2 +1,3 @@
1
- require 'activeoopish/version'
1
+ require 'activeoopish/inheritance'
2
2
  require 'activeoopish/validator'
3
+ require 'activeoopish/version'
@@ -3,7 +3,7 @@ require 'activeoopish/rspec_helper'
3
3
  describe 'activeoopish matchers' do
4
4
  describe 'be_monitored_by matcher', :with_activeoopish_helpers do
5
5
  let(:validator_class) do
6
- Class.new(ActiveOOPish::Validator) do
6
+ Class.new(ActiveOopish::Validator) do
7
7
  declear do
8
8
  end
9
9
 
@@ -45,7 +45,7 @@ describe 'activeoopish matchers' do
45
45
  end
46
46
  end
47
47
 
48
- class SampleValidator < ActiveOOPish::Validator
48
+ class SampleValidator < ActiveOopish::Validator
49
49
  declear do
50
50
  validates(
51
51
  :attr,
@@ -1,6 +1,6 @@
1
1
  require 'activeoopish/rspec_helper'
2
2
 
3
- describe ActiveOOPish::Validator, :with_activeoopish_helpers do
3
+ describe ActiveOopish::Validator, :with_activeoopish_helpers do
4
4
  describe '.monitor' do
5
5
  subject do
6
6
  validator_class.monitor(model_class)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeoopish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuku Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-15 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -109,13 +109,14 @@ files:
109
109
  - Rakefile
110
110
  - activeoopish.gemspec
111
111
  - lib/activeoopish.rb
112
+ - lib/activeoopish/inheritance.rb
112
113
  - lib/activeoopish/rspec_helper.rb
113
114
  - lib/activeoopish/validator.rb
114
115
  - lib/activeoopish/version.rb
115
116
  - spec/activeoopish/rspec_helper_spec.rb
116
117
  - spec/activeoopish/validator_spec.rb
117
118
  - spec/spec_helper.rb
118
- homepage: https://github.com/increments/activeoopish
119
+ homepage: https://github.com/yuku-t/activeoopish
119
120
  licenses:
120
121
  - MIT
121
122
  metadata: {}