Skip to content

Commit

Permalink
Drops model extension feature
Browse files Browse the repository at this point in the history
  • Loading branch information
eudoxa committed Apr 26, 2024
1 parent 33cb940 commit 8db476e
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 127 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Drop support for Ruby 2
* Drop support for classic loader
* The functionality to extend the view_paths has been discontinued.
* The functionality to extend the model methods has been discontinued.

## 2.3.0
* Support Rails 5.0, 5.1, 5,2, 6.0, 6,1.
Expand Down
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ With Chanko, you can release many features concurrently and manage target users
When any errors are raised from chanko's features,
it will be automatically hidden and fallback to its normal behavior.


## Requirements
* Ruby >= 2.6.0
* Rails >= 5.0.0


## Usage
Add to your Gemfile.

Expand Down Expand Up @@ -117,29 +115,6 @@ end
### render
In version 2 and earlier, Chanko extended Rails' search path to include the views path of the unit. This functionality has been discontinued. To maintain the views path under the unit, you will need to manually create a symbolic link in app/views/units to access it.

### models
In models block, you can expand model features by `expand` method.
The expanded methods are available via unit proxy like `User.unit.active`,
`User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.

```ruby
models do
expand(:User) do
scope :active, lambda { where(:deleted_at => nil) }

def active?
deleted_at.nil?
end

class_methods do
def gc_all_soft_deleted_users
where.not(deleted_at: nil).delete_all
end
end
end
end
```

### shared
You can call methods defined by `shared` in invoking.

Expand All @@ -160,7 +135,6 @@ helpers do
end
```


## Example
https://github.com/cookpad/chanko/tree/master/spec/dummy
Chanko provides an example rails application in spec/dummy directory.
Expand Down
4 changes: 0 additions & 4 deletions lib/chanko/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def helpers(&block)
Helper.define(unit_name, &block)
end

def models(&block)
extender.instance_eval(&block)
end

def active_if(*conditions, &block)
@active_if = ActiveIf.new(*conditions, &block)
end
Expand Down
1 change: 0 additions & 1 deletion lib/chanko/unit/scope_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def class?
def label
label_scope_map = {
:controller => ActionController::Base,
:model => ActiveRecord::Base,
:view => ActionView::Base
}

Expand Down
23 changes: 0 additions & 23 deletions lib/generators/chanko/unit/templates/unit.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,6 @@ module <%= class_name %>
# end
# ```

# ## models
# In models block, you can expand model features by `expand` method.
# The expanded methods are available via unit proxy like `User.unit.active`,
# `User.find(params[:id]).unit.active?` or `User.unit.gc_all_soft_deleted_users`.
#
# ```
# models do
# expand(:User) do
# scope :active, lambda { where(:deleted_at => nil) }
#
# def active?
# deleted_at.nil?
# end
#
# class_methods do
# def gc_all_soft_deleted_users
# where.not(deleted_at: nil).delete_all
# end
# end
# end
# end
# ```

# ## shared
# You can call methods defined by `shared` in invoking.
#
Expand Down
57 changes: 0 additions & 57 deletions spec/chanko/unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,62 +188,5 @@ def test
expect(view.__example_unit_test).to eq("test")
end
end

describe ".models" do
before do
stub_const("ExampleModel", model_class)
unit.models do
expand(:ExampleModel) do
scope :active, lambda { where(:deleted_at => nil) }

has_one :user

def test
"test"
end

class_methods do
def test
"test"
end
end
end
end
end

let(:model_class) do
Class.new do
include UnitProxyProvider

def self.scope(name, *args)
singleton_class.class_eval do
define_method(name) { "scoped" }
end
end

def self.has_one(name, *args)
singleton_class.class_eval do
define_method(name) { args }
end
end
end
end

it "defines instance methods with prefix" do
expect(ExampleModel.new.__example_unit_test).to eq("test")
end

it "defines class methods with prefix" do
expect(ExampleModel.__example_unit_test).to eq("test")
end

it "defines scope method with prefix" do
expect(ExampleModel.__example_unit_active).to eq("scoped")
end

it "defines has_one association method with prefix" do
expect(ExampleModel.__example_unit_user).to eq([:class_name => "User"])
end
end
end
end
16 changes: 0 additions & 16 deletions spec/dummy/app/units/entry_deletion/entry_deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ module EntryDeletion
end
end

models do
expand(:Entry) do
scope :active, lambda { where(:deleted_at => nil) }

def soft_delete
update_attributes(:deleted_at => Time.now)
end

class_methods do
def gc_all_soft_deleted_users
where.not(deleted_at: nil).delete_all
end
end
end
end

helpers do
def link_to_deletion(entry)
link_to "Delete", entry, :method => :delete
Expand Down

0 comments on commit 8db476e

Please sign in to comment.