essay 1.0.4 → 1.1.0
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 +4 -4
- data/lib/essay.rb +7 -11
- data/lib/essay/abstract_collection.rb +7 -13
- data/lib/essay/abstract_feature.rb +4 -4
- data/lib/essay/abstract_features.rb +2 -2
- data/lib/essay/association/association_collection.rb +2 -2
- data/lib/essay/association/association_features.rb +3 -3
- data/lib/essay/association/base_feature.rb +3 -3
- data/lib/essay/attribute/attribute_collection.rb +2 -2
- data/lib/essay/attribute/attribute_features.rb +3 -3
- data/lib/essay/attribute/base_feature.rb +3 -3
- data/lib/essay/helpers/model_helper.rb +13 -13
- data/lib/essay/version.rb +1 -1
- metadata +2 -5
- data/lib/essay/helpers/association_helper.rb +0 -17
- data/lib/essay/helpers/attribute_helper.rb +0 -17
- data/lib/essay/helpers/description_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afa4aa60e26f51a5545b57b7b0ad99e5088597a8
|
4
|
+
data.tar.gz: ee869072166075fe1a224378997d9efdf6f9a06f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb8a0a69b4a11e3298b773a46aae74474fbebef2362d43488fc7d0698d31966f175a67ab21f89623d06ce6c971f75b14fdfb309bc275dd087e9a1de7801cab67
|
7
|
+
data.tar.gz: 79a89ab38c33abf43732266128c3b4368e53a98741814abf16c026aeca31e44796a6ef87f5df35583aa1b622cf76b59053761148622390b5e5ebe4f0b3a575a0
|
data/lib/essay.rb
CHANGED
@@ -19,21 +19,17 @@ require 'essay/association/base_feature'
|
|
19
19
|
class ActiveRecord::Base
|
20
20
|
class << self
|
21
21
|
def features
|
22
|
-
@
|
22
|
+
@model_features ||= Essay::ModelFeatures.new(active_record: self)
|
23
23
|
end
|
24
24
|
|
25
|
-
def attribute_features(
|
26
|
-
@
|
27
|
-
|
25
|
+
def attribute_features(attribute = nil)
|
26
|
+
@attributes_features ||= Essay::AttributeCollection.new(active_record: self)
|
27
|
+
attribute ? @attributes_features[attribute] : @attributes_features
|
28
28
|
end
|
29
29
|
|
30
|
-
def association_features(
|
31
|
-
@
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def essay_for(attr_or_assoc)
|
36
|
-
raise NotImplmentedError
|
30
|
+
def association_features(association = nil)
|
31
|
+
@associations_features ||= Essay::AssociationCollection.new(active_record: self)
|
32
|
+
association ? @associations_features[association] : @associations_features
|
37
33
|
end
|
38
34
|
end
|
39
35
|
end
|
@@ -7,18 +7,16 @@ module Essay
|
|
7
7
|
class AbstractCollection
|
8
8
|
include ModelHelper
|
9
9
|
|
10
|
+
attr_reader :env
|
11
|
+
|
10
12
|
def initialize(env)
|
11
|
-
@env
|
12
|
-
@
|
13
|
-
@features_for
|
13
|
+
@env = env
|
14
|
+
@active_record = env.fetch(:active_record)
|
15
|
+
@features_for = {}
|
14
16
|
end
|
15
17
|
|
16
18
|
def [](name)
|
17
|
-
@features_for[
|
18
|
-
end
|
19
|
-
|
20
|
-
def load_contents
|
21
|
-
|
19
|
+
@features_for[name.to_sym] ||= construct_features(name)
|
22
20
|
end
|
23
21
|
|
24
22
|
def to_hash
|
@@ -29,11 +27,7 @@ module Essay
|
|
29
27
|
|
30
28
|
protected
|
31
29
|
def construct_features(name)
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def convert_key(key)
|
36
|
-
key.kind_of?(Symbol) ? key : key.to_sym
|
30
|
+
raise NotImplementedError
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
@@ -3,17 +3,17 @@
|
|
3
3
|
|
4
4
|
require 'essay/helpers/model_helper'
|
5
5
|
require 'essay/helpers/serialize_helper'
|
6
|
-
require 'essay/helpers/description_helper'
|
7
6
|
|
8
7
|
module Essay
|
9
8
|
class AbstractFeature
|
10
9
|
include ModelHelper
|
11
10
|
include SerializeHelper
|
12
|
-
|
11
|
+
|
12
|
+
attr_reader :env
|
13
13
|
|
14
14
|
def initialize(env)
|
15
|
-
@env
|
16
|
-
@
|
15
|
+
@env = env
|
16
|
+
@active_record = env.fetch(:active_record)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -5,8 +5,8 @@ require 'essay/abstract_collection'
|
|
5
5
|
|
6
6
|
module Essay
|
7
7
|
class AssociationCollection < AbstractCollection
|
8
|
-
def construct_features(
|
9
|
-
Essay::AssociationFeatures.new(
|
8
|
+
def construct_features(name)
|
9
|
+
Essay::AssociationFeatures.new(env.merge(association: traits.associations.fetch(name)))
|
10
10
|
end
|
11
11
|
|
12
12
|
protected :construct_features
|
@@ -2,15 +2,15 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'essay/abstract_features'
|
5
|
-
require 'essay/helpers/association_helper'
|
6
5
|
|
7
6
|
module Essay
|
8
7
|
class AssociationFeatures < AbstractFeatures
|
9
|
-
|
8
|
+
attr_reader :association
|
9
|
+
alias this_association association
|
10
10
|
|
11
11
|
def initialize(env)
|
12
12
|
super
|
13
|
-
@
|
13
|
+
@association = env.fetch(:association)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -2,15 +2,15 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'essay/abstract_feature'
|
5
|
-
require 'essay/helpers/association_helper'
|
6
5
|
|
7
6
|
module Essay
|
8
7
|
class AssociationFeatures::Base < AbstractFeature
|
9
|
-
|
8
|
+
attr_reader :association
|
9
|
+
alias this_association association
|
10
10
|
|
11
11
|
def initialize(env)
|
12
12
|
super
|
13
|
-
@
|
13
|
+
@association = env.fetch(:association)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -5,8 +5,8 @@ require 'essay/abstract_collection'
|
|
5
5
|
|
6
6
|
module Essay
|
7
7
|
class AttributeCollection < AbstractCollection
|
8
|
-
def construct_features(
|
9
|
-
Essay::AttributeFeatures.new(
|
8
|
+
def construct_features(name)
|
9
|
+
Essay::AttributeFeatures.new(env.merge(attribute: traits.attributes.fetch(name)))
|
10
10
|
end
|
11
11
|
|
12
12
|
protected :construct_features
|
@@ -2,15 +2,15 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'essay/abstract_features'
|
5
|
-
require 'essay/helpers/attribute_helper'
|
6
5
|
|
7
6
|
module Essay
|
8
7
|
class AttributeFeatures < AbstractFeatures
|
9
|
-
|
8
|
+
attr_reader :attribute
|
9
|
+
alias this_attribute attribute
|
10
10
|
|
11
11
|
def initialize(env)
|
12
12
|
super
|
13
|
-
@
|
13
|
+
@attribute = env.fetch(:attribute)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -2,15 +2,15 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'essay/abstract_feature'
|
5
|
-
require 'essay/helpers/attribute_helper'
|
6
5
|
|
7
6
|
module Essay
|
8
7
|
class AttributeFeatures::Base < AbstractFeature
|
9
|
-
|
8
|
+
attr_reader :attribute
|
9
|
+
alias this_attribute attribute
|
10
10
|
|
11
11
|
def initialize(env)
|
12
12
|
super
|
13
|
-
@
|
13
|
+
@attribute = env.fetch(:attribute)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -3,28 +3,28 @@
|
|
3
3
|
|
4
4
|
module Essay
|
5
5
|
module ModelHelper
|
6
|
-
def
|
7
|
-
@
|
6
|
+
def active_record
|
7
|
+
@active_record
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
10
|
+
def traits
|
11
|
+
active_record.traits
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def active_record_traits
|
15
|
+
traits
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
def model_attributes
|
21
|
-
model_traits.attributes
|
18
|
+
def active_record_attributes
|
19
|
+
traits.attributes
|
22
20
|
end
|
23
21
|
|
24
|
-
|
22
|
+
def active_record_associations
|
23
|
+
traits.associations
|
24
|
+
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
26
|
+
def active_record_features
|
27
|
+
traits.features
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
data/lib/essay/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: essay
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yaroslav Konoplov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,9 +86,6 @@ files:
|
|
86
86
|
- lib/essay/attribute/attribute_collection.rb
|
87
87
|
- lib/essay/attribute/attribute_features.rb
|
88
88
|
- lib/essay/attribute/base_feature.rb
|
89
|
-
- lib/essay/helpers/association_helper.rb
|
90
|
-
- lib/essay/helpers/attribute_helper.rb
|
91
|
-
- lib/essay/helpers/description_helper.rb
|
92
89
|
- lib/essay/helpers/feature_helper.rb
|
93
90
|
- lib/essay/helpers/model_helper.rb
|
94
91
|
- lib/essay/helpers/serialize_helper.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module Essay
|
5
|
-
module AssociationHelper
|
6
|
-
def association_name
|
7
|
-
@association_name
|
8
|
-
end
|
9
|
-
|
10
|
-
def association_traits
|
11
|
-
model_traits.associations[association_name]
|
12
|
-
end
|
13
|
-
|
14
|
-
alias association association_traits
|
15
|
-
alias this_association association
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module Essay
|
5
|
-
module AttributeHelper
|
6
|
-
def attribute_name
|
7
|
-
@attribute_name
|
8
|
-
end
|
9
|
-
|
10
|
-
def attribute_traits
|
11
|
-
model_traits.attributes[attribute_name]
|
12
|
-
end
|
13
|
-
|
14
|
-
alias attribute attribute_traits
|
15
|
-
alias this_attribute attribute
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
module Essay
|
5
|
-
module DescriptionHelper
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
class_attribute :description, instance_predicate: false, instance_writer: false
|
10
|
-
end
|
11
|
-
|
12
|
-
module ClassMethods
|
13
|
-
def describe(description)
|
14
|
-
self.description = description
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|