entity_schema 0.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.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.overcommit.yml +37 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +56 -0
  6. data/.rubocop_todo.yml +26 -0
  7. data/.ruby-gemset +1 -0
  8. data/.ruby-version +1 -0
  9. data/.travis.yml +5 -0
  10. data/CHANGELOG.md +17 -0
  11. data/CODE_OF_CONDUCT.md +74 -0
  12. data/Gemfile +8 -0
  13. data/Gemfile.lock +92 -0
  14. data/Guardfile +30 -0
  15. data/LICENSE.txt +21 -0
  16. data/README.md +114 -0
  17. data/Rakefile +8 -0
  18. data/bin/console +15 -0
  19. data/bin/setup +8 -0
  20. data/entity_schema.gemspec +49 -0
  21. data/lib/entity_schema/class_methods.rb +28 -0
  22. data/lib/entity_schema/dsl.rb +40 -0
  23. data/lib/entity_schema/dsl_helper.rb +26 -0
  24. data/lib/entity_schema/fields/abstract.rb +89 -0
  25. data/lib/entity_schema/fields/builders/.rubocop.yml +7 -0
  26. data/lib/entity_schema/fields/builders/abstract.rb +98 -0
  27. data/lib/entity_schema/fields/builders/belongs_to.rb +91 -0
  28. data/lib/entity_schema/fields/builders/collection.rb +20 -0
  29. data/lib/entity_schema/fields/builders/fk_belongs_to.rb +21 -0
  30. data/lib/entity_schema/fields/builders/object.rb +40 -0
  31. data/lib/entity_schema/fields/builders/object_belongs_to.rb +17 -0
  32. data/lib/entity_schema/fields/builders/property.rb +33 -0
  33. data/lib/entity_schema/fields/collection.rb +35 -0
  34. data/lib/entity_schema/fields/fk_belongs_to.rb +16 -0
  35. data/lib/entity_schema/fields/object.rb +36 -0
  36. data/lib/entity_schema/fields/object_belongs_to.rb +16 -0
  37. data/lib/entity_schema/fields/observer_belongs_to.rb +33 -0
  38. data/lib/entity_schema/fields/property.rb +24 -0
  39. data/lib/entity_schema/instance_methods.rb +42 -0
  40. data/lib/entity_schema/schema.rb +77 -0
  41. data/lib/entity_schema/version.rb +5 -0
  42. data/lib/entity_schema.rb +18 -0
  43. metadata +227 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ae5d5a58cb59d7bc39c1461dcb1f6bed390d665ff00e2493234b5a4e1149b66
4
+ data.tar.gz: 637d69c9e038d9080453f93b5cbe0b716ae40a59153657f73512d6961577b486
5
+ SHA512:
6
+ metadata.gz: 3dcd2b61052f0ceaa9b1fd815edb9762081ff6aca02abb1ab5096e03eebb911826d1424587246b7e26964c26f327f18d31ef2d3feea833c90267b32d5eb77abc
7
+ data.tar.gz: d9224aa835f73858ef679c85c71bcfe79ea159cd0c91fbdab5c69a5bd9418a6ce08ff7e8ff25ad961a82935679fc564d519b1ee177addfd0f9f567abc16a01c6
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.overcommit.yml ADDED
@@ -0,0 +1,37 @@
1
+ # Use this file to configure the Overcommit hooks you wish to use. This will
2
+ # extend the default configuration defined in:
3
+ # https://github.com/brigade/overcommit/blob/master/config/default.yml
4
+ #
5
+ # At the topmost level of this YAML file is a key representing type of hook
6
+ # being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7
+ # customize each hook, such as whether to only run it on certain files (via
8
+ # `include`), whether to only display output if it fails (via `quiet`), etc.
9
+ #
10
+ # For a complete list of hooks, see:
11
+ # https://github.com/brigade/overcommit/tree/master/lib/overcommit/hook
12
+ #
13
+ # For a complete list of options that you can use to customize hooks, see:
14
+ # https://github.com/brigade/overcommit#configuration
15
+ #
16
+ # Uncomment the following lines to make the configuration take effect.
17
+
18
+ PreCommit:
19
+ RuboCop:
20
+ enabled: true
21
+ on_warn: fail # Treat all warnings as failures
22
+
23
+ PrePush:
24
+ RSpec:
25
+ enabled: true
26
+ #
27
+ # TrailingWhitespace:
28
+ # enabled: true
29
+ # exclude:
30
+ # - '**/db/structure.sql' # Ignore trailing whitespace in generated files
31
+ #
32
+ #PostCheckout:
33
+ # ALL: # Special hook name that customizes all hooks of this type
34
+ # quiet: true # Change all post-checkout hooks to only display output on failure
35
+ #
36
+ # IndexTags:
37
+ # enabled: true # Generate a tags file with `ctags` each time HEAD changes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,56 @@
1
+ Metrics/LineLength:
2
+ Max: 95
3
+ IgnoredPatterns:
4
+ - '^ *#.*$'
5
+
6
+ Naming/UncommunicativeMethodParamName:
7
+ AllowedNames: io, id, to, by, on, in, at, fk, pk
8
+
9
+ Style/LambdaCall:
10
+ Enabled: false
11
+
12
+ Naming/ConstantName:
13
+ Exclude:
14
+ - 'lib/entity_schema.rb'
15
+
16
+ Style/Documentation:
17
+ Exclude:
18
+ - 'lib/entity_schema.rb'
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'entity_schema.gemspec'
23
+
24
+ Metrics/AbcSize:
25
+ Exclude:
26
+ - 'lib/entity_schema/dsl_helper.rb'
27
+
28
+ Metrics/CyclomaticComplexity:
29
+ Exclude:
30
+ - 'lib/entity_schema/dsl_helper.rb'
31
+
32
+ Metrics/PerceivedComplexity:
33
+ Exclude:
34
+ - 'lib/entity_schema/dsl_helper.rb'
35
+
36
+ Metrics/MethodLength:
37
+ Exclude:
38
+ - 'lib/entity_schema/dsl_helper.rb'
39
+
40
+ Style/Documentation:
41
+ Exclude:
42
+ - 'lib/entity_schema.rb'
43
+ - 'lib/entity_schema/class_methods.rb'
44
+ - 'lib/entity_schema/dsl_helper.rb'
45
+ - 'lib/entity_schema/fields/abstract.rb'
46
+ - 'lib/entity_schema/fields/builders/abstract.rb'
47
+ - 'lib/entity_schema/fields/builders/belongs_to.rb'
48
+ - 'lib/entity_schema/fields/builders/collection.rb'
49
+ - 'lib/entity_schema/fields/builders/fk_belongs_to.rb'
50
+ - 'lib/entity_schema/fields/builders/object.rb'
51
+ - 'lib/entity_schema/fields/builders/object_belongs_to.rb'
52
+ - 'lib/entity_schema/fields/builders/property.rb'
53
+ - 'lib/entity_schema/fields/collection.rb'
54
+ - 'lib/entity_schema/fields/object.rb'
55
+ - 'lib/entity_schema/fields/property.rb'
56
+ - 'lib/entity_schema/instance_methods.rb'
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,26 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-08-20 00:34:58 +0300 using RuboCop version 0.55.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 14
10
+ Style/Documentation:
11
+ Exclude:
12
+ - 'lib/entity_schema.rb'
13
+ - 'lib/entity_schema/class_methods.rb'
14
+ - 'lib/entity_schema/dsl_helper.rb'
15
+ - 'lib/entity_schema/fields/abstract.rb'
16
+ - 'lib/entity_schema/fields/builders/abstract.rb'
17
+ - 'lib/entity_schema/fields/builders/belongs_to.rb'
18
+ - 'lib/entity_schema/fields/builders/collection.rb'
19
+ - 'lib/entity_schema/fields/builders/fk_belongs_to.rb'
20
+ - 'lib/entity_schema/fields/builders/object.rb'
21
+ - 'lib/entity_schema/fields/builders/object_belongs_to.rb'
22
+ - 'lib/entity_schema/fields/builders/property.rb'
23
+ - 'lib/entity_schema/fields/collection.rb'
24
+ - 'lib/entity_schema/fields/object.rb'
25
+ - 'lib/entity_schema/fields/property.rb'
26
+ - 'lib/entity_schema/instance_methods.rb'
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ entity_schema
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.0
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.0]
8
+ ### Added
9
+ + All base functionality with main specs (141 example)
10
+ + .property
11
+ + .property?
12
+ + .object
13
+ + .collection
14
+ + .has_one
15
+ + .has_many
16
+ + .belongs_to
17
+ + Inheritable
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ph-s@mail.ru. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in entity_schema.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ entity_schema (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (10.0.2)
10
+ childprocess (0.9.0)
11
+ ffi (~> 1.0, >= 1.0.11)
12
+ coderay (1.1.2)
13
+ diff-lcs (1.3)
14
+ ffi (1.9.25)
15
+ formatador (0.2.5)
16
+ guard (2.14.2)
17
+ formatador (>= 0.2.4)
18
+ listen (>= 2.7, < 4.0)
19
+ lumberjack (>= 1.0.12, < 2.0)
20
+ nenv (~> 0.1)
21
+ notiffany (~> 0.0)
22
+ pry (>= 0.9.12)
23
+ shellany (~> 0.0)
24
+ thor (>= 0.18.1)
25
+ guard-bundler (2.1.0)
26
+ bundler (~> 1.0)
27
+ guard (~> 2.2)
28
+ guard-compat (~> 1.1)
29
+ guard-compat (1.2.1)
30
+ guard-rspec (4.7.3)
31
+ guard (~> 2.1)
32
+ guard-compat (~> 1.1)
33
+ rspec (>= 2.99.0, < 4.0)
34
+ iniparse (1.4.4)
35
+ listen (3.1.5)
36
+ rb-fsevent (~> 0.9, >= 0.9.4)
37
+ rb-inotify (~> 0.9, >= 0.9.7)
38
+ ruby_dep (~> 1.2)
39
+ lumberjack (1.0.13)
40
+ method_source (0.9.0)
41
+ nenv (0.3.0)
42
+ notiffany (0.1.1)
43
+ nenv (~> 0.1)
44
+ shellany (~> 0.0)
45
+ overcommit (0.45.0)
46
+ childprocess (~> 0.6, >= 0.6.3)
47
+ iniparse (~> 1.4)
48
+ pry (0.11.3)
49
+ coderay (~> 1.1.0)
50
+ method_source (~> 0.9.0)
51
+ pry-byebug (3.6.0)
52
+ byebug (~> 10.0)
53
+ pry (~> 0.10)
54
+ rake (10.5.0)
55
+ rb-fsevent (0.10.3)
56
+ rb-inotify (0.9.10)
57
+ ffi (>= 0.5.0, < 2)
58
+ rspec (3.8.0)
59
+ rspec-core (~> 3.8.0)
60
+ rspec-expectations (~> 3.8.0)
61
+ rspec-mocks (~> 3.8.0)
62
+ rspec-core (3.8.0)
63
+ rspec-support (~> 3.8.0)
64
+ rspec-expectations (3.8.1)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.8.0)
67
+ rspec-mocks (3.8.0)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.8.0)
70
+ rspec-support (3.8.0)
71
+ ruby_dep (1.5.0)
72
+ shellany (0.0.1)
73
+ thor (0.20.0)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ bundler (~> 1.16)
80
+ byebug
81
+ entity_schema!
82
+ guard
83
+ guard-bundler
84
+ guard-rspec
85
+ overcommit
86
+ pry
87
+ pry-byebug
88
+ rake (~> 10.0)
89
+ rspec (~> 3.0)
90
+
91
+ BUNDLED WITH
92
+ 1.16.3
data/Guardfile ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ ## Uncomment and set this to only include directories you want to watch
7
+ # directories %w(app lib config test spec features) \
8
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
9
+
10
+ ## Note: if you are using the `directories` clause above and you are not
11
+ ## watching the project directory ('.'), then you will want to move
12
+ ## the Guardfile to a watched dir and symlink it back, e.g.
13
+ #
14
+ # $ mkdir config
15
+ # $ mv Guardfile config/
16
+ # $ ln -s config/Guardfile .
17
+ #
18
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
19
+
20
+ guard :rspec, cmd: 'rspec' do
21
+ watch(%r{^spec/.+_spec\.rb$})
22
+ watch(%r{^lib/(.+)\.rb$}) { 'spec/dsl' }
23
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
24
+ watch('spec/spec_helper.rb') { 'spec' }
25
+ end
26
+
27
+ guard :bundler do
28
+ watch('Gemfile')
29
+ watch('entity_schema.gemspec')
30
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Captain Philipp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # EntitySchema
2
+ Class-level DSL for mapping Hash with object-like structure to Object (as Entity), and then return it into Hash.
3
+
4
+ Focused on quick, minimal, lazy interaction with source Hash.
5
+
6
+ #### Describe entity structure:
7
+ ```ruby
8
+ class Product
9
+ property :id
10
+ property :title
11
+ property? :enabled
12
+ property? :new, key: :is_new
13
+ property? :sale, key: :is_sale
14
+ property? :bestseller, key: :is_bestseller
15
+ timestamps
16
+
17
+ object :size, map_to: Values::Size
18
+
19
+ belongs_to :color, { color_uid: :uid }, map_to: Color
20
+ has_many :seasons, map_to: Season
21
+ end
22
+ ```
23
+
24
+ #### Create entity from hash:
25
+ ```ruby
26
+ raw_hash = {
27
+ id: 42,
28
+ title: 'Perfect product',
29
+ enabled: true,
30
+ is_new: false,
31
+ is_sale: false,
32
+ is_bestseller: true,
33
+ created_at: '2018-08-16 20:17:55 UTC',
34
+ updated_at: '2018-08-16 20:17:55 UTC',
35
+ size: { ... size params ... },
36
+ color_uid: 7,
37
+ seasons: [{ ... season params ... }, {...}, ...]
38
+ }
39
+
40
+ product = Product.new(raw_hash)
41
+ product.title
42
+ product.sale?
43
+ product.size # => <Values::Size ... >
44
+ product.seasons # => [<Season ... >, <Season ... >, ...]
45
+
46
+ product.color # => <Color @uid=7 ... >
47
+ product.color_uid # => 7
48
+ product.color = nil # => nil
49
+ product.color_uid # => nil
50
+ ```
51
+
52
+ #### Return entity to hash:
53
+ ```ruby
54
+ product.to_h
55
+ # => {
56
+ # => id: 42,
57
+ # => title: 'Perfect product',
58
+ # => enabled: true,
59
+ # => is_new: false,
60
+ # => is_sale: false,
61
+ # => is_bestseller: true,
62
+ # => created_at: '2018-08-16 20:17:55 UTC',
63
+ # => updated_at: '2018-08-16 20:17:55 UTC',
64
+ # => size: { ... size params ... },
65
+ # => color_uid: nil,
66
+ # => seasons: [{ ... seasons params ... }, {...}, ...]
67
+ # => }
68
+ ```
69
+
70
+ ## Validations, and coercions
71
+
72
+ No. Entity assumes that given data already validated and coerced.
73
+
74
+ ## DSL
75
+
76
+ #### property
77
+
78
+ _TODO_
79
+
80
+ #### property?
81
+
82
+ _TODO_
83
+
84
+ #### timestamps
85
+
86
+ It is sugar, that expanded to:
87
+ ```ruby
88
+ property :created_at, **opts
89
+ property :updated_at, **opts
90
+ ```
91
+
92
+ #### object
93
+
94
+ _TODO_
95
+
96
+ #### has_one
97
+
98
+ Just alias for `object`
99
+
100
+ #### collection
101
+
102
+ _TODO_
103
+
104
+ #### has_many
105
+
106
+ Just alias for `collection`
107
+
108
+ #### belongs_to
109
+
110
+ _TODO_
111
+
112
+ ## Instance methods
113
+
114
+ _TODO_