File: README.md

package info (click to toggle)
ruby-module-methods 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 84 kB
  • sloc: ruby: 24; makefile: 4
file content (102 lines) | stat: -rw-r--r-- 3,028 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Module Methods

[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/module_methods?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/module_methods)
[![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/module_methods/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/module_methods)
[![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/module_methods.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/module_methods)
[![Depfu](https://img.shields.io/depfu/AlexWayfer/benchmark_toys?style=flat-square)](https://depfu.com/repos/github/AlexWayfer/module_methods)
[![Inline docs](https://inch-ci.org/github/AlexWayfer/module_methods.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/module_methods)
[![license](https://img.shields.io/github/license/AlexWayfer/module_methods.svg?style=flat-square)](https://github.com/AlexWayfer/module_methods/blob/main/LICENSE.txt)
[![Gem](https://img.shields.io/gem/v/module_methods.svg?style=flat-square)](https://rubygems.org/gems/module_methods)

Extendable module for modules with instance and class methods.
These modules can be included into each other modules and saving all chain,
including `inherited` or `included` (class) methods.

There are no conflicts with `ActiveSupport::Concern`.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'module_methods'
```

And then execute:

```shell
bundle install
```

Or install it yourself as:

```shell
gem install module_methods
```

## Usage

```ruby
require 'module_methods'

module SomeCommonCode
  extend ::ModuleMethods::Extension

  module ClassMethods
    def inherited(klass)
      ## manipulations with klass
    end
  end

  def some_method
    ## this is instance method
  end
end

module MoreSpecificCommonCode
  include SomeCommonCode

  module ClassMethods
    def inherited(klass)
      ## you can control the order of `inherited` execution by `super`
      ## this `super` executes `inherited` in `SomeCommonCode`
      super
    end
  end

  def some_another_method
    ## This is another instance method.
  end
end

class BaseClass
  include MoreSpecificCommonCode

  ## Instance methods from modules are here.
end

class EndPoint < BaseClass
  ## Both `inherited` from `SomeCommonCode` and `MoreSpecificCommonCode`
  ## are executing here; private methods from modules are also here.
end
```

## Development

After checking out the repo, run `bundle install` to install dependencies.

Then, run `toys rspec` to run the tests.

To install this gem onto your local machine, run `toys gem install`.

To release a new version, run `toys gem release %version%`.
See how it works [here](https://github.com/AlexWayfer/gem_toys#release).

## Contributing

Bug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/module_methods).

## License

The gem is available as open source under the terms of the
[MIT License](https://opensource.org/licenses/MIT).