active_blocks 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 130257b98bb36c293c3a65562aa457bb1336447f
4
+ data.tar.gz: 68e0a2c3e61d8d6ee9b29ef44e191a5a0af87521
5
+ SHA512:
6
+ metadata.gz: 8c0367d0ddb3fa984cdb1daf8050d89f655949e51b4fe49b27394cbf1874f61659c06a22bce8b1b2f5c6bc7dd51d9fd1a1a88fecbfb70dcd52ad543c3874f3d3
7
+ data.tar.gz: 9fc690c89a1f95510fdfaf06d49343c219f819974245873a9294877ba2abbd533be44134fd3b21bea936f54864f3e8c152b3a92dc2031a51586e9d3211b4c67b
@@ -0,0 +1,12 @@
1
+ # ActiveBlocks
2
+ Manage decorators, form objects and operations.
3
+
4
+ # THIS PROJECT IS STILL IN DEVELOPMENT
5
+
6
+ ## Installation
7
+ Add this line to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'active_blocks'
11
+ ```
12
+
@@ -0,0 +1,9 @@
1
+ module ActiveBlocks
2
+ end
3
+
4
+ require 'active_model'
5
+
6
+ require 'active_blocks/version'
7
+ require 'active_blocks/decorator'
8
+ require 'active_blocks/form'
9
+ require 'active_blocks/operation'
@@ -0,0 +1,25 @@
1
+ require 'active_blocks/decorator/setup'
2
+ require 'active_blocks/decorator/schema'
3
+
4
+ class ActiveBlocks::Decorator
5
+
6
+ include Setup
7
+ include Schema
8
+
9
+ class << self
10
+
11
+ def attribute(name, options={}, &block)
12
+
13
+ definitions[name.to_sym] = build_definition(name, options)
14
+
15
+ mod = Module.new do
16
+ define_method(name) { instance_variable_get("@#{name}") }
17
+ define_method("#{name}=") { |value| instance_variable_set("@#{name}", value) }
18
+ end
19
+ include mod
20
+
21
+ end # attribute
22
+
23
+ end # self
24
+
25
+ end
@@ -0,0 +1,17 @@
1
+ class ActiveBlocks::Decorator
2
+
3
+ module Attributes
4
+
5
+ class Definition
6
+
7
+ attr_reader :name, :options
8
+
9
+ def initialize(name, options={})
10
+ @name = name
11
+ @options = options
12
+ end
13
+
14
+ end # Definition
15
+
16
+ end # Attributes
17
+ end
@@ -0,0 +1,22 @@
1
+ class ActiveBlocks::Decorator
2
+
3
+ module Attributes
4
+
5
+ # skip virtual attributes
6
+ #
7
+ module DefinitionsEach
8
+
9
+ def each
10
+ super() do |name, definition_class|
11
+ next if definition_class.options[:virtual]
12
+ yield name, definition_class
13
+ end
14
+ self
15
+ end # each
16
+
17
+ end # DefinitionsEach
18
+
19
+
20
+ end # Attributes
21
+
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'active_blocks/decorator/attributes/definition'
2
+ require 'active_blocks/decorator/attributes/definitions_each'
3
+
4
+ class ActiveBlocks::Decorator
5
+
6
+ module Schema
7
+
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ def schema
13
+ self.class.definitions.extend(Attributes::DefinitionsEach)
14
+ end
15
+
16
+ module ClassMethods
17
+
18
+ def definitions
19
+ @definitions ||= {}
20
+ end
21
+
22
+ def build_definition(name, options)
23
+ Attributes::Definition.new(name, options)
24
+ end
25
+
26
+ end # ClassMethods
27
+
28
+ end # Schema
29
+
30
+ end
@@ -0,0 +1,28 @@
1
+ class ActiveBlocks::Decorator
2
+
3
+ module Setup
4
+
5
+ attr_reader :model, :attributes
6
+
7
+ def initialize(model, attributes={})
8
+ @attributes = {}
9
+ @model = model
10
+
11
+ setup_attributes(attributes)
12
+ end
13
+
14
+ def setup_attributes(attributes)
15
+ attributes.each do |k, v|
16
+ setup_attribute(k, v)
17
+ end
18
+ end
19
+
20
+ def setup_attribute(name, value)
21
+ return false unless respond_to?("#{name}=")
22
+
23
+ send("#{name}=", value)
24
+ end
25
+
26
+ end # Setup
27
+
28
+ end
@@ -0,0 +1,19 @@
1
+ class ActiveBlocks::Form < ActiveBlocks::Decorator
2
+
3
+ include ActiveModel::Validations
4
+
5
+ def save
6
+ # TODO
7
+ end
8
+
9
+ # Override a validate method of ActiveModel::Validations
10
+ # TODO
11
+ old_validate_method = instance_method(:validate)
12
+
13
+ define_method :validate do |context=nil|
14
+
15
+ old_validate_method.bind(self).call(context)
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,35 @@
1
+ class ActiveBlocks::Operation
2
+
3
+ class_attribute :form_class
4
+ self.form_class = Class.new(ActiveBlocks::Form)
5
+
6
+ # @abstract
7
+ #
8
+ # @raise [NotImplementedError]
9
+ def execute
10
+ fail NotImplementedError
11
+ end
12
+
13
+ class << self
14
+
15
+ # @todo
16
+ def run!
17
+ false
18
+ end
19
+
20
+ # @example
21
+ # form do .. end # define a form
22
+ def form(&block)
23
+ return form_class unless block_given?
24
+
25
+ self.form_class.class_eval(&block) if block_given?
26
+ end
27
+
28
+ end # self
29
+
30
+ # @return [ActiveBlocks::Form]
31
+ def form
32
+ @form ||= self.class.form_class.new(nil)
33
+ end
34
+
35
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveBlocks
2
+ VERSION = '0.0.0'
3
+ end
@@ -0,0 +1,20 @@
1
+ describe ActiveBlocks::Decorator do
2
+
3
+ let!(:decorator_class) do
4
+ class Decorator < ActiveBlocks::Decorator
5
+ attribute :name
6
+ attribute :email
7
+ end
8
+ Decorator
9
+ end
10
+
11
+ let!(:model) { Struct.new(:name, :email, :address) }
12
+
13
+ subject { decorator_class.new(model.new) }
14
+
15
+ it { should respond_to(:name) }
16
+ it { should respond_to(:"name=") }
17
+ it { should respond_to(:"email") }
18
+ it { should respond_to(:"email=") }
19
+
20
+ end
@@ -0,0 +1,24 @@
1
+ describe ActiveBlocks::Form do
2
+
3
+ let!(:form) do
4
+ class Form < ActiveBlocks::Form
5
+
6
+ attribute :name
7
+ attribute :admin, virtual: true
8
+
9
+ validates :name, presence: true
10
+
11
+ end
12
+ Form
13
+ end
14
+
15
+ let!(:model_class) { Struct.new(:name) }
16
+ let!(:model_instance) { model_class.new }
17
+
18
+ subject { form.new(model_instance) }
19
+
20
+ it 'invalid' do
21
+ expect(subject.valid?).to be false
22
+ end
23
+
24
+ end
@@ -0,0 +1,97 @@
1
+ require 'active_blocks'
2
+ # This file was generated by the `rspec --init` command. Conventionally, all
3
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
4
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
5
+ # this file to always be loaded, without a need to explicitly require it in any
6
+ # files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need
14
+ # it.
15
+ #
16
+ # The `.rspec` file also contains a few flags that are not defaults but that
17
+ # users commonly want.
18
+ #
19
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
20
+ RSpec.configure do |config|
21
+ # rspec-expectations config goes here. You can use an alternate
22
+ # assertion/expectation library such as wrong or the stdlib/minitest
23
+ # assertions if you prefer.
24
+ config.expect_with :rspec do |expectations|
25
+ # This option will default to `true` in RSpec 4. It makes the `description`
26
+ # and `failure_message` of custom matchers include text for helper methods
27
+ # defined using `chain`, e.g.:
28
+ # be_bigger_than(2).and_smaller_than(4).description
29
+ # # => "be bigger than 2 and smaller than 4"
30
+ # ...rather than:
31
+ # # => "be bigger than 2"
32
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
33
+ end
34
+
35
+ # rspec-mocks config goes here. You can use an alternate test double
36
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
37
+ config.mock_with :rspec do |mocks|
38
+ # Prevents you from mocking or stubbing a method that does not exist on
39
+ # a real object. This is generally recommended, and will default to
40
+ # `true` in RSpec 4.
41
+ mocks.verify_partial_doubles = true
42
+ end
43
+
44
+ # The settings below are suggested to provide a good initial experience
45
+ # with RSpec, but feel free to customize to your heart's content.
46
+ =begin
47
+ # These two settings work together to allow you to limit a spec run
48
+ # to individual examples or groups you care about by tagging them with
49
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
50
+ # get run.
51
+ config.filter_run :focus
52
+ config.run_all_when_everything_filtered = true
53
+
54
+ # Allows RSpec to persist some state between runs in order to support
55
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
56
+ # you configure your source control system to ignore this file.
57
+ config.example_status_persistence_file_path = "spec/examples.txt"
58
+
59
+ # Limits the available syntax to the non-monkey patched syntax that is
60
+ # recommended. For more details, see:
61
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
62
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
63
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
64
+ config.disable_monkey_patching!
65
+
66
+ # This setting enables warnings. It's recommended, but in some cases may
67
+ # be too noisy due to issues in dependencies.
68
+ config.warnings = true
69
+
70
+ # Many RSpec users commonly either run the entire suite or an individual
71
+ # file, and it's useful to allow more verbose output when running an
72
+ # individual spec file.
73
+ if config.files_to_run.one?
74
+ # Use the documentation formatter for detailed output,
75
+ # unless a formatter has already been configured
76
+ # (e.g. via a command-line flag).
77
+ config.default_formatter = 'doc'
78
+ end
79
+
80
+ # Print the 10 slowest examples and example groups at the
81
+ # end of the spec run, to help surface which specs are running
82
+ # particularly slow.
83
+ config.profile_examples = 10
84
+
85
+ # Run specs in random order to surface order dependencies. If you find an
86
+ # order dependency and want to debug it, you can fix the order by providing
87
+ # the seed, which is printed after each run.
88
+ # --seed 1234
89
+ config.order = :random
90
+
91
+ # Seed global randomization in this process using the `--seed` CLI option.
92
+ # Setting this allows you to use `--seed` to deterministically reproduce
93
+ # test failures related to randomization by passing the same `--seed` value
94
+ # as the one that triggered the failure.
95
+ Kernel.srand config.seed
96
+ =end
97
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_blocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kelvin Lemus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ description: ActiveBlocks is an implementation for manage decorators, form objects
34
+ and operations.
35
+ email: kelvin932810@gmail.com
36
+ executables: []
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - README.md
41
+ - lib/active_blocks.rb
42
+ - lib/active_blocks/decorator.rb
43
+ - lib/active_blocks/decorator/attributes/definition.rb
44
+ - lib/active_blocks/decorator/attributes/definitions_each.rb
45
+ - lib/active_blocks/decorator/schema.rb
46
+ - lib/active_blocks/decorator/setup.rb
47
+ - lib/active_blocks/form.rb
48
+ - lib/active_blocks/operation.rb
49
+ - lib/active_blocks/version.rb
50
+ - spec/active_blocks/decorator_spec.rb
51
+ - spec/active_blocks/form_spec.rb
52
+ - spec/spec_helper.rb
53
+ homepage: https://github.com/ikelvinlemus/active_blocks
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.4.8
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Manage decorators, form objects and operations.
77
+ test_files:
78
+ - spec/active_blocks/form_spec.rb
79
+ - spec/active_blocks/decorator_spec.rb
80
+ - spec/spec_helper.rb
81
+ has_rdoc: