dato 0.1.20 → 0.1.21
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/.rubocop.yml +6 -1
- data/Rakefile +1 -1
- data/dato.gemspec +1 -0
- data/lib/dato/account/client.rb +2 -0
- data/lib/dato/account/repo/account.rb +0 -20
- data/lib/dato/account/repo/site.rb +2 -2
- data/lib/dato/dump/cli.rb +10 -1
- data/lib/dato/dump/format.rb +2 -2
- data/lib/dato/dump/runner.rb +10 -22
- data/lib/dato/local/field_type/file.rb +8 -0
- data/lib/dato/local/field_type/global_seo.rb +53 -0
- data/lib/dato/local/field_type/image.rb +7 -0
- data/lib/dato/local/field_type/lat_lon.rb +7 -0
- data/lib/dato/local/field_type/links.rb +6 -2
- data/lib/dato/local/field_type/seo.rb +8 -0
- data/lib/dato/local/field_type/video.rb +50 -35
- data/lib/dato/local/item.rb +36 -14
- data/lib/dato/local/items_repo.rb +36 -17
- data/lib/dato/local/loader.rb +53 -0
- data/lib/dato/local/site.rb +40 -36
- data/lib/dato/version.rb +1 -1
- metadata +18 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: d6df40edef1f8ec088780bf5465eed032d37f853
         | 
| 4 | 
            +
              data.tar.gz: b9a2c1fecc384e608aa7fd483fa8af4ad3a7058b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 96981103eb1441d212ad4932a3b595a1dca7f1b01fc47bfe4a78a385c96e612dcd685efab2603d8b82501f003f0389766f65b7aeba8081561c5114272392b8a8
         | 
| 7 | 
            +
              data.tar.gz: 1b782b8acade363c81060cc31c29ca34fc93a7730f2d4b8df2363308986d6ff160d3d8e5d6e5f2cf84d5590eb505125f3ddc25fa00afcb032518c68df2039e5d
         | 
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -14,11 +14,16 @@ Metrics/ModuleLength: | |
| 14 14 | 
             
              Enabled: false
         | 
| 15 15 |  | 
| 16 16 | 
             
            Metrics/AbcSize:
         | 
| 17 | 
            -
              Max:  | 
| 17 | 
            +
              Max: 20
         | 
| 18 18 |  | 
| 19 19 | 
             
            Metrics/LineLength:
         | 
| 20 20 | 
             
              Exclude:
         | 
| 21 21 | 
             
              - "spec/**/*"
         | 
| 22 22 | 
             
              - "lib/dato/site/repo/*"
         | 
| 23 23 | 
             
              - "lib/dato/account/repo/*"
         | 
| 24 | 
            +
              - "lib/dato/account/repo/*"
         | 
| 24 25 | 
             
              - "dato.gemspec"
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            Metrics/ParameterLists:
         | 
| 28 | 
            +
              Exclude:
         | 
| 29 | 
            +
              - "lib/dato/local/field_type/*"
         | 
    
        data/Rakefile
    CHANGED
    
    
    
        data/dato.gemspec
    CHANGED
    
    | @@ -31,6 +31,7 @@ Gem::Specification.new do |spec| | |
| 31 31 | 
             
              spec.add_development_dependency 'vcr'
         | 
| 32 32 | 
             
              spec.add_development_dependency 'webmock'
         | 
| 33 33 | 
             
              spec.add_development_dependency 'rubocop'
         | 
| 34 | 
            +
              spec.add_development_dependency 'diff_dirs'
         | 
| 34 35 |  | 
| 35 36 | 
             
              spec.add_runtime_dependency 'faraday', ['>= 0.9.0']
         | 
| 36 37 | 
             
              spec.add_runtime_dependency 'faraday_middleware', ['>= 0.9.0']
         | 
    
        data/lib/dato/account/client.rb
    CHANGED
    
    
| @@ -5,16 +5,6 @@ module Dato | |
| 5 5 | 
             
              module Account
         | 
| 6 6 | 
             
                module Repo
         | 
| 7 7 | 
             
                  class Account < Base
         | 
| 8 | 
            -
                    def create(resource_attributes)
         | 
| 9 | 
            -
                      body = JsonApiSerializer.new(
         | 
| 10 | 
            -
                        type: :account,
         | 
| 11 | 
            -
                        attributes: %i(email password),
         | 
| 12 | 
            -
                        required_attributes: %i(email password)
         | 
| 13 | 
            -
                      ).serialize(resource_attributes)
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                      post_request '/account', body
         | 
| 16 | 
            -
                    end
         | 
| 17 | 
            -
             | 
| 18 8 | 
             
                    def update(resource_attributes)
         | 
| 19 9 | 
             
                      body = JsonApiSerializer.new(
         | 
| 20 10 | 
             
                        type: :account,
         | 
| @@ -27,16 +17,6 @@ module Dato | |
| 27 17 | 
             
                    def find
         | 
| 28 18 | 
             
                      get_request '/account'
         | 
| 29 19 | 
             
                    end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                    def reset_password(resource_attributes)
         | 
| 32 | 
            -
                      body = JsonApiSerializer.new(
         | 
| 33 | 
            -
                        type: :account,
         | 
| 34 | 
            -
                        attributes: %i(email),
         | 
| 35 | 
            -
                        required_attributes: %i(email)
         | 
| 36 | 
            -
                      ).serialize(resource_attributes)
         | 
| 37 | 
            -
             | 
| 38 | 
            -
                      post_request '/account/reset_password', body
         | 
| 39 | 
            -
                    end
         | 
| 40 20 | 
             
                  end
         | 
| 41 21 | 
             
                end
         | 
| 42 22 | 
             
              end
         | 
| @@ -16,7 +16,7 @@ module Dato | |
| 16 16 | 
             
                    def create(resource_attributes)
         | 
| 17 17 | 
             
                      body = JsonApiSerializer.new(
         | 
| 18 18 | 
             
                        type: :site,
         | 
| 19 | 
            -
                        attributes: %i(domain name notes template)
         | 
| 19 | 
            +
                        attributes: %i(domain internal_subdomain name notes template)
         | 
| 20 20 | 
             
                      ).serialize(resource_attributes)
         | 
| 21 21 |  | 
| 22 22 | 
             
                      post_request '/sites', body
         | 
| @@ -25,7 +25,7 @@ module Dato | |
| 25 25 | 
             
                    def update(site_id, resource_attributes)
         | 
| 26 26 | 
             
                      body = JsonApiSerializer.new(
         | 
| 27 27 | 
             
                        type: :site,
         | 
| 28 | 
            -
                        attributes: %i(domain name notes)
         | 
| 28 | 
            +
                        attributes: %i(domain internal_subdomain name notes)
         | 
| 29 29 | 
             
                      ).serialize(resource_attributes, site_id)
         | 
| 30 30 |  | 
| 31 31 | 
             
                      put_request "/sites/#{site_id}", body
         | 
    
        data/lib/dato/dump/cli.rb
    CHANGED
    
    | @@ -12,7 +12,16 @@ module Dato | |
| 12 12 | 
             
                  option :token, default: ENV['DATO_API_TOKEN'], required: true
         | 
| 13 13 | 
             
                  def dump
         | 
| 14 14 | 
             
                    config_file = File.expand_path(options[:config])
         | 
| 15 | 
            -
             | 
| 15 | 
            +
             | 
| 16 | 
            +
                    client = Dato::Site::Client.new(
         | 
| 17 | 
            +
                      options[:token],
         | 
| 18 | 
            +
                      extra_headers: {
         | 
| 19 | 
            +
                        'X-Reason' => 'dump',
         | 
| 20 | 
            +
                        'X-SSG' => SsgDetector.new(Dir.pwd).detect
         | 
| 21 | 
            +
                      }
         | 
| 22 | 
            +
                    )
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                    Runner.new(config_file, client).run
         | 
| 16 25 | 
             
                  end
         | 
| 17 26 | 
             
                end
         | 
| 18 27 | 
             
              end
         | 
    
        data/lib/dato/dump/format.rb
    CHANGED
    
    
    
        data/lib/dato/dump/runner.rb
    CHANGED
    
    | @@ -2,23 +2,25 @@ | |
| 2 2 | 
             
            require 'dato/dump/dsl/root'
         | 
| 3 3 | 
             
            require 'dato/dump/operation/root'
         | 
| 4 4 | 
             
            require 'dato/dump/ssg_detector'
         | 
| 5 | 
            +
            require 'dato/local/loader'
         | 
| 5 6 |  | 
| 6 7 | 
             
            module Dato
         | 
| 7 8 | 
             
              module Dump
         | 
| 8 9 | 
             
                class Runner
         | 
| 9 | 
            -
                  attr_reader :config_path, : | 
| 10 | 
            +
                  attr_reader :config_path, :client, :destination_path
         | 
| 10 11 |  | 
| 11 | 
            -
                  def initialize(config_path,  | 
| 12 | 
            +
                  def initialize(config_path, client, destination_path = Dir.pwd)
         | 
| 12 13 | 
             
                    @config_path = config_path
         | 
| 13 | 
            -
                    @ | 
| 14 | 
            +
                    @client = client
         | 
| 15 | 
            +
                    @destination_path = destination_path
         | 
| 14 16 | 
             
                  end
         | 
| 15 17 |  | 
| 16 18 | 
             
                  def run
         | 
| 17 | 
            -
                     | 
| 19 | 
            +
                    loader.load
         | 
| 18 20 |  | 
| 19 21 | 
             
                    Dsl::Root.new(
         | 
| 20 22 | 
             
                      File.read(config_path),
         | 
| 21 | 
            -
                       | 
| 23 | 
            +
                      loader.items_repo,
         | 
| 22 24 | 
             
                      operation
         | 
| 23 25 | 
             
                    )
         | 
| 24 26 |  | 
| @@ -26,25 +28,11 @@ module Dato | |
| 26 28 | 
             
                  end
         | 
| 27 29 |  | 
| 28 30 | 
             
                  def operation
         | 
| 29 | 
            -
                    @operation ||= Operation::Root.new( | 
| 31 | 
            +
                    @operation ||= Operation::Root.new(destination_path)
         | 
| 30 32 | 
             
                  end
         | 
| 31 33 |  | 
| 32 | 
            -
                  def  | 
| 33 | 
            -
                    @ | 
| 34 | 
            -
                  end
         | 
| 35 | 
            -
             | 
| 36 | 
            -
                  def client
         | 
| 37 | 
            -
                    @client ||= Dato::Site::Client.new(
         | 
| 38 | 
            -
                      api_token,
         | 
| 39 | 
            -
                      extra_headers: {
         | 
| 40 | 
            -
                        'X-Reason' => 'dump',
         | 
| 41 | 
            -
                        'X-SSG' => generator
         | 
| 42 | 
            -
                      }
         | 
| 43 | 
            -
                    )
         | 
| 44 | 
            -
                  end
         | 
| 45 | 
            -
             | 
| 46 | 
            -
                  def generator
         | 
| 47 | 
            -
                    SsgDetector.new(Dir.pwd).detect
         | 
| 34 | 
            +
                  def loader
         | 
| 35 | 
            +
                    @loader ||= Dato::Local::Loader.new(client)
         | 
| 48 36 | 
             
                  end
         | 
| 49 37 | 
             
                end
         | 
| 50 38 | 
             
              end
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
            require 'dato/local/field_type/seo'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Dato
         | 
| 5 | 
            +
              module Local
         | 
| 6 | 
            +
                module FieldType
         | 
| 7 | 
            +
                  class GlobalSeo
         | 
| 8 | 
            +
                    attr_reader :site_name
         | 
| 9 | 
            +
                    attr_reader :title_suffix
         | 
| 10 | 
            +
                    attr_reader :twitter_account
         | 
| 11 | 
            +
                    attr_reader :facebook_page_url
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    def self.parse(value, _repo)
         | 
| 14 | 
            +
                      new(
         | 
| 15 | 
            +
                        value[:site_name],
         | 
| 16 | 
            +
                        value[:title_suffix],
         | 
| 17 | 
            +
                        value[:twitter_account],
         | 
| 18 | 
            +
                        value[:facebook_page_url],
         | 
| 19 | 
            +
                        value[:fallback_seo]
         | 
| 20 | 
            +
                      )
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                    def initialize(
         | 
| 24 | 
            +
                      site_name,
         | 
| 25 | 
            +
                      title_suffix,
         | 
| 26 | 
            +
                      twitter_account,
         | 
| 27 | 
            +
                      facebook_page_url,
         | 
| 28 | 
            +
                      fallback_seo
         | 
| 29 | 
            +
                    )
         | 
| 30 | 
            +
                      @site_name = site_name
         | 
| 31 | 
            +
                      @title_suffix = title_suffix
         | 
| 32 | 
            +
                      @twitter_account = twitter_account
         | 
| 33 | 
            +
                      @facebook_page_url = facebook_page_url
         | 
| 34 | 
            +
                      @fallback_seo = fallback_seo
         | 
| 35 | 
            +
                    end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def fallback_seo
         | 
| 38 | 
            +
                      @fallback_seo && Seo.parse(@fallback_seo, nil)
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                    def to_hash
         | 
| 42 | 
            +
                      {
         | 
| 43 | 
            +
                        site_name: site_name,
         | 
| 44 | 
            +
                        title_suffix: title_suffix,
         | 
| 45 | 
            +
                        twitter_account: twitter_account,
         | 
| 46 | 
            +
                        facebook_page_url: facebook_page_url,
         | 
| 47 | 
            +
                        fallback_seo: fallback_seo && fallback_seo.to_hash
         | 
| 48 | 
            +
                      }
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
| @@ -6,49 +6,64 @@ module Dato | |
| 6 6 | 
             
              module Local
         | 
| 7 7 | 
             
                module FieldType
         | 
| 8 8 | 
             
                  class Video
         | 
| 9 | 
            -
                     | 
| 10 | 
            -
             | 
| 11 | 
            -
                     | 
| 12 | 
            -
             | 
| 13 | 
            -
                     | 
| 14 | 
            -
             | 
| 15 | 
            -
                     | 
| 16 | 
            -
             | 
| 17 | 
            -
                    def url
         | 
| 18 | 
            -
                      @attributes[:url]
         | 
| 19 | 
            -
                    end
         | 
| 20 | 
            -
             | 
| 21 | 
            -
                    def thumbnail_url
         | 
| 22 | 
            -
                      @attributes[:thumbnail_url]
         | 
| 23 | 
            -
                    end
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                    def title
         | 
| 26 | 
            -
                      @attributes[:title]
         | 
| 27 | 
            -
                    end
         | 
| 9 | 
            +
                    attr_reader :url
         | 
| 10 | 
            +
                    attr_reader :thumbnail_url
         | 
| 11 | 
            +
                    attr_reader :title
         | 
| 12 | 
            +
                    attr_reader :width
         | 
| 13 | 
            +
                    attr_reader :height
         | 
| 14 | 
            +
                    attr_reader :provider
         | 
| 15 | 
            +
                    attr_reader :provider_url
         | 
| 16 | 
            +
                    attr_reader :provider_uid
         | 
| 28 17 |  | 
| 29 | 
            -
                    def  | 
| 30 | 
            -
                       | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
                    def provider_url
         | 
| 42 | 
            -
                      @attributes[:provider_url]
         | 
| 18 | 
            +
                    def self.parse(value, _repo)
         | 
| 19 | 
            +
                      new(
         | 
| 20 | 
            +
                        value[:url],
         | 
| 21 | 
            +
                        value[:thumbnail_url],
         | 
| 22 | 
            +
                        value[:title],
         | 
| 23 | 
            +
                        value[:width],
         | 
| 24 | 
            +
                        value[:height],
         | 
| 25 | 
            +
                        value[:provider],
         | 
| 26 | 
            +
                        value[:provider_url],
         | 
| 27 | 
            +
                        value[:provider_uid]
         | 
| 28 | 
            +
                      )
         | 
| 43 29 | 
             
                    end
         | 
| 44 30 |  | 
| 45 | 
            -
                    def  | 
| 46 | 
            -
                       | 
| 31 | 
            +
                    def initialize(
         | 
| 32 | 
            +
                      url,
         | 
| 33 | 
            +
                      thumbnail_url,
         | 
| 34 | 
            +
                      title,
         | 
| 35 | 
            +
                      width,
         | 
| 36 | 
            +
                      height,
         | 
| 37 | 
            +
                      provider,
         | 
| 38 | 
            +
                      provider_url,
         | 
| 39 | 
            +
                      provider_uid
         | 
| 40 | 
            +
                    )
         | 
| 41 | 
            +
                      @url            = url
         | 
| 42 | 
            +
                      @thumbnail_url  = thumbnail_url
         | 
| 43 | 
            +
                      @title          = title
         | 
| 44 | 
            +
                      @width          = width
         | 
| 45 | 
            +
                      @height         = height
         | 
| 46 | 
            +
                      @provider       = provider
         | 
| 47 | 
            +
                      @provider_url   = provider_url
         | 
| 48 | 
            +
                      @provider_uid   = provider_uid
         | 
| 47 49 | 
             
                    end
         | 
| 48 50 |  | 
| 49 51 | 
             
                    def iframe_embed(width = nil, height = nil)
         | 
| 50 52 | 
             
                      VideoEmbed.embed(url, { width: width, height: height }.compact)
         | 
| 51 53 | 
             
                    end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    def to_hash
         | 
| 56 | 
            +
                      {
         | 
| 57 | 
            +
                        url: url,
         | 
| 58 | 
            +
                        thumbnail_url: thumbnail_url,
         | 
| 59 | 
            +
                        title: title,
         | 
| 60 | 
            +
                        width: width,
         | 
| 61 | 
            +
                        height: height,
         | 
| 62 | 
            +
                        provider: provider,
         | 
| 63 | 
            +
                        provider_url: provider_url,
         | 
| 64 | 
            +
                        provider_uid: provider_uid
         | 
| 65 | 
            +
                      }
         | 
| 66 | 
            +
                    end
         | 
| 52 67 | 
             
                  end
         | 
| 53 68 | 
             
                end
         | 
| 54 69 | 
             
              end
         | 
    
        data/lib/dato/local/item.rb
    CHANGED
    
    | @@ -73,20 +73,25 @@ module Dato | |
| 73 73 | 
             
                  end
         | 
| 74 74 | 
             
                  alias inspect to_s
         | 
| 75 75 |  | 
| 76 | 
            -
                  def  | 
| 77 | 
            -
                     | 
| 78 | 
            -
                       | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
                     | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 76 | 
            +
                  def to_hash
         | 
| 77 | 
            +
                    base = {
         | 
| 78 | 
            +
                      id: id,
         | 
| 79 | 
            +
                      item_type: item_type.api_key,
         | 
| 80 | 
            +
                      slug: slug(prefix_with_id: false),
         | 
| 81 | 
            +
                      slug_with_prefix: slug,
         | 
| 82 | 
            +
                      updated_at: updated_at
         | 
| 83 | 
            +
                    }
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                    base[:position] = position if item_type.sortable
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                    @attributes ||= fields.each_with_object(base) do |field, result|
         | 
| 88 | 
            +
                      value = send(field.api_key)
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                      result[field.api_key.to_sym] = if value.respond_to?(:to_hash)
         | 
| 91 | 
            +
                                                       value.to_hash
         | 
| 92 | 
            +
                                                     else
         | 
| 93 | 
            +
                                                       value
         | 
| 94 | 
            +
                                                     end
         | 
| 90 95 | 
             
                    end
         | 
| 91 96 | 
             
                  end
         | 
| 92 97 |  | 
| @@ -126,6 +131,23 @@ module Dato | |
| 126 131 | 
             
                    end
         | 
| 127 132 | 
             
                    raise NoMethodError, message.join("\n")
         | 
| 128 133 | 
             
                  end
         | 
| 134 | 
            +
             | 
| 135 | 
            +
                  def respond_to_missing?(method, include_private = false)
         | 
| 136 | 
            +
                    field = fields.find { |f| f.api_key.to_sym == method }
         | 
| 137 | 
            +
                    if field
         | 
| 138 | 
            +
                      true
         | 
| 139 | 
            +
                    else
         | 
| 140 | 
            +
                      super
         | 
| 141 | 
            +
                    end
         | 
| 142 | 
            +
                  end
         | 
| 143 | 
            +
             | 
| 144 | 
            +
                  def title_attribute
         | 
| 145 | 
            +
                    title_field = fields.find do |field|
         | 
| 146 | 
            +
                      field.field_type == 'string' &&
         | 
| 147 | 
            +
                        field.appeareance[:type] == 'title'
         | 
| 148 | 
            +
                    end
         | 
| 149 | 
            +
                    title_field && title_field.api_key
         | 
| 150 | 
            +
                  end
         | 
| 129 151 | 
             
                end
         | 
| 130 152 | 
             
              end
         | 
| 131 153 | 
             
            end
         | 
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 | 
             
            require 'active_support/core_ext/string'
         | 
| 3 3 | 
             
            require 'dato/local/item'
         | 
| 4 | 
            +
            require 'dato/local/site'
         | 
| 4 5 |  | 
| 5 6 | 
             
            module Dato
         | 
| 6 7 | 
             
              module Local
         | 
| @@ -28,6 +29,28 @@ module Dato | |
| 28 29 | 
             
                    end
         | 
| 29 30 | 
             
                  end
         | 
| 30 31 |  | 
| 32 | 
            +
                  def site
         | 
| 33 | 
            +
                    Site.new(entities_repo.find_entities_of_type('site').first)
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def available_locales
         | 
| 37 | 
            +
                    site.locales.map(&:to_sym)
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def item_types
         | 
| 41 | 
            +
                    entities_repo.find_entities_of_type('item_type')
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def items_of_type(item_type)
         | 
| 45 | 
            +
                    method, singleton = item_type_methods[item_type]
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    if singleton
         | 
| 48 | 
            +
                      [@collections_by_type[method]]
         | 
| 49 | 
            +
                    else
         | 
| 50 | 
            +
                      @collections_by_type[method]
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
             | 
| 31 54 | 
             
                  private
         | 
| 32 55 |  | 
| 33 56 | 
             
                  def build_cache!
         | 
| @@ -38,13 +61,13 @@ module Dato | |
| 38 61 | 
             
                  def build_item_type_methods!
         | 
| 39 62 | 
             
                    @item_type_methods = {}
         | 
| 40 63 |  | 
| 41 | 
            -
                    singleton_keys =  | 
| 42 | 
            -
                    collection_keys =  | 
| 43 | 
            -
             | 
| 64 | 
            +
                    singleton_keys = singleton_item_types.map(&:api_key)
         | 
| 65 | 
            +
                    collection_keys = collection_item_types.map(&:api_key)
         | 
| 66 | 
            +
                                                           .map(&:pluralize)
         | 
| 44 67 |  | 
| 45 68 | 
             
                    clashing_keys = singleton_keys & collection_keys
         | 
| 46 69 |  | 
| 47 | 
            -
                     | 
| 70 | 
            +
                    item_types.each do |item_type|
         | 
| 48 71 | 
             
                      singleton = item_type.singleton
         | 
| 49 72 | 
             
                      pluralized_api_key = item_type.api_key.pluralize
         | 
| 50 73 | 
             
                      method = singleton ? item_type.api_key : pluralized_api_key
         | 
| @@ -59,14 +82,14 @@ module Dato | |
| 59 82 | 
             
                  end
         | 
| 60 83 |  | 
| 61 84 | 
             
                  def build_collections_by_type!
         | 
| 62 | 
            -
                     | 
| 85 | 
            +
                    item_types.each do |item_type|
         | 
| 63 86 | 
             
                      method, singleton = item_type_methods[item_type]
         | 
| 64 87 |  | 
| 65 88 | 
             
                      @collections_by_type[method] = if singleton
         | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 89 | 
            +
                                                       nil
         | 
| 90 | 
            +
                                                     else
         | 
| 91 | 
            +
                                                       ItemCollection.new
         | 
| 92 | 
            +
                                                     end
         | 
| 70 93 | 
             
                    end
         | 
| 71 94 |  | 
| 72 95 | 
             
                    item_entities.each do |item_entity|
         | 
| @@ -83,20 +106,16 @@ module Dato | |
| 83 106 | 
             
                    end
         | 
| 84 107 | 
             
                  end
         | 
| 85 108 |  | 
| 86 | 
            -
                  def item_type_entities
         | 
| 87 | 
            -
                    entities_repo.find_entities_of_type('item_type')
         | 
| 88 | 
            -
                  end
         | 
| 89 | 
            -
             | 
| 90 109 | 
             
                  def item_entities
         | 
| 91 110 | 
             
                    entities_repo.find_entities_of_type('item')
         | 
| 92 111 | 
             
                  end
         | 
| 93 112 |  | 
| 94 | 
            -
                  def  | 
| 95 | 
            -
                     | 
| 113 | 
            +
                  def singleton_item_types
         | 
| 114 | 
            +
                    item_types.select(&:singleton)
         | 
| 96 115 | 
             
                  end
         | 
| 97 116 |  | 
| 98 | 
            -
                  def  | 
| 99 | 
            -
                     | 
| 117 | 
            +
                  def collection_item_types
         | 
| 118 | 
            +
                    item_types - singleton_item_types
         | 
| 100 119 | 
             
                  end
         | 
| 101 120 |  | 
| 102 121 | 
             
                  def method_missing(method, *arguments, &block)
         | 
| @@ -0,0 +1,53 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
            require 'dato/local/entities_repo'
         | 
| 3 | 
            +
            require 'dato/local/items_repo'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module Dato
         | 
| 6 | 
            +
              module Local
         | 
| 7 | 
            +
                class Loader
         | 
| 8 | 
            +
                  attr_reader :client
         | 
| 9 | 
            +
                  attr_reader :entities_repo
         | 
| 10 | 
            +
                  attr_reader :items_repo
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  def initialize(client)
         | 
| 13 | 
            +
                    @client = client
         | 
| 14 | 
            +
                    @entities_repo = EntitiesRepo.new
         | 
| 15 | 
            +
                    @items_repo = ItemsRepo.new(@entities_repo)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  def load
         | 
| 19 | 
            +
                    @entities_repo = EntitiesRepo.new(site, all_items)
         | 
| 20 | 
            +
                    @items_repo = ItemsRepo.new(@entities_repo)
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  private
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def site
         | 
| 26 | 
            +
                    include = [
         | 
| 27 | 
            +
                      'item_types',
         | 
| 28 | 
            +
                      'item_types.fields'
         | 
| 29 | 
            +
                    ]
         | 
| 30 | 
            +
                    client.request(:get, '/site', include: include)
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def all_items
         | 
| 34 | 
            +
                    items_per_page = 500
         | 
| 35 | 
            +
                    base_response = client.request(:get, '/items', 'page[limit]' => 1)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    pages = (base_response[:meta][:total_count] / items_per_page.to_f).ceil
         | 
| 38 | 
            +
                    base_response[:data] = []
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    pages.times do |page|
         | 
| 41 | 
            +
                      base_response[:data] += client.request(
         | 
| 42 | 
            +
                        :get,
         | 
| 43 | 
            +
                        '/items',
         | 
| 44 | 
            +
                        'page[offset]' => items_per_page * page,
         | 
| 45 | 
            +
                        'page[limit]' => items_per_page
         | 
| 46 | 
            +
                      )[:data]
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    base_response
         | 
| 50 | 
            +
                  end
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
    
        data/lib/dato/local/site.rb
    CHANGED
    
    | @@ -1,56 +1,60 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 | 
            -
            require ' | 
| 3 | 
            -
            require ' | 
| 2 | 
            +
            require 'forwardable'
         | 
| 3 | 
            +
            require 'active_support/inflector/transliterate'
         | 
| 4 | 
            +
            require 'active_support/hash_with_indifferent_access'
         | 
| 4 5 |  | 
| 5 6 | 
             
            module Dato
         | 
| 6 7 | 
             
              module Local
         | 
| 7 8 | 
             
                class Site
         | 
| 8 | 
            -
                   | 
| 9 | 
            -
             | 
| 10 | 
            -
                  attr_reader : | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
                    @ | 
| 9 | 
            +
                  extend Forwardable
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                  attr_reader :entity
         | 
| 12 | 
            +
                  def_delegators :entity, :id, :name, :locales, :theme_hue, :domain,
         | 
| 13 | 
            +
                                 :internal_domain, :no_index
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                  def initialize(entity)
         | 
| 16 | 
            +
                    @entity = entity
         | 
| 16 17 | 
             
                  end
         | 
| 17 18 |  | 
| 18 | 
            -
                  def  | 
| 19 | 
            -
                     | 
| 20 | 
            -
                    @items_repo = ItemsRepo.new(@entities_repo)
         | 
| 19 | 
            +
                  def global_seo
         | 
| 20 | 
            +
                    read_attribute(:global_seo, FieldType::GlobalSeo, locales.size > 1)
         | 
| 21 21 | 
             
                  end
         | 
| 22 22 |  | 
| 23 | 
            -
                  def  | 
| 24 | 
            -
                     | 
| 23 | 
            +
                  def favicon
         | 
| 24 | 
            +
                    read_attribute(:favicon, FieldType::Image, false)
         | 
| 25 25 | 
             
                  end
         | 
| 26 26 |  | 
| 27 | 
            -
                   | 
| 27 | 
            +
                  def to_s
         | 
| 28 | 
            +
                    "#<Site id=#{id} site_name=#{site_name}>"
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                  alias inspect to_s
         | 
| 28 31 |  | 
| 29 | 
            -
                  def  | 
| 30 | 
            -
                     | 
| 31 | 
            -
                       | 
| 32 | 
            -
                       | 
| 32 | 
            +
                  def to_hash
         | 
| 33 | 
            +
                    attributes = [
         | 
| 34 | 
            +
                      :id, :name, :locales, :theme_hue, :domain, :internal_domain,
         | 
| 35 | 
            +
                      :no_index, :global_seo, :favicon
         | 
| 33 36 | 
             
                    ]
         | 
| 34 | 
            -
                    client.request(:get, '/site', include: include)
         | 
| 35 | 
            -
                  end
         | 
| 36 37 |  | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
             | 
| 38 | 
            +
                    attributes.each_with_object({}) do |attribute, result|
         | 
| 39 | 
            +
                      value = send(attribute)
         | 
| 40 | 
            +
                      result[attribute] = if value.respond_to?(:to_hash)
         | 
| 41 | 
            +
                                            value.to_hash
         | 
| 42 | 
            +
                                          else
         | 
| 43 | 
            +
                                            value
         | 
| 44 | 
            +
                                          end
         | 
| 45 | 
            +
                    end
         | 
| 46 | 
            +
                  end
         | 
| 40 47 |  | 
| 41 | 
            -
             | 
| 42 | 
            -
                    base_response[:data] = []
         | 
| 48 | 
            +
                  private
         | 
| 43 49 |  | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
                      )[:data]
         | 
| 51 | 
            -
                    end
         | 
| 50 | 
            +
                  def read_attribute(method, type_klass, localized)
         | 
| 51 | 
            +
                    value = if localized
         | 
| 52 | 
            +
                              (entity.send(method) || {})[I18n.locale]
         | 
| 53 | 
            +
                            else
         | 
| 54 | 
            +
                              entity.send(method)
         | 
| 55 | 
            +
                            end
         | 
| 52 56 |  | 
| 53 | 
            -
                     | 
| 57 | 
            +
                    value && type_klass.parse(value, @items_repo)
         | 
| 54 58 | 
             
                  end
         | 
| 55 59 | 
             
                end
         | 
| 56 60 | 
             
              end
         | 
    
        data/lib/dato/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: dato
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.21
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Stefano Verna
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016-09- | 
| 11 | 
            +
            date: 2016-09-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -136,6 +136,20 @@ dependencies: | |
| 136 136 | 
             
                - - ">="
         | 
| 137 137 | 
             
                  - !ruby/object:Gem::Version
         | 
| 138 138 | 
             
                    version: '0'
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: diff_dirs
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - ">="
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: '0'
         | 
| 146 | 
            +
              type: :development
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - ">="
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: '0'
         | 
| 139 153 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 140 154 | 
             
              name: faraday
         | 
| 141 155 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -330,6 +344,7 @@ files: | |
| 330 344 | 
             
            - lib/dato/local/field_type/date_time.rb
         | 
| 331 345 | 
             
            - lib/dato/local/field_type/file.rb
         | 
| 332 346 | 
             
            - lib/dato/local/field_type/float.rb
         | 
| 347 | 
            +
            - lib/dato/local/field_type/global_seo.rb
         | 
| 333 348 | 
             
            - lib/dato/local/field_type/image.rb
         | 
| 334 349 | 
             
            - lib/dato/local/field_type/integer.rb
         | 
| 335 350 | 
             
            - lib/dato/local/field_type/lat_lon.rb
         | 
| @@ -342,6 +357,7 @@ files: | |
| 342 357 | 
             
            - lib/dato/local/item.rb
         | 
| 343 358 | 
             
            - lib/dato/local/items_repo.rb
         | 
| 344 359 | 
             
            - lib/dato/local/json_api_entity.rb
         | 
| 360 | 
            +
            - lib/dato/local/loader.rb
         | 
| 345 361 | 
             
            - lib/dato/local/site.rb
         | 
| 346 362 | 
             
            - lib/dato/site/client.rb
         | 
| 347 363 | 
             
            - lib/dato/site/repo/base.rb
         |