mc_record 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45add1ffe0738ebb9f9d925f7e66a733fa80dfc52afd51f1b578383976f151c1
4
- data.tar.gz: 3006284b78f0a555e562c95f8c1be07cc966148f714e8f096377eefa6774e0c7
3
+ metadata.gz: d1b447bc43a7b599ac54d932ce151a140f69d4d879c7c904193dde3c624d950d
4
+ data.tar.gz: 2e0f6429302e2155b6e975e23a064411b6f7e8c5be205925344a9643f5e05e4b
5
5
  SHA512:
6
- metadata.gz: e89b677a6711cd704253ce9802958fd1b19c9522476d9cca6ba42dc6756ab6c4bcf6e431d2c74fb38d5798e871722c303ee75e311f68f76f35e39a0d2a815534
7
- data.tar.gz: 95a932b56203ddfadebf6f03fbec2aba09ba2466a2834704d44cd605c044d9c847a656f1874c008fb4b8e452626ab3428efc0c6f1263fbef70c12cece97e0904
6
+ metadata.gz: e970106cc98568b244e2901231c5eb576702a8483dec2a96617733d7248bbff460debe874ebb46da367ddd88cf6d44aa4c0064a8d85d617a1b3e4d3a96056234
7
+ data.tar.gz: 35849a799e8c5f9e19c06f7746f53af2049653492930b1e8f0a10dfbb21bac30a290b67dd00d2f994541c0ea33789c0c643f224e527cd6bf22a80b1653164599
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem "activesupport", "7.0.6"
9
9
  gem "microcms-ruby-sdk", "1.2.0"
10
10
  gem "rake", "~> 13.0"
11
+ gem "steep"
12
+ gem "typeprof"
data/Gemfile.lock CHANGED
@@ -1,7 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mc_record (0.1.0)
4
+ mc_record (0.1.1)
5
+ activesupport (= 7.0.6)
6
+ microcms-ruby-sdk (= 1.2.0)
7
+ rake (~> 13.0)
5
8
 
6
9
  GEM
7
10
  remote: https://rubygems.org/
@@ -11,14 +14,55 @@ GEM
11
14
  i18n (>= 1.6, < 2)
12
15
  minitest (>= 5.1)
13
16
  tzinfo (~> 2.0)
17
+ ast (2.4.2)
14
18
  concurrent-ruby (1.2.2)
19
+ csv (3.2.7)
20
+ ffi (1.15.5)
21
+ fileutils (1.7.1)
15
22
  i18n (1.14.1)
16
23
  concurrent-ruby (~> 1.0)
24
+ json (2.6.3)
25
+ language_server-protocol (3.17.0.3)
26
+ listen (3.8.0)
27
+ rb-fsevent (~> 0.10, >= 0.10.3)
28
+ rb-inotify (~> 0.9, >= 0.9.10)
29
+ logger (1.5.3)
17
30
  microcms-ruby-sdk (1.2.0)
18
31
  minitest (5.18.1)
32
+ parser (3.2.2.3)
33
+ ast (~> 2.4.1)
34
+ racc
35
+ racc (1.7.1)
36
+ rainbow (3.1.1)
19
37
  rake (13.0.6)
38
+ rb-fsevent (0.11.2)
39
+ rb-inotify (0.10.1)
40
+ ffi (~> 1.0)
41
+ rbs (3.1.0)
42
+ securerandom (0.2.2)
43
+ steep (1.4.0)
44
+ activesupport (>= 5.1)
45
+ concurrent-ruby (>= 1.2.2)
46
+ csv (>= 3.0.9)
47
+ fileutils (>= 1.1.0)
48
+ json (>= 2.1.0)
49
+ language_server-protocol (>= 3.15, < 4.0)
50
+ listen (~> 3.0)
51
+ logger (>= 1.3.0)
52
+ parser (>= 3.1)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ rbs (>= 2.8.0)
55
+ securerandom (>= 0.1)
56
+ strscan (>= 1.0.0)
57
+ terminal-table (>= 2, < 4)
58
+ strscan (3.0.6)
59
+ terminal-table (3.0.2)
60
+ unicode-display_width (>= 1.1.1, < 3)
61
+ typeprof (0.21.7)
62
+ rbs (>= 1.8.1)
20
63
  tzinfo (2.0.6)
21
64
  concurrent-ruby (~> 1.0)
65
+ unicode-display_width (2.4.2)
22
66
 
23
67
  PLATFORMS
24
68
  x86_64-linux
@@ -28,6 +72,8 @@ DEPENDENCIES
28
72
  mc_record!
29
73
  microcms-ruby-sdk (= 1.2.0)
30
74
  rake (~> 13.0)
75
+ steep
76
+ typeprof
31
77
 
32
78
  BUNDLED WITH
33
79
  2.4.13
data/README.md CHANGED
@@ -1,8 +1,63 @@
1
- TBD...
2
-
3
1
  # McRecord
2
+ McRecord is an ORM for MicroCMS API like ActiveRecord written in Ruby.
3
+
4
+ https://document.microcms.io/content-api/get-list-contents
5
+
6
+ # Usage
7
+
8
+ ## Configure MicroCMS API
9
+
10
+ Configure MicroCMS to use API.
11
+ https://document.microcms.io/manual/create-api
4
12
 
5
13
  ## Installation
6
14
 
15
+ Create a Gemfile like below, and `bundle install`.
16
+
17
+ ```ruby
18
+ gem "mc_record"
19
+ ```
20
+
21
+ ## Implementation
22
+
23
+ Create a Ruby source file like below.
24
+
25
+ ```ruby
26
+ require "mc_record"
27
+
28
+ # Credentials
29
+ McRecord::Base.config(
30
+ service_domain: "[Domain Name]",
31
+ api_key: "[API Key]",
32
+ end_point: "[End Point]"
33
+ )
34
+
35
+ # Define a class that inherits `McRecord::Base`
36
+ class Content < McRecord::Base
37
+ end
38
+
39
+ # Examples
40
+ content = Content.find("[ID]") # => Content
41
+
42
+ # MicroCMS API fields can be read/written as attributes of defined classes.
43
+ puts content.name
44
+ content.category = ""
45
+
46
+ # Other Methods.
47
+ Content.all # => Array<Content>
48
+ Content.where(category: "[Name of Category]") # => Array<Content>
49
+ ```
50
+
51
+ # Supported features
52
+
53
+
54
+ The following methods are supported.
55
+
56
+ - all
57
+ - find
58
+ - where
59
+
60
+ # Future Issues.
7
61
 
8
- ## Usage
62
+ It looks like Active Record, but doesn't offer the complexities of Active Record::Relation.
63
+ For example, it does not support method chaining, lazy loading, etc.
data/Steepfile ADDED
@@ -0,0 +1,26 @@
1
+ # D = Steep::Diagnostic
2
+ #
3
+ target :lib do
4
+ signature "sig"
5
+ check "lib" # Directory name
6
+ check "Gemfile" # File name
7
+ library "ostruct"
8
+ # check "app/models/**/*.rb" # Glob
9
+ # ignore "lib/templates/*.rb"
10
+ # library "pathname", "set" # Standard libraries
11
+ # library "strong_json" # Gems
12
+
13
+ # configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
14
+ # configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
15
+ # configure_code_diagFnostics do |hash| # You can setup everything yourself
16
+ # hash[D::Ruby::NoMethod] = :information
17
+ # end
18
+ end
19
+
20
+ # target :test do
21
+ # signature "sig", "sig-private"
22
+ #
23
+ # check "test"
24
+ #
25
+ # # library "pathname", "set" # Standard libraries
26
+ # end
@@ -32,7 +32,7 @@ module McRecord
32
32
 
33
33
  # @param [String]
34
34
  def self.find(id)
35
- raise ".find is only support String parameter." unless id.instance_of?(String)
35
+ raise "wrong type of argument(expected String)" unless id.instance_of?(String)
36
36
 
37
37
  # OpenStruct
38
38
  api_result = MicroCMS.get(
@@ -52,6 +52,8 @@ module McRecord
52
52
 
53
53
  # @param [Hash]
54
54
  def self.where(arg)
55
+ raise ArgumentError, "wrong type of argument(expected Hash)" unless arg.instance_of?(Hash)
56
+
55
57
  param = build_filter_params(arg)
56
58
 
57
59
  raise "param not specified" if param == ""
@@ -64,6 +66,8 @@ module McRecord
64
66
 
65
67
  # @param [Hash]
66
68
  def self.where_not(arg)
69
+ raise ArgumentError, "wrong type of argument(expected Hash)" unless arg.instance_of?(Hash)
70
+
67
71
  param = build_not_filter_params(arg)
68
72
 
69
73
  raise "param not specified" if param == ""
@@ -182,10 +186,15 @@ module McRecord
182
186
  end
183
187
  end
184
188
 
189
+ private
190
+
191
+ # @param [String]
185
192
  def read_attribute(attr_name)
186
193
  @attributes.to_h[attr_name.to_sym]
187
194
  end
188
195
 
196
+ # @param attr_name [String]
197
+ # @param value [Object]
189
198
  def write_attribute(attr_name, value)
190
199
  @attributes[attr_name] = value
191
200
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module McRecord
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/sig/mc_record.rbs CHANGED
@@ -1,4 +1,29 @@
1
+ # TypeProf 0.21.7
2
+
3
+ # Classes
1
4
  module McRecord
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ class ContentNotFound < StandardError
6
+ end
7
+
8
+ class Base
9
+ extend ActiveSupport::Concern
10
+ @attributes: untyped
11
+ @@end_point: untyped
12
+
13
+ def initialize: (untyped attributes) -> void
14
+ def self.config: (service_domain: untyped, api_key: untyped, end_point: untyped) -> untyped
15
+ def self.all: -> Array[Base]
16
+ def self.find: (untyped id) -> Base
17
+ def self.where: (untyped arg) -> Array[Base]
18
+ def self.where_not: (untyped arg) -> Array[Base]
19
+ def self.define_method_attribute_if_needed: (untyped attr_name) -> nil
20
+ def self.build_filter_params: (untyped arg) -> untyped
21
+ def self.build_not_filter_params: (untyped arg) -> untyped
22
+ def self.open_structs_to_instances: (Array[untyped] contents) -> Array[Base]
23
+ def self.fetch_contents: (?nil param) -> Array[untyped]
24
+
25
+ private
26
+ def read_attribute: (untyped attr_name) -> untyped
27
+ def write_attribute: (untyped attr_name, untyped value) -> untyped
28
+ end
4
29
  end
@@ -0,0 +1,29 @@
1
+ # TypeProf 0.21.7
2
+
3
+ # Classes
4
+ module McRecord
5
+ class ContentNotFound < StandardError
6
+ end
7
+
8
+ class Base
9
+ extend ActiveSupport::Concern
10
+ @attributes: untyped
11
+ @@end_point: untyped
12
+
13
+ def initialize: (untyped attributes) -> void
14
+ def self.config: (service_domain: untyped, api_key: untyped, end_point: untyped) -> untyped
15
+ def self.all: -> Array[Base]
16
+ def self.find: (untyped id) -> Base
17
+ def self.where: (untyped arg) -> Array[Base]
18
+ def self.where_not: (untyped arg) -> Array[Base]
19
+ def self.define_method_attribute_if_needed: (untyped attr_name) -> nil
20
+ def self.build_filter_params: (untyped arg) -> untyped
21
+ def self.build_not_filter_params: (untyped arg) -> untyped
22
+ def self.open_structs_to_instances: (Array[untyped] contents) -> Array[Base]
23
+ def self.fetch_contents: (?nil param) -> Array[untyped]
24
+
25
+ private
26
+ def read_attribute: (untyped attr_name) -> untyped
27
+ def write_attribute: (untyped attr_name, untyped value) -> untyped
28
+ end
29
+ end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mc_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Akira Kure
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-30 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 7.0.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 7.0.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: microcms-ruby-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
13
55
  description: MicroCMS API's ORM like ActiveRecord for Ruby.
14
56
  email:
15
57
  - kuredev@gmail.com
@@ -23,11 +65,12 @@ files:
23
65
  - LICENSE
24
66
  - README.md
25
67
  - Rakefile
68
+ - Steepfile
26
69
  - lib/mc_record.rb
27
70
  - lib/mc_record/base.rb
28
71
  - lib/mc_record/version.rb
29
- - mc_record.gemspec
30
72
  - sig/mc_record.rbs
73
+ - sig/mc_record2.rbs
31
74
  homepage: https://github.com/kuredev/mc_record
32
75
  licenses: []
33
76
  metadata:
data/mc_record.gemspec DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/mc_record/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "mc_record"
7
- spec.version = McRecord::VERSION
8
- spec.authors = ["Akira Kure"]
9
- spec.email = ["kuredev@gmail.com"]
10
-
11
- spec.summary = "MicroCMS API's ORM like ActiveRecord for Ruby."
12
- spec.description = "MicroCMS API's ORM like ActiveRecord for Ruby."
13
- spec.homepage = "https://github.com/kuredev/mc_record"
14
- spec.required_ruby_version = ">= 2.6.0"
15
-
16
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
17
-
18
- spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = "https://github.com/kuredev/mc_record"
20
- spec.metadata["changelog_uri"] = "https://github.com/kuredev/mc_record"
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(__dir__) do
25
- `git ls-files -z`.split("\x0").reject do |f|
26
- (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
27
- end
28
- end
29
- spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
35
-
36
- # For more information and examples about making a new gem, check out our
37
- # guide at: https://bundler.io/guides/creating_gem.html
38
- end